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

use MATLAB please. The quadratic formula (http://www.purplemath.com/modules/auad

ID: 3844946 • Letter: U

Question

use MATLAB please.

The quadratic formula (http://www.purplemath.com/modules/auadform.htm) allows us to find the roots of a quadratic equation of the form, ax^2 + bx + c, where a, b, and c are constants. Create a function called quadform() that takes as input the coefficients of the quadratic equation (a, b, c) and returns the two distinct real roots (x1, x2) as output, if they exist. In addition, the function returns a message (flag) that informs the user if an error occurred when trying to find two distinct real roots. The possible errors are: (1) "Only one root is found": (2) "Imaginary roots are found": (3) "Any value of x is a solution": (4) "No zeroes exist." If no errors occur, then flag should be "No errors." a = 1: b = 2: c = -1: [x1, x2, flag] = quadform (a, b, c)

Explanation / Answer

function x= quadd()
p = quadform(4,1,1)
disp(p)
end
function [x,y,flag] = quadform(a,b,c)
p = [a b c]
  
  
  
r = roots(p)
  
s=size(r)

disp(r)
if(s>=1)
x=r(1)
else
x=0
end
if (s>1)
y=r(2)
else
y=x
end
  
  
c1 = isreal(x)
c2 = isreal(y)
  
  
  
if (a==0 && b==0 && c==0)
flag = 3
elseif (c1==0 && c2==0)
flag =2
elseif ((s==1) |( x==y))
flag = 1
else
flag = 4
end

x=[x,y,flag]
end