Define the ODE equals the matrix. Runge Kutta 4

3 visualizaciones (últimos 30 días)
Phong Pham
Phong Pham el 7 de Ag. de 2012
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

Respuesta aceptada

Babak
Babak el 7 de Ag. de 2012
Change
xinital= [ 0 0 -2 0.4]
to
xinital= [ 0 0 -2 0.4]'
or
xinital= [ 0;0;-2;0.4]

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by