Electronic – Solving a linear system of equations from a mesh analysis in the s-Domain

circuit analysisMATLAB

Here is an exercise from my Textbook in which one is asked to find the mesh currents:
problem_outline

The first thing I did was find the s-Domain equivalent of the circuit:
s-domain_equivalent

Now, I can write the mesh equations from it:

From Mesh 1:
$$
\frac{6s\cos{13}+12\sin{13}}{s^2+4}= \frac{4000}{3s}\left(I_1-I_2\right)+2\left(I_1-I_3\right)$$

From Mesh 2:
$$
\frac{4000}{3s}\left(I_2-I_1\right)-10^{-3} +10^{-3}s\left(I_2-I_4\right)=-0.005\,I_1
$$

From Mesh 3:
$$
\frac{6s}{s^2+4}=2\left(I_1-I_3\right)+\frac{1000}{s}\left(I_4-I_3\right)
$$

From Mesh 4:
$$
\frac{1000}{s}\left(I_3-I_4\right)-10^{-3}+10^{-3}\left(I_2-I_4\right)=0
$$

Upon simplification, the linear system to be solved is the following:
$$
\begin{cases}
\frac{6s\cos{13}+12\sin{13}}{s^2+4} & = \left(\frac{4000}{3s} + 2\right)\,I_1 – \frac{4000}{3s}\,I_2 -2\,I_3\\
10^{-3} &= \left(\frac{-4000}{3s} + 0.005\right)\,I_1 +\left(\frac{4000}{3s} + 10^{-3}s\right)\,I_2 -10^{-3}s\,I_4\\
\frac{6s}{s^2 + 4} &= 2\,I_1 – \left(2+\frac{1000}{s}\right)\,I_3 + \frac{10^3}{s}\,I_4\\
10^{-3} &= 10^{-3}s\,I2 + \frac{1000}{s}\,I_3 -\left(\frac{10^3}{s}+10^{-3}s\right)\,I_4
\end{cases}
$$

Now, I would like to ask if there is a method to solve the above system with MATLAB or a calculator because it seems pretty daunting to be done by hand.

Best Answer

There is, you can solve it with the symbolic package. In Gnu Octave, I did as follows:

pkg load symbolic

syms s i1 i2 i3 i4

%Since the angles are in degrees, you'll need to use "cosd" and "sind" instead
 eq_sys = [
 (6*s*cosd(13)+12*sind(13))/(s^2+4) == (4000/(3*s)+2)*i1-4000*i2/(3*s)-2*i3; 
 1e-3 == (-4000/(3*s)+0.005)*i1+(4000/(3*s)+1e-3*s)*i2-1e-3*s*i4;
 6*s/(s^2+4) == 2*i1-(2+(1e3/s))*i3+1e3*i4/s;
 1e-3 == 1e-3*s*i2+1e3*i3/s-(1e3/s+1e-3*s)*i4
 ];

 aux = solve(eq_sys,i1,i2,i3,i4)

After that, you can calculate the inverse Laplace Transform of \$I_1(s)\$ as well as \$I_2(s)\$:

syms t
ilaplace(aux.("i1"))
ilaplace(aux.("i2"))

The expression of \$i_1(t)\$ is: $$ i_1(t) = \frac{18995427834743075\sin\left(2t\right)}{70368744177664}-\frac{17314045002411675\cos\left(2t\right)}{562949953421312} $$

Likewise, that of \$i_2(t)\$ is: $$ i_2(t) = \frac{296812200041343\, \delta(t)}{4503599627370496000}+\frac{607845269247680625947479059060193\, \sin(2t)}{2251770540398008282646577152000}-\frac{34629909136866774277122155673357\, \cos(2t)}{1125885270199004141323288576000}-\left(\frac{829655138918152783365787659}{985149611424128623657877504}\,e^{-1000t/7}\left(\cos\left(\frac{3000\sqrt{3}t}{7}\right)-\frac{341473085180277742962620803\,\sqrt{3}}{2488965416754458350097362977}\sin\left(\frac{3000\sqrt{3}t}{7}\right)\right)\right) $$