Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help writing the following MATLAB code: Program Description 65 PTS This m

ID: 3683459 • Letter: I

Question

I need help writing the following MATLAB code:

Program Description

65 PTS This main program asks for the user to enter the name of their file that contains a system of linear equations

%5pts for successfully loading from a file (.mat is fine) = 5pts

% CHECK THE LOADED FILE

% Before solving the system, the program needs to make sure of the following:

% (I) the A matrix is correctly named and present =5pts

%hint: ws= who; %contains workspace vars % I1=find(strcmp(ws, 'A') ); %finds any instances of matrix 'A'

%(II) the A matrix is valid (call a function to do this) =10pts

% (A) Check if the A matrix is

% (1) non-empty (2) square, (3)nonsingular, (4)well-conditioned

% (B) If not, an error message is displayed, and the main program ends =5pts

%(III) the b vector is correctly named and present =5pts

%(IV) the b vector is valid (call a function to do this) =10pts

% (A) Check if the b vector is:

% (1) non-empty, (2) a column vector, (3) under or overspecified.

% (B) If not, an error message is displayed, and the main program ends =5pts

% (V) SOLVE THE SYSTEM

%If A matrix and b column vector pass the above tests, the main program solves the system of linear equations and outputs the solution to the command window. (5pts)

%The user is prompted to keep entering systems until failure. (10 pts)

% Program + function + nested functions + .mat test file(5pts)= 65 pts

The program should contain the following:

Flowchart or program plan (YourlastnamePLAN.pdf) = 5pts

Main program file (Yourlastname610.m) = 30pts

Function file with at least one nested function (YourlastnameCHECK.m) = 30pts

Test file (ValidAb.mat) = 5pts, made from these 5 simultaneous linear equations:

Please make sure to include comments throughout the code. Thank you!

Explanation / Answer

Hi below i have written the sample function for your reference,

%% Program Description
% This main program asks for the user to enter the name of their file that
% contains a system of linear equations, if the variables of the file meet
% all the requirements, the solution of the linear equations will show on
% the command window; if not, the dispalys of errors will show on the
% command window.
%% Program code
clear %clears the work space
clc %clears the command window
%Variable which becomes 1 if the solution is found to the sytem of equations,
else it is 0
solFound = 1;
%For the while loop to start running, solFound is initialized to 1. After
%the loop starts, the first line makes solFound to 0. Later whent he
%solution is found solFound is made to 1 again, otherwise it stays as zero
%only.
while(solFound == 1)
solFound = 0;
file = input('Which file would you like to import: ','s'); %Asks the user for
the name of the file
file = strcat(file,'.mat'); %Appends the name with .mat (the extension of the
file)
load(file) %loads the data file that the user choose
ws = who; %contains workspace vars
I1=find(strcmp(ws, 'A') ); %finds any instances of matrix 'A'
I2=find(strcmp(ws, 'b') ); %finds any instances of matrix 'b'
%I1 and I2 are 1 if the respective variables are found. If they are not
%found, I1 and I2 are empty matrices.
if (isempty(I1)==1) %If I1 is empty matrix, isempty(I1) will return 1
disp('File is missing matrix A or incorrectly named.')
disp('Please fix your file and rerun the program.')
else
checkA = result1; %Calling the function isAGood with A as its argument
if (checkA==1) %If A is good then checkA will be 1
if (isempty(I2)==1)
disp('A matrix valid but missing vector b')
disp('Please fix your file and then rerun the program')
else
[m,n] = size(A);
checkb = result2;
if checkb==1
X = A; %Evaluates solution X
disp('The solution to the system of equations is: ')
X;
solFound = 1;
end
end
end

end
end