Define the ODE equals the matrix. Runge Kutta 4
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!