Octave integral computation help

In summary, the conversation is about a coding issue with a population simulation using octave. The code involves creating age and time matrices and using a for loop to compute population growth based on birth rates and integration using the cumtrapz function. However, the issue lies in the computation of the population matrix, specifically in the cumtrapz integration which is not recognizing the step process. The problem may stem from passing a single element instead of an array to the function. The speaker asks for help in understanding where the issue lies and provides the code for reference.
  • #1
Jacob Marcum
1
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
  • #2
You are passing a single element to cumtrapz, not an array.

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

1. What is an Octave integral computation?

An Octave integral computation is a computational method used to solve integrals, which are mathematical expressions that represent the area under a curve. Octave is a programming language specifically designed for numerical computations and is commonly used in scientific and engineering applications.

2. How do I perform an Octave integral computation?

To perform an Octave integral computation, you will need to use the "quad" function in Octave. This function takes in the integrand (the mathematical expression that represents the area under the curve), the limits of integration, and any additional arguments that may be required. It then uses numerical methods to approximate the integral and returns the result.

3. What methods does Octave use in integral computation?

Octave uses numerical methods such as the trapezoidal rule, Simpson's rule, and Gaussian quadrature to approximate integrals. These methods involve breaking down the area under the curve into smaller, simpler shapes and then using mathematical formulas to calculate the area of each shape. The results are then combined to estimate the overall integral.

4. Are there any limitations to Octave integral computation?

Like any numerical method, Octave integral computation has its limitations. It may not be able to accurately approximate very complex or oscillating functions. Additionally, it may not be able to handle integrals with infinite or undefined limits. It is important to carefully choose the method and parameters used in Octave to ensure accurate results.

5. How can I check the accuracy of my Octave integral computation?

One way to check the accuracy of your Octave integral computation is to compare the results to known analytical solutions. You can also vary the parameters, such as the number of intervals used, and see how it affects the accuracy of the result. Additionally, Octave has built-in functions such as "quadl" and "quadgk" that use more sophisticated methods and may provide more accurate results for certain types of integrals.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
0
Views
1K
  • Calculus
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
274
Replies
1
Views
1K
Back
Top