Definition of a complex variable in Fortran 77

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 6K views
gelbehahn
Messages
2
Reaction score
0
Hello,
I'm making now a simple program (in Fortran 77) to find the roots of the quadratic function. When the discriminant is negative, imaginary numbers are to be used and the solution of the function is a complex number.
I'd like to define a complex variable so that:

complex x
x = ((-b)/(2*a),sqrt(disc)/(2*a))

where a and b are the variables of the quadratic function, and disc is the discriminant, previously calculated. But when I try to compile it, it says 'invalid complex constant', for what I guess it takes x as a constant and not as a variable... How can I define a complex variable or how can I solve the equation considering complex solutions? I'm doing something wrong but I do not realize...

Thanks a lot for your help!
Alfonso
 
Physics news on Phys.org
one way to do it is:

complex x, ic = (0.0,1.0)
x = (-b)/(2*a)+ic*sqrt(disc)/(2*a)

or complex x
x = cmplx((-b)/(2*a),sqrt(disc)/(2*a))
 
Ou yeah, the second option is the one I was trying to find. So easy! Thanks a lot!