Runge-Kutta Method
Afficher commentaires plus anciens
i got 2 equation first one is dVc/dt=ic second one is dIl/dt=-4vc-4il+20 i've been trying everything but nothing worked if someone can help that'd be great.
clc
f=inline('ic','t','ic','il');
g=inline('-4*vc-4*il+20','t','ic','il');
solution_ic=inline('5-(5*exp(-2*t)*(1+2*t))','t');
solution_il=inline('20*t*exp^(-2*t)','t');
h=.1;
t=0; ic=0; il=0.3839;
hold;
while (t<10)
k1=h*f(t,ic,il);
i1=h*g(t,ic,il);
k2=h*f(t+h/2,ic+k1/2,il+i1/2);
i2=h*g(t+h/2,ic+k1/2,il+i1/2);
k3=h*f(t+h/2,ic+k2/2,il+i2/2);
i3=h*g(t+h/2,ic+k2/2,il+i2/2);
k4=h*f(t+h,ic+k3,il+i3);
i4=h*g(t+h,ic+k3,il+i3);
ic=ic+(1/6)*(k1+2*k2+2*k3+k4);
il=il+(1/6)*(i1+2*i2+2*i3+i4);
plot(t,ic,il,'*');
plot(t,solution_ic(t+h),solution_il(t+h),'bo');t=t+h; end; grid;
Réponses (0)
Catégories
En savoir plus sur Programming 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!