I recently made a code to solve a RLC circuit problem, with a 2th order ODE with Runge-Kutta method, but the code I made doens't match the result with standart result ODE for example, with a 5ohm resistor (R), 10mF capacitor (C), 1H inductor (L), 5v with initial voltage [v(0)], 0A for the electric current [i(0)] and 0.05s for the time (t), with 100 iteration I got 1.5163v, and with the code I got 3.75v, i can't see what I'm doing wrong. Here are the ODE equations:
And here is the equation to find the initial value of v'(0)=w(0):
Now, the Runge-Kutta method:
And finally the code:
for(int i=0;i<iteracao;i++, hX+=h){
tensaofSec=tensaof;
wTV=wf;
wT=wf;
//Runge-Kutta para a funcao v'(t) e w'(t)
l1=h*funcaoV;
k1=h*funcaoW;
wT=(wf+(k1/2));
wTV=(wf+(k1/2));
tensaofSec=(tensaof+(l1/2));
k2=h*funcaoW;
l2=h*funcaoV;
wT=(wf+(k2/2));
wTV=(wf+(k2/2));
tensaofSec=(tensaof+(l2/2));
k3=h*funcaoW;
l3=h*funcaoV;
wT=(wf+k3);
wTV=(wf+k3);
tensaofSec=(tensaof+l3);
k4=h*funcaoW;
l4=h*funcaoV;
wf=wf+((k1+(2*k2)+(2*k3)+k4)/6);
tensaof=tensaof+((l1+(2*l2)+(2*l3)+l4)/6);
}