You are on page 1of 7

Tutorial: Circuit Analysis using MathCad 15.

To use this tutorial effectively, mimic all the mathematical expressions, repeating all the operations and
making sure you can reproduce the results.

Example 1: Using Nodal Analysis, solve for the node voltages of the circuit below

One way to solve this problem in Mathcad is to use an equation   block. First, define your variables
by specifing what is refered to as their intial guess (0 is typically fine)
V1  0 V2  0 V3  0
To enter the equation Va = 0 in Mathcad, you enter Va, then press the colon key : (or shift-;), then 0,
and then enter. Instead of enter, you could also hit the tab key to advance to enter the next equation

Now, define your equation block. This starts with a Given statement. Just type Given and then hit enter.

Given (This "Given" instructs Mathcad that you are going to set up an equation block)
Next, define your equations. When you type equality, hit Ctrl-= (Ctrl key, and then the = key). Note
that the equal sign is in a bold font.
V1 V1  V2 V2  V1 V2  V3 V3  V2 V3
2  =0  4 3 =0  3 =0
15 10 10 5 5 20
Note: Use the space bar to adjust your cursor size. So, to enter the expression (V1-V2)/10, type V1-V2
space / 10. Notice when you press the space bar, the cursor will underline the entire express V1-V2. Then
when you enter / for divide by, Mathcad knows you want to divide the entire expression V1-V2 by
something.

Finally, use the Find function to solve for the unknowns.

V  Find ( V1V2V3) (The "Find" function solves for V1, V2, and V3)

 4.5  To see what V is = to, just type V= (no colon, or Ctrl keys, just =)
V   27.5 
Here we have expressed the solution as a vector. We can also access individua
  elements of the vector as:
 34 
