Octave integral computation help

Click For Summary
SUMMARY

The forum discussion centers on a coding issue in Octave related to integral computation using the cumtrapz function. The user, Jacob M., encounters a problem where the population matrix outputs zeros due to passing a single element to cumtrapz instead of an array. The code provided initializes a population matrix and calculates birthing probabilities, but fails to produce expected results in the population matrix. The moderator suggests that providing equations could clarify the user's intent and facilitate better assistance.

PREREQUISITES
  • Understanding of Octave programming language
  • Familiarity with numerical integration techniques, specifically cumtrapz
  • Knowledge of matrix operations in Octave
  • Basic concepts of population modeling and simulation
NEXT STEPS
  • Review Octave documentation on cumtrapz for proper usage
  • Learn about array manipulation in Octave to ensure correct data input
  • Explore population dynamics modeling techniques
  • Investigate debugging strategies for Octave code to identify logical errors
USEFUL FOR

This discussion is beneficial for Octave programmers, data scientists working on population models, and anyone interested in numerical methods for integration in computational simulations.

Jacob Marcum
Messages
1
Reaction score
0
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:
Matlab:
age = [0:1:100];                            %this is the age matrix, represented by a
time = [0:1:100];                           %this is the time matrix, represented by tpopulation = 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:
Physics news on Phys.org
You are passing a single element to cumtrapz, not an array.

Explaining what you are trying to do (with equations) would help.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K