MATLAB Answers

Suman Koirala

Having problems displaying the real and imaginary parts of a complex root

Asked by Suman Koirala
on 12 Mar 2013

This is what I have. It works all fine in identifying the root but doesn't do anything with displaying the real and complex roots although I think I have it.

a=input('Enter a: ');
b=input('Enter b: ');
c=input('Enter c: ');
d=(b^2)- 4*a*c;
if d>0
    disp('This equation had two real roots');
    r1= (-b+sqrt(d))/(2*a)
    r2= (-b - sqrt(d))/(2*a)
elseif d==0
    disp('This equation has one real root');
    r1= (-b+sqrt(d))/(2*a)
    disp('This equation has two imaginary roots');
    r1= (-b+sqrt(d))/(2*a)
    r2= (-b - sqrt(d))/(2*a)



No products are associated with this question.

1 Answer

Answer by Youssef Khmou
on 12 Mar 2013
 Accepted answer

hi, what is the problem exactly !

delete the part :


I think the code is fine :

 Enter a: 2
 Enter b: 2
 Enter c: 2
 This equation has two imaginary roots
 r1 =
-0.5000 + 0.8660i
 r2 =
-0.5000 - 0.8660i

  1 Comment

Suman Koirala
on 19 Mar 2013

THank you. It works fine.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!