Definition of a complex variable in Fortran 77

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
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
Ou yeah, the second option is the one I was trying to find. So easy! Thanks a lot!