From rk-2 to rk-4
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Danny Helwegen
el 20 de Dic. de 2018
Editada: madhan ravi
el 21 de Dic. de 2018
Hi, I have a problem. I have written the following code for a Runge Kutta 2 but now i want it write a code for a Runge Kutta 4. So if i'm correct i have to add a k3 and a k4 but i have no clue how. Can anyone help me?
function x = exc5rk2(k,M,h,D)
% k, m, and D are preset values
%h is the timesteps and D is the time
N = D/h;
t(1) = 0;
x(1) = 1.5;
v(1) = 0;
for i = 1:N
t(i+1) = t(i) + h;
xs = x(i) + h*(v(i));
vs = v(i) + h*(-k/M*x(i));
x(i+1) = x(i) + h/2*(v(i)+vs);
v(i+1) = v(i) + h/2*(-k/M*x(i)-k/M*xs);
end
plot(t,x,t,v)
return
1 comentario
Respuesta aceptada
madhan ravi
el 21 de Dic. de 2018
Editada: madhan ravi
el 21 de Dic. de 2018
If you want just downloadhttps://www.mathworks.com/matlabcentral/fileexchange/29851-runge-kutta-4th-order-ode?focused=3773771&tab=function from file exchange and adapt it to your equation.
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!