Hello(adsbygoogle = window.adsbygoogle || []).push({});

I have a program for Eulers method >>

% Euler's Method for dy/dt = cost

k = 1;

y0 = 0;

npoints = 500;

dt = 0.01;

y = zeros(npoints,1); % this initializes the vector y to being all zeros

t = zeros(npoints,1);

y(1) = y0; % the initial condition

t(1) = 0.0;

for step=1:npoints-1 % loop over the timesteps

y(step+1) = y(step) + dt*k*(cos(y(step)));

t(step+1) = t(step) + dt;

end

plot(t,y,'r'); %plots the numerical solution in red

hold on; %keep the previously plotted lines

plot(t,yexact2(t)); %plots the exact solution (default plot is in blue, solid line)

The graph asymptotically approaches pi/2, and I cant think of a way to deal with this.

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Euler's Method in MAtlab

Loading...

Similar Threads for Euler's Method MAtlab | Date |
---|---|

MATLAB "Linear Model" of a Pendulum via Euler's Method | Nov 16, 2016 |

Mathematica Rotation of 3D Plot using Euler angles | Feb 15, 2016 |

MATLAB Matlab programming using shooting method, Euler and Runge Ketta methods | Nov 29, 2011 |

Trouble with Euler's method in MATLAB | Jan 30, 2011 |

Excel - help with eulers method on coupled equations | Aug 6, 2008 |

**Physics Forums - The Fusion of Science and Community**