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

Exercise 3. Solving quadratic equation ar2 + br + c 0 Write your own MATLAB func

ID: 2265026 • Letter: E

Question

Exercise 3. Solving quadratic equation ar2 + br + c 0 Write your own MATLAB function function [x1,x2] solve2Eg(a,b,c) = which solves the quadratic equation ax2 + bx + c = 0, a0. Use two different formulas for the solutions x1 and x2, i.e., and r htsign(b)V02-4ac and x2 =- 2a Test your program for (a) a-1, b--(106 + 10-6) and c = 1. (b) a = 10-10)--1010 and c 1010, What problems do you observe? Which formulas behave better depending on the value of b? Compare your results with roots([a b c]). What happens if you try to compute the roots by hand? (6 pts.)

Explanation / Answer

% This m-file will solve the quadratic equation :ax^2 + bx + c = 0

function Quad= Quadratic(A,B,C)

% A=1;
% B=2;
% C=3;


%If-Else statement for if A=0

if A==0,
X= -C/B;
else
X(1) = (-B+sqrt(B^2-4*A*C))/(2*A);
X(2) = (-B-sqrt(B^2-4*A*C))/(2*A);

disp(X(1))
disp(X(2))
fprintf('X(1) = %f ',X(1));
fprintf('X(2) = %f ',X(2));


end

Question is partialy answered