Advanced Math/MATRICES USING MATLAB
Expert: Sherry Wallin - 6/21/2011
QuestionQUESTION: Hello there,
i need some step by step method solving these as i havent come across these before, i normally use mesh analysis, but do you have any other method ?
a1-a2+b1 = 2
a2-a3+b1+b2=10
a3-a4+b2=-3
a1+a2-b1=0
a2+a3+b1-b2=0
a3+a4+b2=0
i need to solve to find values a1,a2,a3,a4,b1,b2
and how would i do them using matlab commands
any help would be grate !!"
ANSWER: John~
We can do this problem by hand using matrices. For every variable in each row we put the coefficient of the variable in the cell. If there is no variable (it is missing), we just put a 0. The last column is the constant (the value each equation is equal to). We have 6 equations and 6 unknowns so there should be at least one solution to this system of equations, provided there are no contradictions, i.e., no row where you get all 0's on the left and a nonzero constant on the right hand side. On the excel spreadsheet I have created there are 'blocks' for 6 rows and 7 columns, where the columns are labeled a1,a2,a3,a4,b1,b2, and c for constant. The rows are labeled R1, R2,...,R6. The first block is just the matrix with your original 6 equations. Our goal is to make 1's along the diagonal which means in the first row, first column we make it a 1 and everything else in the first column a zero using algebraic operations. This is called 'pivoting' on the element in A(1,1) where A is the name of the matrix and the first 1 is the row number and the 2nd number is the column number. I have labeled in the row where the changes occur from the algebraic operations used. For example, in the 2nd block a change was made to R4 so you will see in the column to the left of R4: R1 - R4 = R4 which means subtract the coefficients of row 4 from the coefficients of row 1 and the result becomes the 'new' row 4. Row 4 in the 2nd block now says -2a1 + 2b1 = 2.
We can tell in the 4th block in the 6th row that -2a4 = -3 or a4 = 3/2. We won't jump there right yet but it can be seen already.
Attached is a 6x6 system solved via matrices. Please feel free to ask questions if you have any. I can also help you with Matlab commands as well.
Math Prof
---------- FOLLOW-UP ----------
QUESTION: hi thanks, took a while to understand but will get there,
how would i input the commands into matlab ?
AnswerFirst you need to enter the matrix and then give it the command solve.
You will want to name your matrix so call it A.
Now say A = [1 -1 0 0 1 0 2; 0 1 -1 0 1 1 10; 0 0 1 -1 0 1 3; 1 1 1 0 0 -1 0 0: 0 1 1 0 1 -1 0; 0 0 1 1 0 1 0] and hit enter and then on the next line say b = [1;10;-3;0;0;0] and hit enter.
What you have here is Ax = b but you want x since x is the solution to the system. You will want to solve for x using matrix arithmetic:
Ax = b
A^(-1)Ax = A^(-1)b this is the step that simplifies to x = A^(-1)b
In Matlab the commands will be:
B = inv(A) enter
B*A = B*b which will give you x.
Math Prof