How can i improve my euler code? Code is attached ... I believe i have to improve it by using trapezoids instead of rectangles..How do i do this ? Can someone help

 Akzeptierte Antwort

Jim Riggs
Jim Riggs am 20 Feb. 2018

0 Stimmen

For trapezoidal integration, you use the average of two consecutive evaluations. This could be done by simply adding one line of code after the Euler calculation;
y(:,k+1) = (y(:,k+1) + y(:,k))*h/2

2 Kommentare

Raiven Balderas
Raiven Balderas am 21 Feb. 2018
so i add your suggestion directly below "y(:,k+1)=y(:,k)+h*func(t(k),y(:,k)); " ?
Jim Riggs
Jim Riggs am 21 Feb. 2018
Bearbeitet: Jim Riggs am 21 Feb. 2018
Perhaps this will be more clear:
A = func(t(k), y(:,k) );
B = func(t(k+1),y(:,k+1));
y(:,k+1) = y(:,k) + (A + B) * h/2;
Compare this with the Euler method:
A = func(t(k), y(:,k) );
y(:,k+1) = y(:,k) + A * h;

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by