# Why can't I iterate?

I encounter a problem when computing the following equations:

c[1, 0] := q (cc - a);
c[0, 1] := p (d - b);
c[0, 0] := 1;
c[i_, 0] := -c[i - 1, 0] ((i - 1 + q) p a - p q cc)/((i + q) p - p q);
c[0, j_] := -c[0, j - 1] ((q p b - (j - 1 + p) q d)/((q p - (j + p) q)));
If[h == 0, c[i_, j_] = 0, c[i_, j_] := -(c[i - 1, j] ((i - 1 + q) p a - (j + p) q cc) + c[i, j - 1] ((i + q) p b - (j - 1 + p) q d))/((i + q) p - (j + p) q)];


Then, when I input $$c[1,1]$$, it comes out as $$c[1,1]$$ I don't know what's wrong with it. Hope someone could help. Thanks!

Update:

In the first version, my code looks like this:

c[i_,0]:=-c[i-1,0] ((i-1+q)p a-p q cc)/((i+q) p-p q);
c[0,j_]:=-c[0,j-1] ((q p b-(j-1+p) q d)/((q p-(j+p) q)));
c[i_,j_]:=-(c[i-1,j] ((i-1+q)p a-(j+p) q cc)+c[i,j-1]*
(((i+q) p b-(j-1+p) q d))/(((i+q) p-(j+p) q)));
c[1,0]:=q (cc-a);
c[0,1]:=p (d-b);


then I can compute, for example, c[3,2]: But since I added a condition statement, things went wrong, and I don't know why?

• First, there is a SetDelayed inside If which would not return a result. Second, c[i,j] has not been defined before it is calculated. Third, I do not understand returning c[1,1]=0 as true and looks like a mistake to me. – Titus Dec 9 '18 at 9:20
• If possible, please post some more readable descriptions with necessary better-typeset equations. – Αλέξανδρος Ζεγγ Dec 9 '18 at 10:21
• What exactly are you trying to do? While valid, c[1, 0] is an unusual syntax for Mathematica. If you're trying to create a matrix, you probably will want to use [[ ]] to access each part of the matrix. You can create an n x m matrix with ConstantArray[0, {n, m}] if you're looking for C-style method. Additionally, MMA indexes from 1 rather than 0. – MassDefect Dec 9 '18 at 10:29
• Maybe something with Condition, like c[i_, j_] /; h == 0 = 0. Or maybe you want the If[] inside the function body. You might consider SameQ[] instead of Equal[], that is, h === 0. – Michael E2 Dec 9 '18 at 13:30
• See also RSolve[] and RecurrenceTable[]. – Michael E2 Dec 9 '18 at 13:31

## 1 Answer

Perhaps you can change

If[h == 0, c[i_, j_] = 0, c[i_, j_] := -(c[i - 1, j] ((i - 1 + q) p a - (j + p) q cc) + c[i, j - 1] ((i + q) p b - (j - 1 + p) q d))/((i + q) p - (j + p) q)];


to

c[i_, j_] := If[h == 0, 0, -(c[i - 1, j] ((i - 1 + q) p a - (j + p) q cc) + c[i, j - 1] ((i + q) p b - (j - 1 + p) q d))/((i + q) p - (j + p) q)];

• Thank you for your advice. But it doesn't work. – Yuyi Zhang Dec 10 '18 at 1:04
• @YuyiZhang What do you mean? (Be sure to set h before you try it!) – Alan Dec 10 '18 at 3:04
• It seems that it will work if I change h==0 to h===0. – Yuyi Zhang Dec 10 '18 at 11:43
• @YuyiZhang I suspect your change is not doing what you think it is. Note that h=0.0; If[h==0,0,99] returns 0 but If[h===0,0,99] then returns 99. – Alan Dec 10 '18 at 14:13