Define the ODE equals the matrix. Runge Kutta 4

6 ビュー (過去 30 日間)
Phong Pham
Phong Pham 2012 年 8 月 7 日
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

採用された回答

Babak
Babak 2012 年 8 月 7 日
Change
xinital= [ 0 0 -2 0.4]
to
xinital= [ 0 0 -2 0.4]'
or
xinital= [ 0;0;-2;0.4]

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by