Download ModelDownload Sourceembed

About

1instructorguide

These exercises are designed to get students started on using computers to solve systems of linear equations. Students should have some experience in an appropriate computational package before attempting this. Mathematica is a very good choice of tools for this exercise, closely followed by Python/numpy and MatLab. C/C++ also works, with appropriate libraries. The systems of equations we’ll be using come from resistor networks typical of a second-semester physics course, but the same techniques can be used for any system of linear equations regardless of their source.

Being able to solve systems of equations is an important computational skill, with applications in everything from mechanical engineering to quantum physics. For small systems of equations it is fairly simple to solve the systems algebraically, but for large complex systems it’s important to be able to solve them numerically using computers.

2theory

We first express the system of equations as a single matrix equation,

(1)Mx=b

Since there are as many equations (rows inΒ M) as there are variables (columns inΒ M),Β MΒ will be a square matrix. If there is a solution to this set of equations, then there will exist another matrixΒ Mβˆ’1Β such thatΒ Mβˆ’1M=I, whereΒ IΒ is the identity matrix. In that case,

(2)Mβˆ’1Mx=Mβˆ’1b
(3)Ix=x=Mβˆ’1b

There are algorithmic methods for findingΒ Mβˆ’1Β (and thusΒ x; in our case we’ll be using standard libraries to calculate this matrix and the corresponding solution. One standard method is to have the computer calculateΒ Mβˆ’1Β directly using an β€œinvert()” function, and then multiply that inverse matrix byΒ bΒ to obtainΒ x.

Most computational packages that have the ability to calculateΒ Mβˆ’1Β also have an additional function, often called β€œsolve()”, that takes care of the multiplication as well, and gives the userΒ xΒ directly.

For more information about how these functions work, seeΒ Numerical Recipes in CΒ by Flannery, Teukolsky, Press, and Vetterling, or similar text.

3exercises

Exercise 1: Introductory Problem

Consider the network of resistors and batteries shown in the first figure below.

There are three unknowns in that circuit,Β I1,Β I2, andΒ I3. We can solve for these unknowns by building a system of equations using Kirchhoff’s Laws:

  1. The sum of voltages around any loop is zero.
  2. The sum of currents at any junction is zero.

Applying the voltage law to the left-hand loop, we get

(4)V1βˆ’I1R1βˆ’I3R3=0

From the right-hand loop, we get

(5)V2+I2R2βˆ’I3R3=0

We need one more equation, for which we can use the junction at top center and the current law:

(6)I1βˆ’I2βˆ’I3=0

We now have the requisite three independent equations, which we can solve using methods learned in high-school algebra.

There’s another way of solving this, using matrix methods. First, rewrite the equations just a bit.

(7)R1I1+0I3+R3I3=V1(8)Β 0I1βˆ’R2I2+R3I3=V2(9)Β I1βˆ’I2βˆ’I3=0

And now we can see that this can be written as a matrix equation!

(10)[R10R3Β 0βˆ’R2R3Β 1βˆ’1βˆ’1][I1Β I2Β I3]=[V1Β V2Β 0]

This matrix equation,

(11)Mx=b

has solution

(12)x=Mβˆ’1b

whereΒ Mβˆ’1Β is theΒ inverseΒ ofΒ M. Most computational packages have built-in capability for inverting matrices.

ASSIGNMENT

  1. By carrying out the matrix multiplication explicitly, show that the matrix equation above reduces to the system of equations from which it is derived.
  2. Use a matrix-solving package to find the currents.
  3. Check your answers by substituting the currents into the equations and verifying that they are solutions.

Exercise 2: More complicated problem

The resistor network below is perhaps a bit more challenging.

ASSIGNMENT

  1. Write a system of equations that can be used to solve for the currents in the circuit above.
  2. Re-write the system of equations from part 1 of this assignment as a matrix equation.
  3. Use a matrix-solving package to find the currents.
  4. Check your answers: do the values of currents you found solve the equations with which you started?
  5. You may notice something interesting if you compare your solution here to your solution for exercise 1. (Assuming the same values ofΒ RΒ andΒ VΒ were used in both exercises.) Explain why this happened.

Unless your instructor provides you with other values, assume each voltage source and each resistor has a valueΒ 10Γ—Β its identifying number. (i.e.Β V2=20Β V,Β R3=30Ξ©.)

5solutions

The set of equations from the assigned problem will vary, here is one possible set.

(13)V1βˆ’R1I1βˆ’R3I3=0
(14)βˆ’R2I2βˆ’V2+R3I3=0
(15)V2βˆ’V3βˆ’R6I6+R5I5=0
(16)R4I4βˆ’R5I5=0
(17)βˆ’V4βˆ’R4I4=0
(18)I1βˆ’I2βˆ’I3=0

This set of equations can be converted to the following matrix equation:

(19)[R10R30000βˆ’R2R30000000βˆ’R5R6000R4R50000βˆ’R4001βˆ’1βˆ’1000][I1I2I3I4I5I6]=[V1V2V2βˆ’V30V40]

The answers are

(20)I1=βˆ’0.091
(21)I2=βˆ’0.455
(22)I3=0.364
(23)I4=βˆ’1
(24)I5=0.8
(25)I6=0.5

It should be noted that for the circuit in the second figure, currentsΒ I1Β throughΒ I3Β are the same as for the first figure, and it may be interesting to discuss with students why that should be the case.

solutionpy

'''

solution.py

Eric Ayars

June 2016

A solution of the 5-loop circuit exercise.

'''

import numpy as np

# Start by getting the values of R and V

R1 = float(input("R1 = "))

R2 = float(input("R2 = "))

R3 = float(input("R3 = "))

R4 = float(input("R4 = "))

R5 = float(input("R5 = "))

R6 = float(input("R6 = "))

V1 = float(input("V1 = "))

V2 = float(input("V2 = "))

V3 = float(input("V3 = "))

V4 = float(input("V4 = "))

# Use these values to build the matrix M. Note that this matrix

# will vary depending on the equation set selected to solve the

# problem: here I use the equations from the solution on the

# PICUP webpage.

M = np.array([ [R1, 0, R3, 0, 0, 0],

[0,-R2, R3, 0, 0, 0],

[0, 0, 0, 0,-R5, R6],

[0, 0, 0, R4, R5, 0],

[0, 0, 0,-R4, 0, 0],

[1, -1, -1, 0, 0, 0] ])

# here is the right-hand-side b:

b = np.array([V1,V2,V2-V3,0,V4,0])

# And this is all it takes to get a solution:

x = np.linalg.solve(M,b)

# show the result.

print(x)

 

Translations

Code Language Translator Run

Software Requirements

SoftwareRequirements


Android iOS Windows MacOS
with best with Chrome Chrome Chrome Chrome
support full-screen? Yes. Chrome/Opera No. Firefox/ Samsung Internet Not yet Yes Yes
cannot work on some mobile browser that don't understand JavaScript such as.....
cannot work on Internet Explorer 9 and below

 

Credits

Fremont Teng; Loo Kang Wee

end faq

Sample Learning Goals

[text]

For Teachers

 

Instructions

Combo Box and Functions

 
Toggling through the combo box will give you their respective functions.
Selecting Solution will give you their respective input fields for
the variables as shown in the diagram above.


Selecting user defined allow you to customise the matrix
of Mgeneral and bgeneral to solve any equation.
 
Note that putting an invalid matrix/solution will catch you an error message.
 

Toggling Full Screen

Click anywhere inside the panel to toggle full screen.
 

Reset Button

 
Resets the simulation.

Research

[text]

Video

[text]

 Version:

  1.  https://www.compadre.org/PICUP/exercises/exercise.cfm?I=118&A=linearEquations
  2. http://weelookang.blogspot.com/2018/05/solving-systems-of-linear-equations.html 

Other Resources

[text]

end faq

Testimonials (0)

There are no testimonials available for viewing. Login to deploy the article and be the first to submit your review!

Submit your review

Please deploy the article before submitting your review!

You have to login first to see this stats.

1 1 1 1 1 1 1 1 1 1 Rating 0.00 (0 Votes)

Article Stats

Article ID: 773
Article Category ID: 45
Opinions
Deployed Users
Total # of Likes
Total # of Dislikes
Total # of Deployment 0
Tags
  • Practical Electricity
  • PICUP
  • Science
  • Simulations