Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab Octave integral computation help

Tags:
  1. Apr 20, 2017 #1
    Hello,

    I'm having some trouble with my octave coding and would appreciate any input on where the issue lies.
    The coding is as follows:


    Code (Matlab M):

    age = [0:1:100];                            %this is the age matrix, represented by a
    time = [0:1:100];                           %this is the time matrix, represented by t


    population = zeros(101,101);

    for a = 1:101;
      population(a,1) = 0.5;                    %this is the initial population
      B(a) = (1./(2.*a));                          %this is the birthing probability at age (a)
      endfor
     
    for t = 1:100
      for a = 2:101
        population(1,t+1) = cumtrapz(B(a));     %this is the birth rate
       population(a,t+1) = population(a-1,t);    %this is the interation process
      endfor
    endfor

    surf(age,time,population)
     
    <Moderator's note: code tags added. Please use them when posting code.>


    The issue I'm having lies in the population matrix computation; the cumtrapz integration is not recognizing the step process and all outputs from t = 2:101 in the population matrix are zeros. I would again appreciate any help to understand where the issue lies.

    Thank You,
    Jacob M.
     
    Last edited by a moderator: Apr 21, 2017
  2. jcsd
  3. Apr 21, 2017 #2

    DrClaude

    User Avatar

    Staff: Mentor

    You are passing a single element to cumtrapz, not an array.

    Explaining what you are trying to do (with equations) would help.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Octave integral computation help
  1. Help with Octave (Replies: 3)

Loading...