Create a Matlab Function file and a script file that runs the function. When run
ID: 2267423 • 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.
Write the following set of equations in matrix form: X2 4x2 +7x3 30 0 x1 7x3 40 3x2 5x Use MATLAB to solve for the unknowns. In addition, use it to compute the transpose and the inverse of the coefficient matrixExplanation / Answer
MATLAB code:
clear all
clc
syms x1 x2 x3; % initializing the coefficients
equ1= 0*x1 - 7*x2 + 5*x3 == 50; % equation 1 coefficients
equ2= 0*x1 + 4*x2 + 7*x3 == -30; % equation 2 coefficients
equ3= -4*x1 + 3*x2 - 7*x3 == 40; % equation 3 coefficients
[A,B] = equationsToMatrix([equ1, equ2, equ3], [x1, x2, x3]) % converting the equations to matrix and saving in different terms A and B
X = linsolve(A,B) % using the code linsolve(linear solve so that the equations are solved
tran= transpose(A) % transpose of coefficient matrix
inverse= inv(A) % inverse of coefficient matrix
Matlab Output:
A =
[ 0, -7, 5]
[ 0, 4, 7]
[ -4, 3, -7]
B =
50
-30
40
X =
-2095/138
-500/69
-10/69
tran =
[ 0, 0, -4]
[ -7, 4, 3]
[ 5, 7, -7]
inverse =
[ -49/276, -17/138, -1/4]
[ -7/69, 5/69, 0]
[ 4/69, 7/69, 0]
if you are having any doubt please comment here or else rate me.