Define the ODE equals the matrix. Runge Kutta 4
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Babak
le 7 Août 2012
Change
xinital= [ 0 0 -2 0.4]
to
xinital= [ 0 0 -2 0.4]'
or
xinital= [ 0;0;-2;0.4]
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!