Define the ODE equals the matrix. Runge Kutta 4

3 visualizzazioni (ultimi 30 giorni)
I have velocity vector in matrix form [ 1, 2, 3,4 ];
Velocity is dx/dt 1) first matlab function f = func(t,x)
f= [1,2,3,4]
2) Second matlab
dt=0.001;
t=[0:dt:20];
xinital= [ 0 0 -2 0.4]
use the Runge Kutta to estimate the final x
for i = 1: 20/dt
k1 = dt*func(t(i),x(i));
k2 = dt*func(t(i)+dt/2,x(i)+dt*k1/2);
k3 = dt*func(t(i)+dt/2,x(i)+dt*k2/2);
k4 = dt*func(t(i)+dt,x(i)+dt*k3);
x(2,:) =xintial(1,:) + (k1 + 2*k2 + 2*k3 + k4)/6;
end
I keep getting error message dimension mismatch on xinitial.
Please help

Risposta accettata

Babak
Babak il 7 Ago 2012
Change
xinital= [ 0 0 -2 0.4]
to
xinital= [ 0 0 -2 0.4]'
or
xinital= [ 0;0;-2;0.4]

Più risposte (0)

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by