:
b2 4ac
1
c=0
b
(Vieta)
)
a=0
b=0
(
function[x,flag]=root2qe(a,b,c)
ifnargin==1,
c=a(3);b=a(2);a=a(1);end
ifa~=0,%Solve2-orderequation
M=max(abs([a,b,c]));%scalinga=a/M;b=b/M;c=c/M;s=sign(b);
ifs==0,s=1;end
x1=(-b-s*sqrt(b^2-4*a*c))/2/a;x2=c/(a*x1);%avoidlargeerrorx=[x1x2]’;
flag=’twosolutions’;elseifb~=0,%Solve1-orderequation
x=-c/b;
flag=’onesolution’;elseifc~=0,%nonzeroconstant
x=[];
flag=’noxisasolution’;else%equality0=0
x=[1];
flag=’allxaresolutions’;end
6