Fortran Definition of a complex variable in Fortran 77

AI Thread Summary
The discussion revolves around programming in Fortran 77 to find the roots of a quadratic function, particularly when dealing with complex numbers due to a negative discriminant. The user, Alfonso, encounters an issue with defining a complex variable correctly, receiving an 'invalid complex constant' error. A solution is provided, suggesting the use of a complex variable declaration and the proper syntax for assigning complex values. Two methods are highlighted: defining a complex variable with an imaginary unit or using the `cmplx` function to create complex numbers directly. Alfonso expresses gratitude for the clarification, noting that the second method was the one he was seeking.
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!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
59
Views
11K
Replies
4
Views
2K
Replies
9
Views
5K
Replies
3
Views
2K
Replies
9
Views
2K
Replies
8
Views
4K
Replies
3
Views
2K
Replies
12
Views
2K
Replies
1
Views
4K
Replies
1
Views
2K
Back
Top