writing a Matlab program solving linear equation system. Using the scaled partia
ID: 3602340 • Letter: W
Question
writing a Matlab program solving linear equation system. Using the scaled partial pivoting method and keep the index vector in the Gauss elimination step. Also program the backward evaluation step. Write the program as a function, with the following variables (in the exact order) as input. 1) n, an integer for the size of the matrix A. 2) A, a n*n matrix, with single precision. 3) b, a n entry vector, with single precision. The output: return the following variable from your program, in the exact order. Notice, do not print your solution on the screen. Use the return command. 1) x, the n entry solution vector, with single precision. 2) l, the n entry vector, which is the final index vector. Use integer format.
Explanation / Answer
Solve System of Linear Equations Using linsolve
A system of linear equations
a11x1+a12x2+…+a1nxn=b1a21x1+a22x2+…+a2nxn=b2am1x1+am2x2+…+amnxn=bm
can be represented as the matrix equation Ax=b, where A is the coefficient matrix,
A=a11am1…a1namn
and b is the vector containing the right sides of equations,
b=b1bm
If you do not have the system of linear equations in the form AX = B, use equationsToMatrix to convert the equations into this form. Consider the following system.
2x+y+z=2x+yz=3x+2y+3z=10
Declare the system of equations.
Use equationsToMatrix to convert the equations into the form AX = B. The second input to equationsToMatrix specifies the independent variables in the equations.
Use linsolve to solve AX = B for the vector of unknowns X.
From X, x = 3, y = 1 and z = -5.
Solve System of Linear Equations Using solve
Use solve instead of linsolve if you have the equations in the form of expressions and not a matrix of coefficients. Consider the same system of linear equations.
2x+y+z=2x+yz=3x+2y+3z=10
Declare the system of equations.
Solve the system of equations using solve. The inputs to solve are a vector of equations, and a vector of variables to solve the equations for.
solve returns the solutions in a structure array. To access the solutions, index into the arr
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.