MATLAB Can anyone help me solve 2nd-order ODEs using Euler's method in MATLAB?

  • Thread starter Thread starter vendtfan
  • Start date Start date
  • Tags Tags
    Ode
AI Thread Summary
The discussion centers on solving second-order ordinary differential equations (ODEs) using MATLAB, specifically through Euler's method. The original equation presented is d²y/dt² = -9y, which can be transformed into a system of first-order equations: dy/dt = z and dz/dt = -9y. The user expresses confusion about implementing this in MATLAB, particularly regarding the output and behavior of the solution. It is clarified that both equations must be used in the Euler method to track the solutions for y and z. The output should focus solely on the values of y, as the original equation is defined in terms of y. The importance of correctly setting up the matrix form for Euler's method is emphasized to ensure accurate results.
vendtfan
Messages
1
Reaction score
0
I'm trying to come up with an algorithm for solving second-order ode problems with euler's on matlab. the problem is that my MATLAB skills are very minimal! If anyone can point me in the right direction, it would be greatly appreciated!
 
Physics news on Phys.org
Can't you just use a system of first-order equations to solve it?
 
arildno said:
Can't you just use a system of first-order equations to solve it?

So for example, my function is:

\frac{d^2y}{dt^2}=-9y

So converting it into two first orders would be:

\frac{dy}{dt} = z

and

\frac{dz}{dt} = -9y

So as I understand,

y' = \int{\frac{dz}{dt}} = -9yt

When I plug this into Matlab (with a Euler's ODE solver and initial guess of 1), it looks good for about a quarter of a period then levels off to zero. Should I be doing something with the z equation, or do I use it as a conceptual tool to solve the one equation?

I'm sorry, this is very confusing for me, any help would be awesome.
 
No, once you have defined z to be dy/dt you have the second equation in your system.

So your system will be:

\frac{dz}{dt}=-9y
\frac{dy}{dt}=z

You "track" the solution (both z and y) using a matrix form of Euler's method. But since the original equation was in terms of y, you'll output only the values of y.
 
Back
Top