Using MATLAB develop an Mfile to determine LU factorization

Using MATLAB, develop an M-file to determine LU factorization of a square matrix with partial pivoting. That is, develop a function called mylu that is passed the square matrix [A] and returns the triangular matrices [L] and [U] and the permutation P. You are not to use MATLAB built-in function lu in your codes. Test your function by using it to solve a system of equations listed below in part 3. Confirm that your function is working properly by verifying that [L][U]=P[A] and by using the MATLAB built-in function lu. Using MATLAB, develop an M-file to determine matrix inverse based on the LU factorization method above. That is, develop a function called myinv that is passed the square matrix [A] and utilizing codes of part 1 above to return the inversed matrix. You are not to use MATLAB built-in function inv or left-division in your codes. Test your function by using it to solve a system of equations listed below in part 3. Confirm that your function is working properly by verifying that [A] [A^-1] = [I] and by using the MATLAB built-in function inv. Using MATLAB, develop an M-file for the Gauss-Seidel Method to solve the system of equations listed below until the percent relative error falls below epsilon_s = 5% x_1 + x_2 + 5x_3 = -21.5 -3x_1 -6x_2 + 2x_3 = -61.5 10x_1 + 2x_2 - x_3 = 27

Solution

3)

clc

%Click the run bottom and refer to the command window

%these are the inputs that can be modified by the user

%n = number of equations\'))

n=3;

%[A] = nxn coefficient matrix

A=[1,1,5;
   -3,-6,2;
   10,2,-1];

%[RHS] = nx1 right hand side array

RHS=[-21.5,-61.5,27];

%[X] = nx1 initial guess of the solution vector

X=[1,1,1];

%maxit = maximum number of iterations

maxit=15;

%initializing the absolute relative approximate error array

abs_ea=zeros(n);

%Iterations

%--------------------------------------------------------------------------

%defining the number of iterations to be conducted.

for k=1:maxit

disp(sprintf(\'Iteration number%d\',k))

disp(sprintf(\'Previous iteration values of the solution vector\'))

Xold=X;

Xold

%The following i loop generates the new solution vector:

for i=1:n

%initializing the series sum to zero.

summ=0;

for j=1:n

%Only adding i<> terms.   

if (i<j)

%Generating the summation term.

summ=summ+A(i,j)*X(j);

end

if (i>j)

%generating the summation term.

summ=summ+A(i,j)*X(j);

end

end

%Using Gauss-Seidel method to calculate new [X] term.

X(i)=(RHS(i)-summ)/A(i,i);

end

%Initializing the maximum absolute relative percentage approximate error to zero.

Max_abs_ea=0.05;

%The following i loop generates the maximum absolute relative percentage approximate error for the kth step:

for i=1:n

%Calculating absolute relative percentage approximate error for each Xi.

abs_ea(i)=abs((X(i)-Xold(i))/X(i))*100.0;

%Defining the maximum value of the relative approximate errors.

if abs_ea(i)>Max_abs_ea

Max_abs_ea=abs_ea(i);

end

end

disp(sprintf(\'New iterative values of the solution vector\'))

X

disp(sprintf(\'Absolute relative percentage approximate error\'))

Y=rot90(abs_ea);

abs_e=Y(n,1:n)

disp(sprintf(\'Maximum absolute relative percentage approximate error\'))

Max_abs_ea

end

Output :

Iteration number1

Previous iteration values of the solution vector

Xold = 1 1 1

New iterative values of the solution vector

X = -29.500 25.333 -271.333

Absolute relative percentage approximate error

abs_e = 103.390 96.053 100.369

Maximum absolute relative percentage approximate error

Max_abs_ea = 103.39

-----------------------------------------------------------------------------

Iteration number2

Previous iteration values of the solution vector

Xold = -29.500 25.333 -271.333

New iterative values of the solution vector

X = 1.2592e+03 -7.0978e+02 1.1145e+04

Absolute relative percentage approximate error

abs_e = 102.34 103.57 102.43

Maximum absolute relative percentage approximate error

Max_abs_ea = 103.57

--------------------------------------------------------------------------------

Iteration number3

Previous iteration values of the solution vector

Xold = 1.2592e+03 -7.0978e+02 1.1145e+04

New iterative values of the solution vector

X = -5.3618e+04 3.0534e+04 -4.7514e+05

Absolute relative percentage approximate error

abs_e = 102.35 102.32 102.35

Maximum absolute relative percentage approximate error

Max_abs_ea = 102.35

----------------------------------------------------------------------------------

Iteration number4

Previous iteration values of the solution vector

Xold = -5.3618e+04 3.0534e+04 -4.7514e+05

New iterative values of the solution vector

X = 2.2841e+06 -1.3004e+06 2.0240e+07

Absolute relative percentage approximate error

abs_e = 102.35 102.35 102.35   

Maximum absolute relative percentage approximate error

Max_abs_ea = 102.35

----------------------------------------------------------------------------------

Iteration number5

Previous iteration values of the solution vector

Xold = 2.2841e+06 -1.3004e+06 2.0240e+07

New iterative values of the solution vector

X = -9.7298e+07 5.5395e+07 -8.6218e+08

Absolute relative percentage approximate error

abs_e = 102.35 102.35 102.35

Maximum absolute relative percentage approximate error

Max_abs_ea = 102.35

 Using MATLAB, develop an M-file to determine LU factorization of a square matrix with partial pivoting. That is, develop a function called mylu that is passed
 Using MATLAB, develop an M-file to determine LU factorization of a square matrix with partial pivoting. That is, develop a function called mylu that is passed
 Using MATLAB, develop an M-file to determine LU factorization of a square matrix with partial pivoting. That is, develop a function called mylu that is passed
 Using MATLAB, develop an M-file to determine LU factorization of a square matrix with partial pivoting. That is, develop a function called mylu that is passed

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site