Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

double percision

Status
Not open for further replies.

shasa

Programmer
Aug 14, 2010
17
IR
how can i deternine a complex eignvalue of a matrix with complex elements?

and how about a complex double percision eignvalues?
 
actually my matrix elements r complex 2, thats why any code that i use for calculating its eigenvalue dosent work well,
 
I suggest the use of EISPACK, an old FORTRAN library dedicated to the computation of eigen values :


About double precision complex values, the standard conforming way is :

Code:
integer,parameter:: dp=kind(0.d0)
complex(dp) :: value
 
actually i use that but the problem is for converting complex 2 complex(dp), bcz in my programm most subroutines work with complex parameters,

i use that subroutin but i have the problem that i explained before.

 
Sorry but the troubles you met are not clear.

Is it a problem of declaration ? Of course, if you declare your matrix as "complex double precision" and you pass it to a subroutine which declares it as simple precision, you will have a trouble.

You must declare COMPLEX(dp) your matrix every where. I even suggest to declare COMPLEX(dp) all complex variables.

 
is there any thing for converting simple precision 2 dp in middle of program?
 
If you are in a hurry, you can use at the top of each subroutine/function/main

implicit complex(kind(0.d0)) (a-h,o-z)

which declares complex all variables starting by a,b...h,o...z. Variables starting by i,j,k,l,m,n are integer by default.

But I prefer an explicit declaration of each variable which is made obligatory by IMPLICIT NONE.
 
It would help a lot if you typed words in full instead of using 2 and r. Some compilers use complex*2 instead of complex*16 so seeing complex 2 can be very confusing.
 
actuallly there isnt any problem with complex*16 , but i have a matrix elements that defining variables as complex*16 make so many mistakes (because of declaring them them as complex before)i change forexample 2-->2.d0 but errors didnt gone. so i perefer to use a function or any thing else that convert complex variables to complex*16 (some thing that we have for int to real in c++)is there any thing here?
 
It is rather easy to write such function promoting a single precision complex to a double precision complex. It is even possible to make that function working on whole arrays as well as scalars.

But it will not solve your problem. Indeed, you will continue to have computations performed with single precision variables or which results are stored into single precision variables.

Promoting after that single precision into double precision will never restore magically the precision you could have expected if all variables were declared double precision since the beginning.

Nevertheless, here is an example for such function :

Code:
module tools
  implicit none
  contains
  pure elemental function dblx(a) result(b)
    complex,intent(in)  :: a
    complex(kind(0.d0)) :: b
    b=a
  end function
end module

program test
  use tools
  implicit none
  complex :: a(10)
  integer :: i
  real :: re,im
  do i=1,10
    a(i)=complex(real(i),-2.*i)
  enddo
  write(*,*) a
  write(*,*) dblx(a)
end program

Notice also, that the intrinsic function COMPLEX returns a double precision complex value if its two arguments are double precision real values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top