You are on page 1of 1

array=input('Enter the coefficients of the quadratic function as an array:'); a=array(1); b=array(2); c=array(3); if (a==0) && (b==0) fprintf('The equation

of the quadratic function.'); end if (a==0) && (b~=0) fprintf('There is a single root. It is %g.\n', -c/b); end if (a~=0) && (c==0) fprintf('There are two real roots at 0 and %g.\n', -b/a); end if (a~=0) && (c~=0) root1=(-b+sqrt(b*b-4*a*c)/(2*a)); root2=(-b-sqrt(b*b-4*a*c)/(2*a)); if isreal(root1) fprintf('There are two real roots. They are %g and %g.\n.', root1, root2 ); else fprintf('It seems that the roots are complex:\n'); fprintf(' '); disp(root1); fprintf(' and '); disp(root2); end end