2nd order ODE using RK4
Ältere Kommentare anzeigen
Ok, I have a second order ODE and I need to solve it using Runge-Kutta 4. I know that I have to make it into 2 first order equations.
So what I have is x''+1.14x'+3.14x=2.14cos(t)
I make this look like...
x'=v
x''=dvdt=2.14cos(t)-1.14v-3.14x
my step size is h=1.
and i am going from t=0 to t=5
initial conditions are x(0)=1 and x'(0)=0
I can solve this by hand on paper, however I am not too clear on how to write this out in MATLAB. Any help with the coding is greatly appreciated.
Antworten (2)
Honglei Chen
am 28 Mär. 2012
You can use ode45. You first define a function for your differential equation
function dy = myode(t,y)
dy = zeros(2,1);
dy(1) = y(2);
dy(2) = 2.14*cos(t)-1.14*y(2)-3.14*y(1);
then you can call ode45 with your initial conditions
[T,Y] = ode45(@myode,0:5,[1;0])
freestyler000218
am 28 Mär. 2012
0 Stimmen
1 Kommentar
Matt Tearle
am 28 Mär. 2012
Why would you want to? ode45 is an adaptive stepsize 4th-order method, so it's going to do a better job than the vanilla RK4 we all know and love from our differential equations course.
And you don't need feval, even if you do want to write your own. You can just call a function, either hard-coded or passed to a function as a function handle.
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!