Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

OBJECTIVE: Use matrix math to solve a system of linear equations You should work

ID: 3597956 • Letter: O

Question

OBJECTIVE: Use matrix math to solve a system of linear equations You should work on this task individually, but you may discuss results with your teammates. The system of linear equations 12*2 22*2 can be represented in matrix form as a121 111 a221 LX2llb l21 or, more succinctly, as The system has a solution if and only if A is invertible (det(A) 0, where det(A) = a, a22 a 2a21). If A is invertible, the system has the solution x = A-lb. This is obtained by left- multiplying both sides of the equation by the inverse of A. In MATLAB, this operation (left- multiply by inverse) is streamlined by the matrix left-divide operator (V) Write a script (task2.m) that prompts the user for the four a values and the two b values and outputs the solution to the corresponding system of linear equations, or prints an error message if no solution exist:s Example: >>task2 a11 = 8 a12 6 b1 = 3 a21 = 7 a22 = 5 b2 = 0 7.5000 10.5000

Explanation / Answer

prompt = 'read the a11 value';
a11 = input(prompt)

prompt = 'read the a12 value';
a12 = input(prompt)

prompt = 'read the a21 value';
a21 = input(prompt)

prompt = 'read the a22 value';
a22 = input(prompt)

prompt = 'read the b1 value';
b1 = input(prompt)

prompt = 'read the b2 value';
b2 = input(prompt)

X = [a11 a12 ; a21 a22]

Z = [b1;b2]

Y = inv(X)

R = Y * X

S = linsolve(X,Z)

% Examine why solving a linear system by inverting the matrix using inv(A)*b is inferior to solving it directly using the backslash operator, x = A.%