Error in using 'cumtrapz' for integration
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Akzeptierte Antwort
Matt J
am 10 Aug. 2022
Bearbeitet: Matt J
am 10 Aug. 2022
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))
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!