MATLAB: Need help Writing a function that returns roots of a quadratic

function returns roots of a quadratichomework

This is my plan on how to write it (don't have software at my disposal currently). I am learning matlab so understand there may be quite a few problems.
Function [x]=myquad(a,b,c)
x=[r1 r2];
d=sqrt((b.^2)-4.*a.*c)
if a==0 & b>0
r1=-c/b;
elseif a==0 & b==0
r1=0;
elseif a~=0 & d==0
r1=-b./(2.*a);r2=r1;
elseif a~=0 & d>0
r1=(-b+d)./2a; r2=(-b+d)./2.*a;
elseif a~=0 & d<0
r1=(-b+d.*i)/2a; r2=(-b-d.*i)./2.*a;
end
end
I need to follow this algorithm for an assignment.
THANKS!

Best Answer

Your first two cases do not appear to set r2 to anything.
your a=0 b=0 case is wrong
Your "di" should probably be "d*i"