Problem: Use MATLAB's symbolic toolbox to find the general and particular solution for the transient response of i(t) in a simple/canonical RLC circuit.
Challenge: Execution of the line iSol(t) = dsolve(eqn, [cond1, cond2]);
in the code below raises an error that states that the solver is unable to reduce the square system because the number of equations differes from the number of indeterminates. Can someone help me resolve this issue?
syms i(t) R L C V0
% Define component values
R = 10;
L = 1;
C = 1;
V0 = 12;
% Define the differential equation
eqn = L*diff(i(t), t, 2) + R*diff(i(t), t) + (1/C)*i(t) == 0;
% Define initial conditions
cond1 = i(0) == 0; % i(0) = 0
cond2 = diff(i(t),t) == V0/L; % di/dt(0) = V0/L
% Solve the differential equation with initial conditions
iSol(t) = dsolve(eqn, [cond1, cond2]);
% Display the particular solution
disp('Particular Solution for i(t):')
disp(iSol(t))
You directly have an example in the documentation of a second order equation with initial conditions on the unknown function and its derivative.
Applying it to your problem gives:
syms i(t) R L C V0
% Define component values
R = 10;
L = 1;
C = 1;
V0 = 12;
% Define the differential equation
eqn = L*diff(i, t, 2) + R*diff(i, t) + (1/C)*i == 0;
% Define initial conditions
Di = diff(i,t);
init_cond = [i(0)==0, Di(0)==V0/L];
% Solve the differential equation with initial conditions
iSol(t) = dsolve(eqn, init_cond);
% Display the particular solution
disp('Particular Solution for i(t):')
disp(iSol(t))
Edit: I have called the unknown i
, like you did, but it is good practice not to use i
(or j
) as variable names in Matlab.
Edit 2: It seems like the variable in the differential equation governing the behavior of a RLC circuit should be the charge q
instead of the current i
. Nonetheless the equation is right (if solving for the charge)