Hi, I'm trying to write a matlab program for a recursive sequence. I worked out the sequence right I think but can't get the figures right in the program. Here's 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 I've got it wrong?
Thank you