Results 1 to 2 of 2

Math Help - Matlab Help

  1. #1
    Newbie
    Joined
    Apr 2010
    Posts
    1

    Matlab Help

    I have a hw question that I couldn't seem to find the answer for hours (its now late so I also will get 0 credit for it). I still want to know the answer, or at least what I'm doing wrong. Thanks for your help!

    Question:
    Consider the logistic equation
    x_(k+1) = βx_k (1 − x_k + (εx^2_k)/2)
    which is based upon a model used to study the growth and decay of a population of some species.
    Iterate the equation for the following values of β with ε = 0.1 and x_0 = 0.479:
    β = 0.8, 1.5, 2.8, 3.2, 3.5, 3.65
    Iterate the equation for each β value and calculate six column vectors (one for each β) of length
    50 which contains x(1) = x1 to x(50) = x50 .
    Answers: Write the output as A1.dat - A6.dat


    This is the code I had for it:

    Code:
    E = 0.1;
    A1 = 0;
    A2 = 0;
    A3 = 0;
    A4 = 0; 
    A5 = 0;
    A6 = 0;
    
    for B = [0.8 1.5 2.8 3.2 3.5 3.65]
        xold = 0;
        i = 1;
        for i = 1:50
        xnew = B*xold*(1-xold+(E*xold^2)/2) + 0.479;
        xold = xnew ;
       if B == 0.8
           A1(i, 1) = xnew ; 
       elseif B== 1.5
           A2(i, 1) = xnew ;
       elseif B== 2.8
           A3(i, 1) = xnew ;
       elseif B== 3.2
           A4(i, 1) = xnew ;
       elseif B== 3.5
           A5(i, 1) = xnew ;
       elseif B== 3.65
           A6(i, 1) = xnew ;
       end
       end
        
    end
    
    save A1.dat A1 -ascii
    save A2.dat A2 -ascii
    save A3.dat A3 -ascii
    save A4.dat A4 -ascii
    save A5.dat A5 -ascii
    save A6.dat A6 -ascii
    Last edited by CaptainBlack; April 15th 2010 at 10:11 PM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by robgld View Post
    I have a hw question that I couldn't seem to find the answer for hours (its now late so I also will get 0 credit for it). I still want to know the answer, or at least what I'm doing wrong. Thanks for your help!

    Question:
    Consider the logistic equation
    x_(k+1) = βx_k (1 − x_k + (εx^2_k)/2)
    which is based upon a model used to study the growth and decay of a population of some species.
    Iterate the equation for the following values of β with ε = 0.1 and x_0 = 0.479:
    β = 0.8, 1.5, 2.8, 3.2, 3.5, 3.65
    Iterate the equation for each β value and calculate six column vectors (one for each β) of length
    50 which contains x(1) = x1 to x(50) = x50 .
    Answers: Write the output as A1.dat - A6.dat


    This is the code I had for it:

    Code:
    E = 0.1;
    A1 = 0;
    A2 = 0;
    A3 = 0;
    A4 = 0; 
    A5 = 0;
    A6 = 0;
     
    for B = [0.8 1.5 2.8 3.2 3.5 3.65]
        xold = 0;
        i = 1;
        for i = 1:50
        xnew = B*xold*(1-xold+(E*xold^2)/2) + 0.479;
        xold = xnew ;
       if B == 0.8
           A1(i, 1) = xnew ; 
       elseif B== 1.5
           A2(i, 1) = xnew ;
       elseif B== 2.8
           A3(i, 1) = xnew ;
       elseif B== 3.2
           A4(i, 1) = xnew ;
       elseif B== 3.5
           A5(i, 1) = xnew ;
       elseif B== 3.65
           A6(i, 1) = xnew ;
       end
       end
     
    end
     
    save A1.dat A1 -ascii
    save A2.dat A2 -ascii
    save A3.dat A3 -ascii
    save A4.dat A4 -ascii
    save A5.dat A5 -ascii
    save A6.dat A6 -ascii
    Try single stepping through this code in the debugger and see what you get at each step for the first few trips around that loop.

    Hint "x_0 = 0.479" means initialise xold to 0.479.

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Matlab help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 11th 2010, 02:59 AM
  2. Matlab FFT Help
    Posted in the Math Software Forum
    Replies: 0
    Last Post: June 3rd 2009, 12:48 PM
  3. help about ODE in matlab
    Posted in the Math Software Forum
    Replies: 1
    Last Post: May 31st 2009, 03:10 AM
  4. Matlab
    Posted in the Math Software Forum
    Replies: 0
    Last Post: November 6th 2008, 08:46 AM
  5. Matlab
    Posted in the Calculus Forum
    Replies: 3
    Last Post: August 20th 2008, 10:39 PM

Search Tags


/mathhelpforum @mathhelpforum