Having problems displaying the real and imaginary parts of a complex root
    6 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
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)
else
    disp('This equation has two imaginary roots');
    r1= (-b+sqrt(d))/(2*a)
    r2= (-b - sqrt(d))/(2*a)
    real(r1)
    real(r2)
    y1=imag(r1)
    y2=imag(r2)
end
0 commentaires
Réponse acceptée
  Youssef  Khmou
      
 le 12 Mar 2013
        hi, what is the problem exactly !
delete the part :
   real(r1);real(r2);
    y1=imag(r1);y2=imag(r2);
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
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Logical dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

