I am trying to solve a 2nd order system of 2 ODEs using the ODE45. the variables to be solved are V_1 and V_6.
the output vetor y = [V_1 ; V_1' ; V_6 ;V_6'] as I defined has the length of 4, and it matches the definition of the system of ODEs
the length of the initial condition vector is 4, and it matches the definition of the system of the 2 ODEs
but I get this error:
"LINEAR_ODE returns a vector of length 2, but the length of initial conditions vector is 4. The vector returned by
LINEAR_ODE and the initial conditions vector must have the same number of elements."
the ODE equations are pretty complicated but correspond to the equations of a coupled two LC resonators. I checked my code pretty much but going crazy.
I am following the same approch as is in this question (https://www.mathworks.com/matlabcentral/answers/491409-how-to-solve-system-of-2nd-order-differential-equations-using-ode45), and the code works with no error !
Thank you so much !
TimeScale= 10*1E-10;
TimeStep= 1 * 1E-15;
tspan = [0:TimeStep: TimeScale];
y0 = [0; 0; 0;0];
[t, y]= ode45(@Linear_ODE, tspan, y0);
function dydt=Linear_ODE(t,y)
h = 6.62607015 * 1E-34 ;
e=1.60217662 * 1E-19;
K_J= (2*e*2*pi)/h ;
C_1 = 0.3e-12;
L_5 = 10.0e-9;
L_J = 2*L_5;
L_3 = L_J;
M_4 = 100e-12;
C_6 = 0.3e-12;
tildeL_3 = L_3-M_4;
tildeL_5 = L_5-M_4;
V_0 = 1e-6;
R_s=50;
Ic_0= 25e-9;
w= 2.9e09;
Alpha= tildeL_3 + M_4;
Beta = tildeL_5 + M_4;
TimeStep= 1 * 1E-15;
dydt= [y(2); -1/(R_s*C_1)*y(2)-(1 + Alpha * 1/L_J)*1/(Alpha*C_1) * y(1) + M_4*C_6/(C_1*Alpha) * diff(y(4))/TimeStep-V_0*w*sin(w*t)/(R_s*C_1) ; y(4) ; M_4*C_1/(C_6*Beta)* diff(y(2))/TimeStep+ M_4/(R_s*C_6*Beta)* y(2)+ M_4*1/(C_6*Beta)* 1/L_J * y(1)+y(3)/(C_6*Beta)+ M_4/(R_s*C_6*Beta)*V_0*w*cos(w*t)];
end