V  4.5 V  27.5 V  34
0 1 2
To get the subscript, type [ immediately after V. So, V sub 0 = is entered as V[0=
Next, the problem is re-solved by representing it as matrix equation. To this end, the 3 equations derived
from the nodal analysis can be expressed as a matrix equation A x = b.

First, enter the matrix by typing A: (note the colon after A), and then Ctrl-m (which opens the insert
matrix window). Specify 3 rows and 3 columns. Then, enter in your matrix elements. Note, there is no
reason to combine terms or find common denominators. Enter the sum of terms that weights V1 in the
first column entry, the terms weighting V2 in the second column entry, etc.

Similarly, to enter b, type b: (again, b, then colon), and then Ctrl-m. Set 3 rows and 1 column for b.
Enter in the values of the matrix by entering in the expression for the first element, then use the tab key
to advance to the next element.

 1  1 1 
 15 10 10
0 
   2 
 1 1 
b   4  3 
1 1
A  
 10 10 5 5   
  3 
1 1 1 
 0  
 5 5 20 

Solve for x by typing x : A ^ -1 space space * b (Note that the 2 spaces brings the cursor back to the
main line.)
1
x  A b

 4.5 
x   27.5 
  Of course, this comes up with the same solution as the equation block.
 34 

Now, as a post processing we can do things such as compute the current through the 5-ohm resister:

x x
1 2
I5  I5  1.3
5

Example 2: Mesh Analysis

The next tutorial is a mesh analysis of the circuit below. The same steps will be followed, to solve the
circuit using an equation block, as well as a matrix equation. Both give the same solution, and is up to
your preference which to use.

For the equation block: First specify the initial conditions of the 5 mesh currents

I1  0 I2  0 I3  0 I4  0 I5  0
I3
I2
I1
I4

I5

Next, define the equation block using mesh analysis with the following steps: First define the current
constrants. Second, write the KVL equation for all mesh loops not touching a current source. Finally,
combine any loops that share a current source, defining your KVL about that super-loop. This will lead
the 5 necessary equations.

Given

Current Contraints: I2  I1 = 2 I3 = 5

KVL: 2 ( I4  I3)  5  1  ( I4  I5) = 0 15  1  ( I5  I4)  5  I5 = 0

Super Loop KVL: 10  3  I1  1  ( I2  I3) = 0

Solution:
 3.25 
 
I  Find( I1 I2 I3 I4 I5)  5.25 
I  5 
 2.647 
 
 2.941 
Note that the solution can also be computed analytically. To do this, type I Ctrl-. (that is press the Ctrl k
and then the period key), and hit enter:

 13 
 4 
 
 21  This is the analytical solution (pretty slick!)
 4 
I 5 
 
 45 
 17 
 50 
 
 17 
Again, the solution to the mesh analysis problem can be solved using a matrix equation. Note, that intitial
conditions, etc., are not needed. We just need to enter in the matrix coefficients, and the forcing vector.
Here, we will use a 5x5 matrix, where each row represents each of the 5 equations.

 1 1 0 0 0  2 Again, use the tab key to advance from one cell to
    the next. The cursor will jump to the next empty
0 0 1 0 0
 5
A   0 0 2 2  1 1  b   5  row cell when the tab key is pressed.
0 0 0 1 1  5   15 
   
3 1 1 0 0   10 

The matrix is solved via computing the inverse of A times b:

 3.25 
x  A
1
b  
 5.25 
x 5   13 
 4 
 2.647   
 
 2.941   21 
 4 
Again, Mathcad can compute the solution analytically if you want: x 5 
 
 45 
 17 
 50 
 
 17 

Finally, for this problem, compute Vx and Ix from the circuit diagram

Ix  I Ix  2.941
4

2 
Vx  I  I  1  15
1
Vx  15.25

Note that the subscripts are 0-based. Therefore, I subscript 2 is actually I3, and I subscript 1 is actually
I2.

Some space filler here: To start a text block to type text such as this, first type the double quote ", and
then just start typeing! Or, if you start typing text, once you insert a space, Mathcad will interpret it as
text. To get fancier fonts like this, you can define a "style" (defining, font, font size, color, etc.), to be
used with your text.
Example 3: AC steady-state analysis

The next tutorial is to compute the AC-steady state response of a circuit in the phasor domain. In this
example, the circuit values will be left as variables which can be changed to formulate a different solution

Set the radial frequency: ω  2π 60 [Note that the Greek letter omega was grabbed from the
Greek symbol pallet. Also, pi can be typed using Ctrl-Alt-p]

3 3
Set the values of the circuit elements: R1  500 L1  100  10 L2  200  10
6
R2  100 C1  10 10

R3  100 R4  500

Next, compute the impedances: ZL1  j  ω L1 ZL2  j  ω L2


1
ZC1 
j  ω C1

ZL1  37.699i ZL2  75.398i ZC1  265.258i


[Note: To enter the complex j, type 1j. Else, it will interpret j as a
variable. If you need 20j, just type 20j (or 20i). Do not type 20*j,
or j20. It must be 20j. Mathcad understands j = sqrt(-1), which is
EE notation. However, if you note, it will write out the imaginary
term using i = sqrt(-1).]

Define the source voltage: Vs  1  0i

Solve the equations using Nodal Analysis. After applying the voltage constraint V1 = Vs, the solution can
be limited to 2 unknowns, V1 and V2, by combining the series R-L branches.

Initial values: V1  0 V2  0

Given
V1  Vs V1 V1  V2 V2  V1 V2 V2  0
  =0   =0
R1  ZL1 R2 R3 R3 ZC1 R4  ZL2
Solve for V

V  Find( V1 V2)  0.135  0.03i 


V  
 0.097  0.054i 


 75 10875000 π2  27000 π4  800781250  61328125i π  371250i π3  648i π5


 2 4 6
9450000000  π  28552500 π  11664  π  410400390625 
V 


 2 4 3
625  123750 π  648  π  80078125  32400i π  13500000i π  
 2 4 6 
 9450000000  π  28552500 π  11664  π  410400390625

Note that Mathcad can also give an analytical solution. However, the analytical solution is pretty ugly!

The voltages can be converted to polar form. This can be done using two functions. The magnitude is
obtained by using the absolute value symbol. You can get this from the "calculator" tool pallet. Or, using
the key-board, type | (which is shift-\). The angle of a complex # is computed using the function "arg".
Note it returns the angle in radians. So, if you want degrees, multiply the result by 180/pi. Here are some
examples for this problem:

V1  V V2  V
0 1
180
V1  0.138 arg ( V1)  0.221 arg ( V1)   12.648
π

180
V2  0.111 arg ( V2)  0.504 arg ( V2)   28.855
π

It may be convenient to create a function that will convert a complex number from rectangular form to
polar form:

 z 
 z  in radians, or   in degress
Rect2Pol( z)    Rect2Pold( z)  180
 arg( z)   arg( z)  
 π 

 0.138   0.138 
Rect2Pol( V1)    Rect2Pold( V1)   
 0.221   12.648 

The reciprocal function would be to convert the polar form back to rectangular:

  1  j  sinz1
Pol2Rect( z)  z  cos z
0
assuming polar form in radians, or

Pold2Rect( z)  z   cos z    j  sin z  π  


π
assuming polar form in radians degrees.
1 180   1 
0     180  
Lets check the functions: V1  0.135  0.03i

 0.138   0.138 
V1p  Rect2Pol( V1)    V1pd  Rect2Pold( V1)   
 0.221   12.648 

V1r  Pol2Rect( V1p )  0.135  0.03i V1r  Pold2Rect( V1pd)  0.135  0.03i

This works!

Since Mathcad is doing all the computations directly, there is typically little reason to switch between
rectangular and polar form. This would be more useful to format the final answer. You can re-use these
functions by cutting and pasting them into the top of your next worsheet, or save them to a file and link to
them via a reference for later on.

Finally, lets look at a time-domain form of V1 and graph it out for a few periods.

v1( t)  V1  cos( ω t  arg( V1) ) arg ( V1)  0.221

ω 1 V1  0.138
f   60 T   0.017
2π f

Choose the 2D plot from the graph pallette. Then enter "t" for the horizontal axis, and we will plot it
from 0 to 3T seconds (3 full periods). Then enter "v1(t)" for the vertical. Let Mathcad determine the
max and minimum vertical values. It will automatically scale it to fit.

0.2

0.1
V1 (V)

v1( t) 0

 0.1

 0.2
0 0.02 0.04
t

sec

Note that by double clicking on the graph, you can change the trace characterstics, add a grid, add labels
to the axis, etc.

You might also like