MATLAB: How to improve the euler code

euler

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

Best Answer

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