Using MATLAB and Mathcad for solving
(mesh current) equations. A little writeup by Piotr Bania |
There are times when you need to do something simple from the logic point of view but a bit exhausting when it comes to the sum of calculations you need to perform. I'm referring here to the past times (like 3-4 years ago) when I was forced to do all my circuit calculations manually without using anything except paper, pen and a calculator (without the solve function :-)). Hopefully now when I need to do some circuit calculations (which happens very rarely - thank God!) I'm allowed to use some computer software like MATLAB, Mathcad etc. However every single piece of software has it own environment and something like own programming language. So the question is how to use it properly, to speed your work and limit it to writing the logic and forcing computer to do the calculations.
Figure 1. Sample circuit
Figure 1 shows a sample circuit
which is going to be analyzed. So our task is to calculate all the
unknown currents (I1,I2,I3,I4,I6) and voltage value of Uj. To
compute the logic equations I'm using the Mesh analysis method (loop
analysis) [1] which relies on Kirchhoff's circuit laws [2] (this
little article is not a circuit theory tutorial so I hope the reader
is familiar with those laws).
And now the Kirchhoff's current
laws:
So now there are at least two
methods to put those equations into MATLAB or Mathcad and force them
to calculate the values we need. In Mathcad we can use the
Given-Find method [3,4] which basically solves the equations (as
shown at the code listed below). When it comes to MATLAB we can use
the symbolic 'solve' command [5] as shown at the corresponding
MATLAB code below. Of course due to the fact MATLAB 'solve' command
operates on symbols we need to convert the symbol values to numbers
afterwards (this is done by the symbolic substitution command -
'subs'). I think the source codes are self-explanatory, so that's
basically all. I have no idea if this is useful for other 'human'
beings but well it's useful for me :-) References:
|
Mathcad solution |
|
MATLAB solution |
|