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 wor

ID: 3682500 • 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

can be represented in matrix form as

or, more succinctly, as

The system has a solution if and only if is invertible (, where ). If is invertible, the system has the solution . This is obtained by left-multiplying both sides of the equation by the inverse of . In MATLAB, this operation (left-multiply by inverse) is streamlined by the matrix left-divide operator ().

Write a script (task2.m) that prompts the user for the four values and the two values and outputs the solution to the corresponding system of linear equations, or prints an error message if no solution exists.

Example:

>> task2

a11 = 8

a12 = 6

b1 = 3

a21 = 7

a22 = 5

b2 = 0

x =

-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.%

This above code may help you solve the given systen of equations