USE MATLAB ONLY AND EDIT THE mySolve.m Provided!!!! Will rate high for correct answer and following directions accordingly.Use if statements, or error if there is an error, and else if....




USE MATLAB ONLY AND EDIT THE mySolve.m Provided!!!! Will rate high for correct answer and following directions accordingly.Use if statements, or error if there is an error, and else if.

Modify mySolve.m to make sure the inputs are valid. Your function should check for each of the following cases: 1. A is not a square matrix; 2. b is not a column vector; 3. Ax and b do not have the same dimension.


Submit your m-file and a diary showing how you tested the code. Only submit the m-file for mySolve.m. Do not submit the m-files for backward.m, forward.m, or MYLU.m. Test to show that each error code works and that the program still works using the follow tests.


(1) To test the error of A not being a square matrix use


A = [1 2; 3 4; 5 6]


b = [1; 2; 3]


(2) To test the error of b not being a column vector use 12


A = [1 2; 3 4]


b = [1 2]


(3) To test the error of Ax and b not having compatible dimensions use


A = [1 2; 3 4]


b = [1; 2; 3; 4]


(4) To test that the program still works given no errors use


A = [1 2; 3 4]


b = [1; 2]


Then make sure that Ax = b.


---------mySolve.m----------


function x = mySolve(A,b)


[L,U] = MYLU(A);


y = forward(L,b);


x = backward(U,y);


end


---------MYLU.m----------


function [L,U] = MYLU(A)



n = size(A,1);


L = eye(n);


U = A; % U is A initially.


for j = 1:1:n-1


    for i = j+1:1:n


        L(i,j) = U(i,j)/U(j,j);


        U(i,j:n) = U(i,j:n) - L(i,j)*U(j,j:n);


    end


end



end


---------forward.m----------


function x = forward(A,b)



n = size(A,1);


x = zeros(n,1);


x(1) = b(1)/A(1,1);


for i = 2:1:n


    x(i) = (b(i) - A(i,1 : i-1)*x(1 : i-1))/A(i,i);


end


end


---------backward.m----------


function x = backward(A,b)



n = size(A,1);


x = zeros(n,1);


x(n) = b(n)/A(n,n);


for i = n-1:-1:1


    x(i) = (b(i) - A(i,i+1 : n)*x(i+1 : n))/A(i,i);


end


end


May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here