create a matlab function mfile called mymatrixsolver to solv


create a matlab function m-file called my_matrix_solver to solve a system of linear equations, using nested for loops instead of matlab\'s built-in operators or functions. Your function should accept a coeffecient matrix and a result matrix, and should return the values of the variables. For example, if you wish to solve the following matrix equation for X     

AX = B

your function should accept A and B as input, and return X as the result.

Solution

Solving the system of linear equations done by below 3 ways

     Using inverse of a matrix

Ax = b

A-1Ax = A-1b

X = A-1b

So write the above in Matlab

>>A =[3 2 -1; -1 3 2 ; 1 -1 -1]; % accepting the matrix A

>>b = [10; 5; -1];

>>x =inv(A)*b

% or use “\\” back slash

>>A\\b

%use linesolve also

>>linsolve(A,B);

Taking runtime input

>>syms A

>>syms B

>>Enter Matrix as input

>>A=input(\'Enter the Matrix: \ \')

>>B = input(‘enter the matrix: \ ’)

>>x=inv(A)*B;

 create a matlab function m-file called my_matrix_solver to solve a system of linear equations, using nested for loops instead of matlab\'s built-in operators o

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site