Does anyone could help me out with this RK4 code, the code runs but it does plot nothing
Afficher commentaires plus anciens
function rungekutta
h = 0.1; %tamao de paso
t = 0; %valor incial del intervalo
a = 1; %valor final del intervalo
w = 0.5; %condicin inicial
n=(a-t)/h; %cantidad de subintervalos
for i=0:n-1
k1 = h*f(t,w);
k2 = h*f(t+h/2, w+k1/2);
k3 = h*f(t+h/2, w+k2/2);
k4 = h*f(t+h, w+k3);
wo = w + (k1+2*k2+2*k3+k4)/6;
to = t + h;
fprintf('Step %d: to = %6.4f\n wo = %18.15f\n', i, to, wo);
plot(wo, to)
end
%%%%%%%%%%%%%%%%%%
function v = f(t,y)
v = y-t^2+1;
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!