Error in using 'cumtrapz' for integration

조회 수: 12 (최근 30일)
N Haq
N Haq 2022년 8월 10일
편집: Matt J 2022년 8월 11일
Hello
I need to use 'cumtrapz' for a particular part of my project, but before that i am trying to understand how it works for multiple time cumulative integration. As a test, i was trying the following basic code:
ny = 101;
eta = linspace(-1,1,ny)';
f1 = sin(eta);
% Calculation of first cumulative integral
g1 = cumtrapz(eta,f1);
% Calculation of second cumulative integral
h1 = cumtrapz(eta,g1);
% Calculation of third cumulative intergal
k1 = cumtrapz(eta,h1);
We know that first integration of sinx is -cosx and then second intergration is -sinx.
So the value of g1 at each grid point must match {-cos(grid point) + cos(-1)}, Which it does.
But then the value of h1 at each grid point must match {-sin(grid point) + sin(-1)}, which it doesn't.
I was wondering why this happens.

채택된 답변

Matt J
Matt J 2022년 8월 10일
편집: Matt J 2022년 8월 10일
But next, value of h1 at each grid point must match {-sin(grid point value) - (-sin(-1))},
No, it will be -sin(x)+x*cos(-1) -( -sin(-1)-1*cos(-1))
  댓글 수: 3
Matt J
Matt J 2022년 8월 10일
편집: Matt J 2022년 8월 11일
What is the indefinite integral of f(x)=-cos(x)+c? It is g(x)=-sin(x)+c*x.
The definite integral from a to b is therefore,
g(b)-g(a) = (-sin(b)+c*b) - (-sin(a)+c*a)
Now, substitute in b=x and a=-1 and c=cos(-1).
N Haq
N Haq 2022년 8월 10일
Thank you Matt ! This really helped , i appreciate your time.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by