Download presentation
Presentation is loading. Please wait.
Published byBryce Walker Modified over 9 years ago
2
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 22P. 1Winter Quarter MATLAB: Simultaneous Equations Lecture 22
3
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 22P. 2Winter Quarter Simultaneous Equations with MATLAB MATLAB is very powerful for solving systems of N equations with N unknowns. It is used extensively for analyzing electric power grids and circuits, fluid flow in piping systems, and other engineering applications. It can, of course, be used for any application with n equations and n unknowns. For example, suppose that a Calculus text (C), a Physics text (P) and a Graphics text (G) can be purchased for $146. Then suppose the Calculus and Graphics texts can be purchased for $87 and the Physics and Calculus texts can be purchased for $105. How much does each text cost?
4
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 22P. 3Winter Quarter Simultaneous Equations with MATLAB The problem can be written as: 1P + 1C + 1G = 146 1C + 1G = 87 1P + 1C = 105 In MATLAB, the coefficients of the variables P, C & G are placed in a matrix and the Dollar values in a column vector. >>Books=[1,1,1;0,1,1;1,1,0] Books = 1 1 1 0 1 1 1 1 0 >>Dollars=[146;87;105] Dollars = 146 87 105
5
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 22P. 4Winter Quarter Simultaneous Equations with MATLAB Now, the inverse of the matrix Books is multiplied by the vector Dollars: >>Cost = inv (Books) * Dollars Cost = 59 46 41 This vector contains the cost of P in row one, C in row 2 and G in row 3.
6
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 22P. 5Winter Quarter Simultaneous Equations with MATLAB Another MATLAB solution would be to use the reverse division sign as follows: >>Cost = Books \ Dollars Cost = 59 46 41
7
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 22P. 6Winter Quarter Simultaneous Equations with MATLAB A third MATLAB solution can be obtained by using the Row Reduced Echelon Form (rref) function as follows. First combine the matrix and vector: EDU» COMBINED=[Books Dollars] COMBINED = 1 1 1 146 0 1 1 87 1 1 0 105
8
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 22P. 7Winter Quarter Simultaneous Equations with MATLAB Then invoke the rref function with the resulting matrix. >> Cost = rref (COMBINED) Cost = 1 0 0 59 0 1 0 46 0 0 1 41 The last column in the new matrix is the cost vector.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.