| Recursive Matlab problem Hi, im trying to write a matlab program for a recursive sequence. I worked out the sequence right i think but cant get the figures right in the program. Heres the program I have so far:
%recursive program for water
%dam cycling down to empty
clear
format long
A=32;
fprintf(' Week Megalitres\n\n');
for n=1:10;
A=A+9-3*n;
disp([n A])
end
These are what i get-
Week Megalitres
1 38
2 41
3 41
4 38
5 32
6 23
7 11
8 -4
9 -22
10 -43
But these are the figures i require-
1 38
2 42
3 44
4 44
5 42
6 38
7 32
8 24
9 14
10 2
The problem is where i have 3*n it should be be going up by 2(n+1) at a time. ie 3,5,7,9 whereas mine is going up as 3,6,9,12.
Can anybody see where ive got it wrong?
Thankyou |