Definition of a complex variable in Fortran 77

Click For Summary
SUMMARY

The discussion focuses on defining complex variables in Fortran 77 for solving quadratic equations with negative discriminants. The user, Alfonso, encountered an 'invalid complex constant' error when attempting to define a complex variable. The solution provided includes two methods: using the imaginary unit defined as 'ic' and employing the 'cmplx' function to create complex numbers. Both methods effectively allow for the calculation of complex roots in quadratic equations.

PREREQUISITES
  • Understanding of Fortran 77 syntax and structure
  • Knowledge of quadratic equations and discriminants
  • Familiarity with complex numbers and their representation
  • Experience with compiling Fortran programs
NEXT STEPS
  • Explore the Fortran 77 'cmplx' function for creating complex numbers
  • Learn about the use of imaginary units in Fortran programming
  • Research error handling in Fortran 77 compilation
  • Investigate numerical methods for solving quadratic equations with complex roots
USEFUL FOR

This discussion is beneficial for Fortran developers, mathematicians working with complex numbers, and anyone interested in numerical methods for solving quadratic equations in programming environments.

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
 
Technology 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!
 

Similar threads

  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K