Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions

Question

WHAT IS AUTOMATION TESTING?

Answered: 1 week ago

Question

2. Why has the conflict escalated?

Answered: 1 week ago

Question

1. What might have led to the misinformation?

Answered: 1 week ago