Presentation is loading. Please wait.

Presentation is loading. Please wait.

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 22P. 1Winter Quarter MATLAB: Simultaneous.

Similar presentations


Presentation on theme: "Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 22P. 1Winter Quarter MATLAB: Simultaneous."— Presentation transcript:

1 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 22P. 1Winter Quarter MATLAB: Simultaneous Equations Lecture 22

2 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 22P. 2Winter Quarter Simultaneous Equations with MATLAB MATLAB is a very powerful tool 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 –numerous other engineering applications. It can, of course, be used for any application with n equations and n unknowns.

3 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 22P. 3Winter Quarter Simultaneous Equations with MATLAB For example, let's suppose that: –a Calculus text (C), a Physics text (P) and a Graphics text (G) can be purchased for $146. –a Calculus text and a Graphics text can be purchased for $87 –a Physics text and Calculus text can be purchased for $105. How much does each text cost?

4 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 22P. 4Winter 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 The Ohio State University Gateway Engineering Education Coalition Lect 22P. 5Winter 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 The Ohio State University Gateway Engineering Education Coalition Lect 22P. 6Winter 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 The Ohio State University Gateway Engineering Education Coalition Lect 22P. 7Winter 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 The Ohio State University Gateway Engineering Education Coalition Lect 22P. 8Winter 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.


Download ppt "Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 22P. 1Winter Quarter MATLAB: Simultaneous."

Similar presentations


Ads by Google