Ask Experts Questions for FREE Help !
Ask
    Gemma82au's Avatar
    Gemma82au Posts: 1, Reputation: 1
    New Member
     
    #1

    Mar 11, 2003, 12:26 AM
    Recursive Matlab problem
    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
    dtecmeister's Avatar
    dtecmeister Posts: 6, Reputation: 1
    New Member
     
    #2

    Mar 22, 2003, 11:02 AM
    Recursive Matlab problem
    I'm not used to Matlab, but I think you need to do the following:
    Clear
    Format long
    A=38;
    Fprintf(' Week Megalitres\n\n');

    For n=1:10;
    Disp([n A])
    A=A-(2*(n-4))

    End
    renut's Avatar
    renut Posts: 1, Reputation: 1
    New Member
     
    #3

    Jun 30, 2010, 11:57 PM
    The equation u hv used A = A+9-3(n) is not gvng right answer. As I solved manually then I got
    1 38
    2 35
    3 29
    4 26
    .
    .
    .

    . So prblem is related with the equation. Check it.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Pi by recursive decimal places [ 5 Answers ]

I would like to know if there is a way to calculate pi by using the current last decimal place to calculate the next decimal place. I already made a formula for pi that I posted on another board, but someone suggested I copy here. ---Begin quote--- This doesn't really fit anywhere so I'm just...

Playboy girlfirend problem.. Real problem [ 14 Answers ]

I have this new girlfriend.. that I really, really like (more than any other). She seems really nice... she was wearing everything of the "playboy" (earrings, bag, shirt, etc, etc) brand name / merchandise. I thought it was cute and a one time thing. Until I saw her bedroom.. It was 100%...


View more questions Search