How would I improve my euler code?

1 次查看(过去 30 天)
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

采纳的回答

Jim Riggs
Jim Riggs 2018-2-20
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 个评论
Raiven Balderas
Raiven Balderas 2018-2-21
so i add your suggestion directly below "y(:,k+1)=y(:,k)+h*func(t(k),y(:,k)); " ?
Jim Riggs
Jim Riggs 2018-2-21
编辑:Jim Riggs 2018-2-21
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;

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by