Create a Matlab Function file and a script file that runs the function. When run
ID: 2255060 • Letter: C
Question
Create a Matlab Function file and a script file that runs the function. When running the script, the answer's should display on the screen.
Post a clear picture of the hand written work if the problem asks for hand written work.
Comment the MatLab code so I can understand it. I should be able to just copy and paste the code and have it run.
The work and answer should match the answer posted.
Post the code and written work.
Given the equations 2x1 – 6x2 - x3 = -38 – 3x - x2 + 7x3 = -34 -8x1 + x2 - 2x3 = -20 (a) Solve by Gauss elimination with partial pivoting. Show all steps of the computation. (b) Substitute your results into the original equations to check your answers. Answer: X1=4, x2=8, X3=-2Explanation / Answer
(a) Given set of linear equations are of the form AX = B, where
Enter the following MATLAB code
A = [2 -6 -1;-3 -1 7; -8 1 -2];
B = [-38;-34;-20];
X = mldivide(A,B); % mldivide is the MATLAB function to solve set of linear equations
By entering above MATLAB we will get the solution to given set of linear equations as,
X = [4;8;-2]
where x1 = X(1) = 4, x2 = X(2) = 8, x3 = X(3) = -2
(b) Given set of linear equations:
2x1 - 6x2 - x3= -38 -------> (1)
-3x1 - x2 + 7x3 = -34 -------> (2)
-8x1 + x2 - 2x3 = -20 ----------> (3)
substituting the values of x1 = 4, x2 = 8, x3 = -2 in (1), we have
8 - 48 + 2 = -38
Similarly substituting the values of x1,x2,x3 in (2), we have
-12 - 8 -14 = -34
substituting the values in (3), we have
-32 + 8 + 4 = -20