MATLAB HELP Write a function called linear_equation_solver that will attempt to
ID: 648573 • Letter: M
Question
MATLAB HELP
Write a function called linear_equation_solver that will attempt to solve a system of linear equations
provided by the user. You cannot use the MATLAB built-in matrix functions or matrix operations when
computing the solution and you need to use for-loop(s) to solve this problem.
Input arguments to the function will be the matrices A and B. Output arguments will be the matrix X and
also was_solved, which is either true or false depending on whether there was a solution to the problem.
Your function will first make sure that the system of equations has a solution and if it does not it will set
was_solved to false and the function will end. If the system has a solution then was_solved will be set to
true and solving for X can proceed. Be sure to test your function with systems of equations that have
solutions and some that do not.
Explanation / Answer
prompt = 'Enter the value for Matrix? ';
x = input(prompt)
y = input(prompt)
prompt="Guassian Elimination on x'
prompt='Enter 1 for Guassian Elimination on X And Y';
prompt='Enter 2 For Same Size Check';
prompt='Enter 3 For Multiplication';
prompt='Enter 4 For Multiplication';
if(prompt==1)
for j=2:3,
for i=j:3,
x(i,:) = x(i,:) - x(j-1,:)*x(i,j-1)/x(j-1,j-1)
end
end
for j=2:3,
for i=j:3,
y(i,:) = y(i,:) - y(j-1,:)*y(i,j-1)/y(j-1,j-1)
end
end
end
if(prompt==2)
if isequal(size(A),size(B))
C = [x; y];
else
disp('X and Y are not the same size.')
C = [];
end
end
if(prompt==3)
[nRows1,nCol1]=size(x);
s1=zeros(nRows1,1);
for i1=1:nRows1
tmp1 = 0;
for j1=1:nCol1
tmp1 = tmp1 + x(i,j)*y(j);
end
s1(i) = tmp;
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.