Definition of a complex variable in Fortran 77

In summary, the conversation discusses how to define a complex variable in a Fortran 77 program to find the roots of a quadratic function with complex solutions. The solution is to use the complex data type and either include a complex number in the definition or use the cmplx() function.
  • #1
gelbehahn
2
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
  • #2
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))
 
  • #3
Ou yeah, the second option is the one I was trying to find. So easy! Thanks a lot!
 

Related to Definition of a complex variable in Fortran 77

What is a complex variable in Fortran 77?

A complex variable in Fortran 77 is a data type that consists of two real numbers, known as the real and imaginary parts. It is used to represent complex numbers in scientific and mathematical calculations.

How is a complex variable declared in Fortran 77?

A complex variable is declared using the COMPLEX keyword followed by a name and optional dimensions. For example, COMPLEX Z declares a single complex variable named Z, while COMPLEX X(10,10) declares an array of 100 complex variables named X with dimensions 10 by 10.

What operations can be performed on complex variables in Fortran 77?

Fortran 77 supports a variety of mathematical operations on complex variables, including addition, subtraction, multiplication, division, and exponentiation. These operations can be performed between two complex variables or between a complex variable and a real number.

How are complex variables stored in memory in Fortran 77?

In Fortran 77, complex variables are stored as two consecutive real numbers, with the real part preceding the imaginary part. This means that a complex variable with dimensions (10,10) would occupy 20 memory locations, with the first 10 locations storing the real part and the next 10 storing the imaginary part.

Can Fortran 77 handle complex functions?

Yes, Fortran 77 has built-in functions for working with complex variables, such as COS, SIN, EXP, and LOG. These functions can be used to perform calculations involving complex numbers and return a complex result.

Similar threads

  • Programming and Computer Science
2
Replies
59
Views
9K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
13
Views
1K
  • Precalculus Mathematics Homework Help
Replies
9
Views
592
  • Programming and Computer Science
Replies
9
Views
4K
  • General Math
Replies
7
Views
2K
  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
Back
Top