Matlab provides the built-in function ode45
to solve ordinary differential equations numerically. In order to use ode45
to solve second order differential equations, we need to create a system of two first order differential equations from the second order one.
Let's consider the second order differential equation:
main.m28 chars2 lines
We can rewrite this as a system of two first order differential equations by introducing a new function z
such that:
main.m33 chars3 lines
Now we can use ode45
to solve this system of differential equations numerically.
main.m544 chars23 lines
This code solves the second order differential equation y'' + y'/t + (2t-1)/t^2 y = 10e^{-t}
using ode45
and plots the solution.
gistlibby LogSnag