Author: Yaz

  • Stability Analysis of a First-Order System with Proportional Control – Bode Plot

    Stability Analysis of a First-Order System with Proportional Control – Bode Plot

    Let’s analyze the stability of a first-order system with a proportional controller using Bode Plot method. The process has a time constant of 10 seconds, and the proportional controller gain is K_p.

    Closed Loop System with First Order Process and Proportional Controller

    The transfer function of the process under control is:

        \[ P(s) = \frac{1}{10s + 1} \]

    The transfer function of the open-loop system is:

    (more…)
  • Nodal Analysis – Dependent Current Source

    Nodal Analysis – Dependent Current Source

    Deploy nodal analysis method to solve the circuit and find the power of the dependent source.

    I. Identify all nodes in the circuit.
    The circuit has 4 nodes.

    (more…)
  • Nodal Analysis – Dependent Voltage Source

    Nodal Analysis – Dependent Voltage Source

    Use nodal analysis method to solve the circuit and find the power of the 3\Omega– resistor.

    Nodal Analysis  Dependent Current Source

    I. Identify all nodes in the circuit.
    The circuit has 3 nodes:

    (more…)
  • Nodal Analysis – Circuit with Dependent Voltage Source

    Nodal Analysis – Circuit with Dependent Voltage Source

    Nodal Analysis - Supernode - Dependent Voltage Source 1

    Determine the power of each source after solving the circuit by the nodal analysis.

    Answers:  P_{I_x}=0.497W, P_{1A}=-1.806W, P_{2A}=4.254W, P_{3V}=-3.87W, and  P_{5V}=-3.552W


    Solution

    I. Identify all nodes in the circuit.
    The circuit has 6 nodes as highlighted below.


    II. Select a reference node. Label this node with the reference (ground) symbol.

    The right top node is connected to two voltage sources and has three elements. All other nodes also have three elements. Hence, we select the right top node because by this selection, we already know the node voltages of two other nodes, i.e. the ones that the reference node is connected to them by voltage sources.

    Nodal Analysis - Supernode - Dependent Voltage Source  - The reference node and node voltages

    III. Assign variables for unknown node voltages.
    We label the remaining nodes as shown above. Nodes of  V_3 and  V_4 are connected to the reference node through voltage sources. Therefore,  V_3 and  V_4 can be found easily by the voltages of the voltage sources. For  V_3 , the negative terminal of the voltage source is connected to the node. Thus,  V_3 is equal to minus the source voltage,  V_3=-5 V . The same argument applies to  V_4 and  V_4=-3V .

    IV. Incorporate dependent sources. If there are dependent sources in the circuit, write down equations that express their values in terms of node voltages.

    The voltage of the dependent voltage source is  I_x . We should find this value in terms of the node voltages.  I_x is the current of the  3\Omega – resistor. The voltage across the resistor is  V_2-V_4 . We prefer to define  V_{3\Omega} as  V_2-V_4 instead of  V_4-V_2 to comply with passive sign convention. By defining  V_{3\Omega} as mentioned,  I_x is entering from the positive terminal of  V_{3\Omega} and we have  V_{3\Omega}= 3 \Omega \times I_x . Therefore,  I_x=\frac{V_2-V_4}{3\Omega} .  \to I_x=\frac{V_2}{3} +1

    V. Apply Kirchhoff’s Current Law (KCL) / VI. Handle super-nodes.
    Nodes of  V_1 and  V_2 :
    These two nodes are connected through a voltage source. Therefore, they form a supernode and we can write the voltage of one in terms of the voltage of the other one. Please note that the voltage of the dependent voltage source is  I_x and we have  V_2=V_1+I_x
     \to V_2=V_1+\frac{V_2}{3} +1 \to \frac{2}{3} V_2=V_1+1
     \to V_1=\frac{2}{3} V_2-1

    KCL for the supernode:
     \frac{V_1-V_3}{5\Omega}+\frac{V_1-V_5}{2\Omega}+\frac{V_2-V_4}{3\Omega}-2A=0
     \to \frac{V_1+5}{5}+\frac{V_1-V_5}{2}+\frac{V_2+3}{3}-2=0
     \to \frac{V_1}{5}+\frac{V_1-V_5}{2}+\frac{V_2}{3}=0
     \to 21V_1-15V_5+10V_2=0
    Substituting  V_1=\frac{2}{3} V_2-1 ,
     \to 8V_2-5V_5=7

    Node of  V_5 :
     \frac{V_5-V_1}{2 \Omega} +\frac{V_5-V_3}{1 \Omega}+1=0
     \to -V_1 +3V_5-2V_3+2=0
    Substituting  V_1=\frac{2}{3} V_2-1 and  V_3=-5 V ,
     \to -2 V_2 +9V_5=-39

    Here is the system of equations that we need to solve and obtain  V_2 nd  V_5 :

     \left\{ \begin{array}{l} I: 8V_2-5V_5=7 \\ II: -2 V_2 +9V_5=-39 \end{array} \right.

    VII. Solve the System of Equations.

    We use elimination method to solve this system of equation:
     (II)\times 4 +(I): 31V_5=-149 \to
     V_5=-4.806 V
     V_2=\frac{9V_5+39}{2} \to
     V_2=-2.127 V
    Using  V_1=\frac{2}{3} V_2-1 ,
     V_1=-2.418 V

    VIII. Determine Additional Variables.

    All node voltages are determined. Now, the power of voltage sources can be calculated from the node voltages. For each source, we need to find the voltage across the source as well as the current flowing through it to compute the power.

     2A current source:
    The voltage across the  2A current source is equal to  V_2 . However, the comply with the passive voltage convention, the current should be entering from the positive terminal of the defined voltage as shown below. Therefore,  V_{2A}=-V_2=2.127 V .

     P_{2A}=2A \times V_{2A}=4.254W absorbing power

     1A current source:

    To compliant with the passive sign convention, the voltage  V_{1A} should be defined with polarity as indicated above. We have  V_{1A}= V_5-V_4=-1.806V . Hence,

     P_{1A}=1A \times (-1.806 V)=-1.806W supplying power.

     5V voltage source:

     I_{5V} should be defined such that it enters from the positive terminal of the source in order to use the voltage of the source in power calculation. Another option is to use  V_3 and define the current as entering from the voltage source terminal connected to the node of  V_3 . We use the first approach here. KCL should be applied in the node of  V_3 to determine  I_{5V} .

    KCL @ Node of  V_3 :

     -I_{5V}+I_{1\Omega}+I_{5\Omega}=0
     \to I_{5V}=\frac{V_3-V_5}{1\Omega}+\frac{V_3-V_1}{5\Omega}=-0.7104A

     P_{5V}=5V \times (-0.7104 A)= -3.552 W supplying power.

     3V voltage source:

    Likewise,  I_{3V} should be defined as shown above to comply with the passive sign convention. We apply KCL to the reference node to find  I_{3V} .

    KCL @ the reference node:

     I_{5V}+I_{3V}+2A=0
     \to I_{3V}=-1.29A

     P_{3V}=3V \times (-1.29 A)= -3.87 W supplying power.

    The dependent source:
    The voltage of the dependent source is  I_x and we define its current  I_{I_x} with the direction illustrated above.  I_{I_x} can be calculated by applying KCL at the node of  V_2 . The current of the  3\Omega resistor is  I_x which is equal to  \frac{V_2}{3} +1= 0.291A .

    KCL @ Node of  V_2 : -2A+I_x+I_{I_x}=0 \to I_{I_x}=1.709A

     P_{I_x}=I_x \times I_{I_x}=0.291 V \times 1.709 A= 0.497W absorbing power.

    Download the Circuit File

    To download the LTspice circuit file for your own simulations, click the link below.Please remember to unzip the file after downloading to access the .asc file for your simulations:

  • Nodal Analysis – 6-Node Circuit

    Nodal Analysis – 6-Node Circuit

    Determine the power of each source after solving the circuit by the nodal analysis.

    I. Identify all nodes in the circuit.

    The circuit has 6 nodes as indicated below:

    II. Select a reference node. Label this node with the reference (ground) symbol.

    The bottom left node is connected to 4 nodes while the other ones are connected to three or less elements. Therefore, we select it as the reference node of the circuit.

    III. Assign variables for unknown node voltages.

    We label the remaining nodes as shown above. V_1 is connected to the reference node through a voltage source. Therefore, it is equal to the voltage of the voltage source: V_1=10V.

    IV. Incorporate dependent sources. There are no dependent sources in this circuit.

    V. Apply Kirchhoff’s Current Law (KCL) / VI. Handle super-nodes.

    Nodes of V_2 and V_3 are connected by a voltage source. Therefore, they form a super-node. The negative terminal of the voltage source is connected to V_3 and the positive terminal is connected to V_2. Thus,

        \[V_2=V_3+2.\]

    This can also be verified by a KVL around the loop which starts from the reference node, jumps to the node of V_3 with -V_3 (the reference is always assumed to be the negative terminal of node voltages), passes through the voltage source by -2V and returns back to the reference node from V_2 as +V_2

        \[-V_3-2V+V_2=0 \to V_2=V_3+2.\]

    Super-node of V_2 & V_3:

        \[\frac{V_3}{1\Omega}+\frac{V_3-V_4}{5\Omega}+\frac{V_2-V_1}{2\Omega}+\frac{V_2-V_5}{3\Omega}=0\]

        \[\to {V_3}+\frac{V_3}{5}-\frac{V_4}{5}+\frac{V_3+2-10}{2}+\frac{V_3+2-V_5}{3}=0\]

        \[\to {V_3}+\frac{V_3}{5}-\frac{V_4}{5}+\frac{V_3}{2}-4+\frac{V_3}{3}+\frac{2}{3}-\frac{V_5}{3}=0\]

        \[\to \frac{61}{30}V_3-\frac{V_4}{5}-\frac{V_5}{3}=\frac{10}{3}\]

        \[\to 61 V_3-6 V_4-10 V_5=100\]

    Node of V_4:

        \[\frac{V_4}{6\Omega}+\frac{V_4-V_3}{5\Omega}+10=0\]

        \[\to 5 V_4+6 V_4-6V_3+300=0\]

        \[\to -6V_3+11 V_4=-300\]

    Node of V_5:

        \[\frac{V_5}{4\Omega}+\frac{V_5-V_2}{3\Omega}-10=0\]

        \[\to 3V_5+4V_5-4V_2-120=0\]

        \[\to 7V_5-4 V_3-8-120=0\]

        \[\to -4 V_3+7V_5=128\]

    Hence, we have the following system of equations:

        \[\left\{ \begin{array}{l} 61 V_3-6 V_4-10 V_5=100 \\ -6V_3+11 V_4=-300 \\ -4 V_3+7V_5=128 \end{array} \right.\]

    VII. Solve the System of Equations.

    This system of equations can be solved by any preferred method such as elimination, row reduction, Cramer’s rule or other methods. We use the Cramer’s rule here:

    V_3=\frac{ \left| \begin{array}{c  c  c} 100 & -6 & -10 \ -300 & 11 & 0 \ 128 & 0 & 7 \end{array} \right| }{ \left| \begin{array}{c  c  c} 61 & -6 & -10 \ -6 & 11 & 0 \ -4 & 0 & 7 \end{array} \right| }=\frac{9180}{4005}=2.292 V

    V_4=\frac{ \left| \begin{array}{c  c  c} 61 & 100 & -10 \ -6 & -300 & 0 \ -4 & 128 & 7 \end{array} \right| }{ \left| \begin{array}{c  c  c} 61 & -6 & -10 \ -6 & 11 & 0 \ -4 & 0 & 7 \end{array} \right| }=\frac{-104220}{4005}=-26.022 V

    and

    V_5=\frac{ \left| \begin{array}{c  c  c} 61 & -6 & 100 \ -6 & 11 & -300 \ -4 & 0 & 128 \end{array} \right| }{ \left| \begin{array}{c  c  c} 61 & -6 & -10 \ -6 & 11 & 0 \ -4 & 0 & 7 \end{array} \right| }=\frac{78480}{4005}=19.595 V.

    Thus, [latex]V_2=V_3+2=4.292.

    VIII. Determine Additional Variables.

    After solving for all node voltages, we can calculate the currents and powers for the sources in the circuit as follows:

    • Current of the 10 \, \mathrm{V} Source:

    The current through the 10 \, \mathrm{V} source is the same as the current through the 2 \, \Omega resistor. Using Ohm’s Law, this current is:

        \[I_{10 \, \mathrm{V}} = \frac{V_2 - V_1}{2 \, \Omega} = -2.854 \, \mathrm{A}.\]

    The current direction is chosen such that it enters the positive terminal of the voltage source, in compliance with the \textit{passive sign convention}.

    The power delivered by the 10 \, \mathrm{V} source is then:

        \[P_{10 \, \mathrm{V}} = 10 \times (-2.854) = -28.54 \, \mathrm{W}.\]

    Since the power is negative, the source is \textbf{absorbing power}.

    • Current of the 2 \, \mathrm{V} Source:

    The current through the 2 \, \mathrm{V} source is the sum of the currents through the 5 \, \Omega and 1 \, \Omega resistors. Using Ohm’s Law, we calculate:

        \[I_{2 \, \mathrm{V}} = I_{5 \, \Omega} + I_{1 \, \Omega} = \frac{V_3 - V_4}{5 \, \Omega} + \frac{V_3}{1 \, \Omega}.\]

    Substituting the values:

        \[I_{2 \, \mathrm{V}} = 5.663 + 2.292 = 7.955 \, \mathrm{A}.\]

    The power delivered by the 2 \, \mathrm{V} source is:

        \[P_{2 \, \mathrm{V}} = 2 \times 7.955 = 15.91 \, \mathrm{W}.\]

    Since the power is positive, the source is supplying power.

    • Voltage Across the 10 \, \mathrm{A} Current Source:

    The voltage across the 10 \, \mathrm{A} current source is given by the difference in node voltages:

        \[V_{10 \, \mathrm{A}} = V_4 - V_5 = -45.617 \, \mathrm{V}.\]

    The power delivered by the 10 \, \mathrm{A} source is:

        \[P_{10 \, \mathrm{A}} = 10 \times (-45.617) = -456.17 \, \mathrm{W}.\]

    Since the power is negative, the source is \textbf{supplying power}.

    Download the Circuit File

    To download the LTspice circuit file for your own simulations, click the link below.Please remember to unzip the file after downloading to access the .asc file for your simulations:

  • Electrical Circuits eBooks

    Electrical Circuits eBooks

    Nodal Analysis eBook

    Screenshots

  • Solving Systems of Equations Using Cramer’s Rule

    Solving Systems of Equations Using Cramer’s Rule

    Cramer’s Rule is a powerful method for solving systems of linear equations using determinants. It is particularly effective for small systems where calculating determinants manually is feasible. In this post, we will explain the method step-by-step and provide examples to help you master the technique.


    What is Cramer’s Rule?

    Cramer’s Rule is applicable to systems of linear equations where the number of equations matches the number of variables. The system:

        \[\begin{cases}a_{11}x_1 + a_{12}x_2 + \dots + a_{1n}x_n = b_1 \\a_{21}x_1 + a_{22}x_2 + \dots + a_{2n}x_n = b_2 \\\vdots \\a_{n1}x_1 + a_{n2}x_2 + \dots + a_{nn}x_n = b_n\end{cases}\]

    can be expressed in matrix form as:

        \[A \vec{x} = \vec{b},\]

    where A is the coefficient matrix, \vec{x} is the vector of variables, and \vec{b} is the constants vector.

    To solve for x_1, x_2, \dots, x_n using Cramer’s Rule:

    1. Compute the determinant of the coefficient matrix, \det(A).
    2. Replace the i-th column of A with \vec{b} to create a new matrix A_i.
    3. Solve for each variable using the formula:

        \[x_i = \frac{\det(A_i)}{\det(A)},\]

    provided \det(A) \neq 0.


    Steps to Solve Using Cramer’s Rule

    1. Write the coefficient matrix A and constants vector \vec{b}.
    2. Compute \det(A).
    3. For each variable x_i:
    • Replace the i-th column of A with\ ( \vec{b} \) to form A_i.
    • Compute \det(A_i).
    • Solve for x_i using x_i = \frac{\det(A_i)}{\det(A)}.

    Example 1: Solving a 2×2 System

    Consider the system:

        \[\begin{cases}x + 2y = 5 \\3x - y = 4\end{cases}\]

    Step 1: Write the Coefficient Matrix and Constants Vector

        \[A = \begin{bmatrix}1 & 2 \\3 & -1\end{bmatrix}, \quad \vec{b} = \begin{bmatrix} 5 \ 4 \end{bmatrix}.\]

    Step 2: Compute \det(A)

        \[\det(A) = \begin{vmatrix}1 & 2 \\3 & -1\end{vmatrix}\]

        \[\det(A) = (1)(-1) - (2)(3) = -1 - 6 = -7.\]

    Step 3: Solve for Each Variable

    • Replace the 1st column of A with \vec{b} to get A_1:

        \[A_1 = \begin{bmatrix}5 & 2 \\4 & -1\end{bmatrix}.\]

    Compute \det(A_1):

        \[\det(A_1) = \begin{vmatrix}5 & 2 \\4 & -1\end{vmatrix}\]

        \[\det(A_1) = (5)(-1) - (2)(4) = -5 - 8 = -13.\]

    Solve for x:

        \[x = \frac{\det(A_1)}{\det(A)} = \frac{-13}{-7} = \frac{13}{7}.\]

    • Replace the 2nd column of A with \vec{b} to get A_2:

        \[A_2 = \begin{bmatrix}1 & 5 \\3 & 4\end{bmatrix}.\]

    Compute \det(A_2):

        \[\det(A_2) = \begin{vmatrix}1 & 5 \\3 & 4\end{vmatrix}.\]

        \[\det(A_2) = (1)(4) - (5)(3) = 4 - 15 = -11.\]

    Solve for y:

        \[y = \frac{\det(A_2)}{\det(A)} = \frac{-11}{-7} = \frac{11}{7}.\]

    Solution:

        \[x = \frac{13}{7}, \quad y = \frac{11}{7}.\]

    Below, you can see the lines defined by this system of equations and their intersection point, which represents the solution to the system.


    Example 2: Solving a 3×3 System

    Solve the system:

        \[\begin{cases}2x + y - z &= 1, \\3x - 2y + 4z &= 7, \\x + 3y - 2z &= -3.\end{cases}\]

    Step 1: Write the coefficient matrix A and constants vector \vec{b}:

        \[A = \begin{bmatrix}2 & 1 & -1 \\3 & -2 & 4 \\1 & 3 & -2\end{bmatrix}, \quad\vec{b} = \begin{bmatrix}1 \ 7 \ -3\end{bmatrix}.\]

    Step 2: Compute \det(A):

        \[\begin{split}\det(A) = &2(-2 \times -2 - 4 \times 3) \\&- 1(3 \times -2 - 4 \times 1) \\&- 1(3 \times 3 - (-2 \times 1)).\end{split}\]

        \[\begin{split}\det(A) &= 2(4 - 12) - 1(-6 - 4) - 1(9 + 2) \\&= 2(-8) + 10 - 11 \\ &= -16 + 10 - 11 \\&= -17.\end{split}\]

    Step 3: Solve for x_1, x_2, and x_3:

    Solve for x_1:

    Replace the first column of A with \vec{b}:

        \[A_1 = \begin{bmatrix}1 & 1 & -1 \\7 & -2 & 4 \\-3 & 3 & -2\end{bmatrix}.\]


        \[\begin{split}\det(A_1) = &1(-2 \times -2 - 4 \times 3) \\&- 1(7 \times -2 - 4 \times -3) \\&+ (-1)(7 \times 3 - (-2 \times -3)).\end{split}\]


        \[\begin{split}\det(A_1) &= 1(4 - 12) - 1(-14 + 12) - (21 - 6) \\&= -8 + 2 - 15 \\&= -21.\end{split}\]


        \[x_1 = \frac{\det(A_1)}{\det(A)} = \frac{-21}{-17} = \frac{21}{17}.\]

    Solve for x_2:

    Replace the second column of A with \vec{b}:

        \[A_2 = \begin{bmatrix}2 & 1 & -1 \\3 & 7 & 4 \\1 & -3 & -2\end{bmatrix}.\]


        \[\begin{split}\det(A_2) = &2(7 \times -2 - 4 \times -3) \\&- 1(3 \times -2 - 4 \times 1) \\&+ (-1)(3 \times -3 - 7 \times 1).\end{split}\]


        \[\begin{split}\det(A_2) &= 2(-14 +12) - 1(-6 - 4) - 1(-9 - 7) \\&= 2(-2) + 10 +16 \\&= -4 + 10 + 16 \\&= 22.\end{split}\]


        \[x_2 = \frac{\det(A_2)}{\det(A)} = \frac{22}{-17} = -\frac{22}{17}.\]

    Solve for x_3:

    Replace the third column of A with \vec{b}:

        \[A_3 = \begin{bmatrix}2 & 1 & 1 \\3 & -2 & 7 \\1 & 3 & -3\end{bmatrix}.\]


        \[\begin{split}\det(A_3) = &2(-2 \times -3 - 7 \times 3) \\&- 1(3 \times -3 - 7 \times 1) \\&+ 1(3 \times 3 - (-2 \times 1)).\end{split}\]


        \[\begin{split}\det(A_3) &= 2(6 - 21) - 1(-9 - 7) + 1(9 + 2) \\&= 2(-15) + 16 + 11 \\&= -30 + 16 + 11 \\&= -3.\end{split}\]


        \[x_3 = \frac{\det(A_3)}{\det(A)} = \frac{-3}{-17} = \frac{3}{17}.\]

    Solution:

        \[x_1 = \frac{21}{17}, \quad x_2 = -\frac{22}{17}, \quad x_3 = \frac{3}{17}.\]

    Below is an interactive plot displaying three planes defined by the system of equations, along with their intersection point, which represents the solution to the system. You can change the viewpoint by dragging the plot to explore the relationship between the planes and their intersection more effectively. Enjoy visualizing the solution!


    Example 3: Special Case – No Solution

    Solve the system:

        \[\begin{cases}x + y + z &= 2, \\2x + 2y + 2z &= 5, \\x - y + z &= 1.\end{cases}\]

    Step 1: Write the coefficient matrix A and constants vector \vec{b}:

        \[A = \begin{bmatrix}1 & 1 & 1 \\2 & 2 & 2 \\1 & -1 & 1\end{bmatrix}, \quad\vec{b} = \begin{bmatrix}2 \ 5 \ 1\end{bmatrix}.\]

    Step 2: Compute \det(A):

        \[\begin{split}\det(A) &= 1(2 \times 1 - 2 \times -1) \\&- 1(2 \times 1 - 2 \times 1) \\&+ 1(2 \times -1 - 2 \times 1).\end{split}\]


        \[\det(A) = 1(2 + 2) - 1(2 - 2) + 1(-2 - 2) = 4 - 0 - 4 = 0.\]

    Since \det(A) = 0, the system is inconsistent and has no solution.

    Below, you can see a plot of three planes defined by this system of equations. You can change the viewpoint by dragging the plot for a better perspective. As you observe, these three planes do not intersect at any point, indicating that there is no solution for this system of equations.


    Example 4: Special Case – Infinitely Many Solutions

    Solve the system:

        \[\begin{cases}x + y + z &= 3, \\2x + 2y + 2z &= 6, \\x - y + z &= 1.\end{cases}\]

    Step 1: Write the coefficient matrix A and constants vector \vec{b}:

        \[A = \begin{bmatrix}1 & 1 & 1 \\2 & 2 & 2 \\1 & -1 & 1\end{bmatrix}, \quad\vec{b} = \begin{bmatrix}3 \ 6 \ 1\end{bmatrix}.\]

    Step 2: Compute \det(A):

        \[\begin{split}\det(A) =& 1(2 \times 1 - 2 \times -1) \\&- 1(2 \times 1 - 2 \times 1) \\&+ 1(2 \times -1 - 2 \times 1).\end{split}\]


        \[\begin{split}\det(A) &= 1(2 + 2) - 1(2 - 2) + 1(-2 - 2) \\&= 4 - 0 - 4 \\&= 0.\end{split}\]

    Since \det(A) = 0, we check consistency.

    The second equation is a multiple of the first, indicating a dependency between them. As a result, the system has infinitely many solutions. Essentially, instead of three distinct equations, we only have two, which means there are two planes that intersect along a line, resulting in infinitely many solutions.Below, you can see a plot of three planes defined by this system of equations. You can change the viewpoint by dragging the plot for a better perspective. To observe the relationship between the planes, you can toggle their visibility by clicking on their names in the legend. You’ll notice that the first and second planes overlap completely. The infinitely many solutions for this system of equations can be expressed as the line x = 2t, \, y = 1, \, z = 2 - 2t


    Python Code

    Here is the Python code to define and solve the examples above . It includes calculations for determinants and solutions for each case.

    import numpy as np
    
    # Function to compute determinant of a matrix
    def determinant(matrix):
        return round(np.linalg.det(matrix), 2)
    
    # Function to solve a system using Cramer's Rule
    def cramers_rule(A, b):
        det_A = determinant(A)
        if det_A == 0:
            print("Det(A) = 0, system may have no solution or infinitely many solutions.")
            return None
    
        solutions = []
        n = len(b)
        for i in range(n):
            Ai = np.copy(A)
            Ai[:, i] = b
            det_Ai = determinant(Ai)
            solutions.append(det_Ai / det_A)
        return solutions
    
    # Example 1: Solving a 2x2 System
    A1 = np.array([[1, 2],
                   [3, -1]])
    b1 = np.array([5, 4])
    
    print("Example 1: Solving a 2x2 System")
    solutions_1 = cramers_rule(A1, b1)
    if solutions_1:
        print(f"Solutions: x1 = {solutions_1[0]}, x2 = {solutions_1[1]}")
    
    # Example 2: Solving a 3x3 System
    A2 = np.array([[2, 1, -1],
                   [3, -2, 4],
                   [1, 3, -2]])
    b2 = np.array([1, 7, -3])
    
    print("\nExample 2: Solving a 3x3 System")
    solutions_2 = cramers_rule(A2, b2)
    if solutions_2:
        print(f"Solutions: x1 = {solutions_2[0]}, x2 = {solutions_2[1]}, x3 = {solutions_2[2]}")
    
    # Example 3: No Solution
    A3 = np.array([[1, 1, 1],
                   [2, 2, 2],
                   [1, -1, 1]])
    b3 = np.array([2, 5, 1])
    
    print("\nExample 3: No Solution")
    det_A3 = determinant(A3)
    if det_A3 == 0:
        print("Det(A) = 0. The system has no solution (inconsistent).")
    
    # Example 4: Infinitely Many Solutions
    A4 = np.array([[1, 1, 1],
                   [2, 2, 2],
                   [1, -1, 1]])
    b4 = np.array([3, 6, 1])
    
    print("\nExample 4: Infinitely Many Solutions")
    det_A4 = determinant(A4)
    if det_A4 == 0:
        print("Det(A) = 0. The system has infinitely many solutions (dependent equations).")
  • Solving Systems of Equations Using the Row Reduction Method

    Solving Systems of Equations Using the Row Reduction Method

    Understanding how to solve systems of equations is a foundational skill in algebra and linear algebra. One of the most powerful methods for solving these systems is row reduction, which leverages matrices to streamline the solution process. In this post, we will cover the step-by-step process of solving systems of linear equations using the row reduction method and provide detailed examples to ensure clarity.

    (more…)
  • Nodal Analysis – Five-Node Circuit

    Nodal Analysis – Five-Node Circuit

    Use nodal analysis to solve the circuit shown below and determine the power of node V_{s_2}.

    I. Identify all nodes in the circuit.
    The circuit has five nodes as shown below.

    (more…)
  • Solving Systems of Equations Using the Elimination Method

    Solving Systems of Equations Using the Elimination Method

    When solving systems of linear equations, the elimination method is one of the most popular and systematic approaches. This method involves adding or subtracting equations to eliminate one of the variables, allowing us to solve for the other. Once one variable is found, we substitute it back into one of the original equations to find the second variable.


    Steps for Solving Using the Elimination Method

    Here are the general steps for solving a system of equations using the elimination method:

    1. Align the equations so that like terms (variables and constants) are in columns.
    2. Eliminate one variable by adding or subtracting the equations. If necessary, multiply one or both equations by a constant to align coefficients.
    3. Solve for the remaining variable.
    4. Substitute the solution back into one of the original equations to find the other variable.
    5. Verify the solution by substituting the values into both original equations.

    Example 1: A Simple Elimination Scenario

    Solve the following system of equations:

     \begin{aligned}[t] 2x + 3y &= 8 \\  4x - 3y &= 10 \end{aligned}

    Step 1: Align the equations

    The equations are already aligned:

    \begin{aligned}2x + 3y &= 8 \\ 4x - 3y &= 10 \end{aligned}

    Step 2: Eliminate one variable

    Notice that the coefficients of y are opposites: +3y  in the first equation and −3y in the second equation. To eliminate y, add the two equations:

    (2x+3y)+(4x -3y)=8+10

    Simplify:

    6x=18

    Step 3: Solve for x

    Divide both sides by 6:

    x=3

    Step 4: Solve for y

    Substitute  x=3 into one of the original equations. Let’s use the first equation:

    2(3)+3y=8

    Simplify:

    6+3y=8

    Subtract 6 from both sides:

    3y=2

    Divide by 3:

    y=\frac{2}{3}

    Step 5: Verify the solution

    Substitute x=3 and y=\frac{2}{3}​​ into both original equations to confirm they work:

    1. For 2x+3y=8:  2(3) + 3\left(\frac{2}{3}\right) = 8 \quad \text{✓}
    2. For 4x−3y=10:  4(3) - 3\left(\frac{2}{3}\right) = 10 \quad \text{✓}

    Thus, the solution is: \boxed{(x, y) = (3, \frac{2}{3})}

    Visualization

    In the plot below, you can see the two lines represented by the equations. The point of intersection, marked on the graph, represents the solution to the system of equations.


    Example 2: Multiplying to Align Coefficients

    Solve the following system of equations:

     \begin{aligned}[t] 2y + 3x&= 12 \\ 5x - 4y &= -2 \end{aligned}

    Step 1: Align the equations

    The equations are aligned below:

      \begin{aligned}[t]  3x + 2y &= 12 \\ 5x - 4y &= -2  \end{aligned}

    Step 2: Eliminate one variable

    We need to align the coefficients of either x or y. Let’s eliminate y. To do this, multiply the first equation by 2 and the second equation by 1 (so that the coefficients of y are opposites):

     \begin{aligned}[t] 2(3x + 2y) &= 2(12) \\ 1(5x - 4y) &= 1(-2) \end{aligned}

    This gives us:

     \begin{aligned}[t] 6x + 4y &= 24 \\ 5x - 4y &= -2 \end{aligned}

    Now, add the equations to eliminate y:

     (6x + 4y) + (5x - 4y) = 24 + (-2)

    Simplify: 11x = 22

    Step 3: Solve for x

    Divide both sides by 11: x = 2

    Step 4: Solve for y

    Substitute x=2 into one of the original equations. Let’s use the first equation:

     3(2) + 2y = 12

    Simplify:

     6 + 2y = 12

    Subtract 6 from both sides:

     2y = 6

    Divide by 2:

     y = 3

    Step 5: Verify the solution

    Substitute  x = 2  and  y=3  into both original equations to confirm they work:

    1. For 3x+2y=12:  3(2) + 2(3) = 12 \quad \text{✓}
    2. For 5x−4y=−2:  5(2) - 4(3) = -2 \quad \text{✓}

    Thus, the solution is: \boxed{(x, y) = (2, 3)}

    Visualization

    The plot below illustrates the two lines corresponding to the equations. The intersection point indicates the solution to the system of equations.


    Example 3: Infinite Solutions

    Sometimes, a system of equations can have infinite solutions (the equations represent the same line). Let’s look at an example.

    Solve the following system:

     \begin{aligned}[t] 2x + 4y &= 8 \\ x + 2y &= 4 \end{aligned}

    Step 1: Align the equations

    The equations are already aligned:

     \begin{aligned} 2x + 4y &= 8 \\ x + 2y &= 4 \end{aligned}

    Step 2: Eliminate one variable

    Notice that the second equation is just half of the first. Multiply the second equation by 2:

     \begin{aligned} 2x + 4y &= 8 \\ 2x + 4y &= 8 \end{aligned}

    Subtract the second equation from the first:

     (2x + 4y) - (2x + 4y) = 8 - 8

    Simplify:

     0 = 0

    This is a true statement, meaning the two equations represent the same line. Therefore, there are infinite solutions.

    Visualization

    The plot below shows the two equations as overlapping lines, indicating that every point on the line is a solution to the system.

    Example 4: No Solution

    Also, a system of equations can have no solution (the lines are parallel). Here is an example.

    Solve the following system of equations:

     \begin{aligned}[t] 2x + 3y &= 6 \\ 6y + 4x &= 15 \end{aligned}

    Step 1: Align the equations

    The equations are aligned below:

     \begin{aligned}[t] 2x + 3y &= 6 \ 4x + 6y &= 15 \end{aligned}

    Step 2: Eliminate one variable

    To eliminate one variable, we need to make the coefficients of either x or y the same. Let’s eliminate x. Multiply the first equation by 2 so that the coefficients of x: match:

     \begin{aligned}[t] 2(2x + 3y) &= 2(6) \\ 4x + 6y &= 15 \end{aligned}

    This gives us:

     \begin{aligned}[t] 4x + 6y &= 12 \\ 4x + 6y &= 15 \end{aligned}

    Now subtract the first equation from the second:

     (4x + 6y) - (4x + 6y) = 15 - 12

    Simplify:

     0 = 3

    This is a false statement, meaning the system of equations has no solution. The two lines are parallel and never intersect.

    Visualization

    The plot below illustrates the two parallel lines, confirming that there is no point of intersection. This graphical representation helps to visualize why the system has no solution.


    Example 5: Solving a 3×3 System of Equations

    Solve the following system of equations:

        \[\begin{cases}x + 2y + z &= 8 \\2x + y - z &= 3 \\3x - y + 2z &= 7\end{cases}\]

    Step 1: Align the equations
    The equations are already aligned:

        \[\begin{cases}x + 2y + z &= 8 \\2x + y - z &= 3 \\3x - y + 2z &= 7\end{cases}\]

    Step 2: Eliminate one variable
    We will eliminate ( z ) first. To do this, we can use the first two equations. We can add the first equation to the second equation after adjusting the coefficients of ( z ).

    First, we can rewrite the second equation to align ( z ):

        \[2x + y - z = 3 \quad \text{(no change needed)}\]

    Now, we can add the first equation to the second equation:

        \[\begin{aligned}(x + 2y + z) + (2x + y - z) &= 8 + 3 \\3x + 3y &= 11\end{aligned}\]


    Simplify:

    (Eq 4)   \[x + y = \frac{11}{3} \quad \]

    Next, we will eliminate ( z ) using the first and third equations. We can rewrite the first equation to align ( z ):

        \[2x + 4y + 2z = 16 \quad \text{(multiplied by two)}\]

    Now, we can add the first equation to the third equation after adjusting the coefficients of ( z ):

        \[(3x - y + 2z) - (2x + 4y + 2z) &= 7 - 16\]


    Simplify:


    (Eq 5)   \[x - 5y = -9 \quad \]

    Step 3: Solve for one variable
    Now we have two new equations (Equation 4 and Equation 5):

    1. x + y = \frac{11}{3} (Equation 4)
    2. x - 5y &= -9 (Equation 5)

    We can solve Equation 4 for x:

        \[x = \frac{11}{3} - y\]

    Substituting x into Equation 5:


        \[\left(\frac{11}{3} - y\right) - 5y = -9\]


    Simplify:


        \[\frac{11}{3} - y - 5y = -9\]


    Combine like terms:


        \[\frac{11}{3} - 6y = -9\]


    Multiply through by 3 to eliminate the fraction:


        \[11 - 18y = -27\]


    Subtract 11 from both sides:


        \[-18y = -38\]


    Divide by -18:

        \[y = \frac{19}{9}\]

    Step 4: Solve for x and z
    Substituting y = \frac{19}{9} back into Equation 4:

        \[x + \frac{19}{9} = \frac{11}{3}\]


    Subtract \frac{19}{9} from both sides:


        \[x = \frac{11}{3} - \frac{19}{9} = \frac{33-19}{9} = \frac{14}{9}\]

    Now, substitute x = \frac{14}{9} and y =  \frac{19}{9} back into the first original equation to find z:

        \[ \frac{14}{9} + 2\left( \frac{19}{9}\right) + z = 8\]


    Simplify:


        \[ \frac{14}{9} + \frac{38}{9} + z = 8\]


    Combine the fractions:


        \[\frac{52}{9} + z = 8\]


    Subtract \frac{52}{9} from both sides:


        \[z = 8 - \frac{52}{9} = \frac{72}{9} - \frac{52}{9} = \frac{20}{9}\]

    Step 5: Verify the solution
    Substitute x = \frac{14}{9}, y =  \frac{19}{9}, and z = \frac{20}{9} into all original equations to confirm they work:

    1. For x + 2y + z = 8:

          \[\begin{aligned}&\frac{14}{9} + 2\left(\frac{19}{9} \right) + \frac{20}{9} \\&= \frac{14}{9}  + \frac{38}{9} + \frac{20}{9} \\&= \frac{14+38+20}{9} \\&= 8 \quad \text{\checkmark}\end{aligned}\]

    2. For 2x + y - z = 3:

          \[\begin{aligned}&2(\frac{14}{9}) + \frac{19}{9} - \frac{20}{9}  \\&= \frac{28}{9} + \frac{19}{9} -  \frac{20}{9} \\&= - \frac{28+19-20}{9} \\&= 3 \quad \text{\checkmark}\end{aligned}\]

    3. For 3x - y + 2z = 7:

          \[\begin{aligned}&3(\frac{14}{9}) - \frac{19}{9} + 2\left(\frac{20}{9} \right) \\&= \frac{42}{9} - \frac{19}{9} + \frac{40}{9} \\&=  \frac{42-19+40}{3} \\&= 7 \quad \text{\checkmark}\end{aligned}\]

    Thus, the solution is: \boxed{(x, y, z) = \left(\frac{14}{9}, \frac{19}{9}, \frac{20}{9}\right)}

    Visualization

    The plot below illustrates the three planes represented by the equations. The point of intersection, marked on the graph, represents the unique solution to the system of equations.


    Key Takeaways

    • The elimination method is a powerful way to solve systems of equations by eliminating one variable at a time.
    • Always align your equations properly and, if necessary, multiply through by constants to align coefficients.
    • Verify your solution by substituting the values into both original equations.
    • Keep an eye out for special cases like infinite solutions or no solution.