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

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

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

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.

• shouldn't the 1000 be 1000e-6? Commented Jan 6, 2020 at 16:12
• Yes. Indeed 1000 uF = 1 mF so when we take the representation model of that capacitor in the s-domain, we end up with $1000/s$ Commented Jan 6, 2020 at 18:39

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)$$

• Thanks for the answer. Unfortunately, I am not using GNU Octave. But I am curious to know if the following code works in MATLAB. Commented Jan 5, 2020 at 7:59
• Just out of curiousity, can these type of equations be solved with a calculator? I am asking in case I might encounter these type of questions in my exams. Or must it be solved with MATLAB and Octave? Commented Jan 5, 2020 at 8:01
• Octave is more or less like Matlab, with a few tweaks you can get it to run in Matlab.
– jDAQ
Commented Jan 5, 2020 at 8:03
• There are ways to solve this manually, but I don't think it will be possible to use a calculator for this (unless you put a lot of effort in writing a program for the calculator). What I would suggest is that you write the whole system as some $b = A(s)I$ with all the currents and so, then you could solve for $I$ using Gaussian elimination or Cramer's rule.
– jDAQ
Commented Jan 5, 2020 at 8:06
• Do, aux = solve(...), Then aux.("i1") should return i1
– jDAQ
Commented Jan 5, 2020 at 9:44