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

Matlab question Complete the implementation of the linSys_1 function, which solv

ID: 3111724 • Letter: M

Question

Matlab question

Complete the implementation of the linSys_1 function, which solves a system of simultaneous linear equations.

The function should return a vector x which is the solution of the system of equations below.

Input variable:

Output variables:

Hint: You can verify your solution by substituting the values of x produced by your function into the original system of equations.

-2.64 x1 + 6.23 x2 + 5.81 x3 + 3.38 x4 = 1.32 -0.46 x1 + 3.96 x2 + -3.65 x3 + 7.99 x4 = -1.13 6.28 x1 + 2.76 x2 + -2.63 x3 + 0.11 x4 = -8.37 9.91 x1 + -0.87 x2 + -0.61 x3 + 9.79 x4 = 8.86

Explanation / Answer

If you are using matlab version which is newer than R2012b :

function X=linSys_1()
syms x1 x2 x3 x4 % listing variables

% writing equations
eqn1 = (-2.64)*x1 + 6.23*x2 + 5.81*x3+ 3.38*x4 == 1.32;
eqn2 = (-0.46)*x1 + 3.96*x2 + (-3.65)*x3+ 7.99*x4 == -1.13;
eqn3 = 6.28*x1 + 2.76*x2 -2.63*x3+ 0.11*x4 == -8.37;
eqn4 = 9.91*x1 -0.87*x2 -0.61*x3+ 9.79*x4 == 8.86;
[A1,B1] = equationsToMatrix([eqn1, eqn2, eqn3, eqn4], [x1,x2,x3,x4]); % using the equationsToMatrix function to get matrix vectors A and B as in AX=B
A=double(A1);
B=double(B1);

X = linsolve(A,B); % linsolve function solves the linear equations


end

if you're using older versions:

function X=linSys_1()

% writing given linear equations in the form of AX=B gives A and B as follows
A=[-2.64    6.23    5.81    3.38;
   -0.46    3.96   -3.65 7.99;
    6.28    2.76   -2.63    0.11;
    9.91   -0.87   -0.61    9.79]
B=[ 1.32;
   -1.13;
   -8.37;
    8.86]
X=AB; % It solves the linear equations. it is nothing but matrix left division (mldivide)
end

Answer:


X =

   -0.2393
   -1.4929
    1.0896
    1.0825