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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Solving a Matrix for Eigenvalues

Status
Not open for further replies.

Mythrem

Technical User
May 6, 2008
9
TR
I'm using visual fortran professional edition version 6.0.0 and looking for a code to find the eigenvalues of a matrix. I'm new in programming. Could you help me?
 
Thanks for your help but I had tried to use the programs you refered before I began to seek help here and I could not use them. I think they work with different libraries or with some other systems. Even if I were able to make them work, they are written for advanced mathematical purposes, not for a simple engineering application so they are too professional for me. I need a solver that just gives me real eigenvalues of a nxn matrix with which no numerical or conceptual problems occur or that does not require advanced mathematical approaches.
 
I am trying to IMSL library to compute eigenvalues but the example in referance guide uses the comand 'parameter' at the very beginning of the program and defines dimensions of the varibles that are going to be transfered to the subroutine. Look at the following:
INTEGER LDA, LDEVEC, N
PARAMETER (N=3, LDA=N, LDEVEC=N)
INTEGER NOUT
REAL PI
COMPLEX EVAL(N), EVEC(LDEVEC,N)
REAL A(LDA,N)
EXTERNAL EVCRG, UMACH, WRCRN, EPIRG
REAL EPIRG
C Define values of A:
C
C A = ( 8.0 -1.0 -5.0 )
C ( -4.0 4.0 -2.0 )
C ( 18.0 -5.0 -7.0 )
C
DATA A/8.0, -4.0, 18.0, -1.0, 4.0, -5.0, -5.0, -2.0, -7.0/
C
C Find eigenvalues and vectors of A
CALL EVCRG (N, A, LDA, EVAL, EVEC, LDEVEC)


It does not allow the user to assign a value to N during execution, user must change the N value by manuplating the code each time.
What can I do to get this code take the N value during execution?
 
I'm attaching the program I wrote. If anyone corrects it, I'm going to be glad.
Thanks.

USE IMSL

DIMENSION A(100,100), INERTIA(110)
COMPLEX, ALLOCATABLE, DIMENSION:),:) :: EVAL
COMPLEX, ALLOCATABLE, DIMENSION:)) :: EVEC
REAL INERTIA, INER
INTEGER LDA, LDEVEC, N, CHK, CHK2
REAL(8) A

LABEL=0

PRINT *,'ENTER THE LENGTH OF THE COLUMN...'
READ *, LENGTH
PRINT *,'ENTER NUMBER OF SPANS THE COLUMN TO BE DIVIDED INTO...'
READ *, STN

N=STN-1
ALLOCATE(EVAL(N))
ALLOCATE(EVEC(N,N))


PRINT *,'ENTER MODULUS OF ELASTICITY...'
READ *,E
H=LENGTH/STN

PRINT *,'ENTER 1 IF COLUMN IS SIMPLY SUPPORTED, 2 IF IT IS FIXED AT ONE END...'
READ *, CHK
IF((CHK.EQ.1).OR.(CHK.EQ.2)) LABEL=1


1 PRINT *,'ENTER 1 IF INERTIA VARIES ANYOTHER VALUE OTHERWISE...'
READ *,CHK2

IF(CHK2.EQ.1) THEN
DO 3 I=1, STN+1
J=1
PRINT *,'ENTER INERTIA OF THE',I,'. STATION:'
READ *, INERTIA(I,J)
3 CONTINUE
GO TO 4
ENDIF


PRINT *,'ENTER THE INERTIA OF THE CROSS-SECTION...'
READ *, INER

DIM=(STN-1)*(STN-1)

DO 5 I=1, STN+1
J=1
5 INERTIA(I,J)=INER

4 CONTINUE

IF(CHK.NE.1) GO TO 6

A(1,1)=2
A(1,2)=-1

DO 7 I=2, STN-1
DO 9 J=1, STN-1
IF(I.GT.J) GO TO 9
IF(ABS(I-J).EQ.1) A(I,J)=-1
IF(I.EQ.J) A(I,J)=2
9 CONTINUE
7 CONTINUE


DO 8 I=1, DIM
R=1
DO 35 J=1, DIM
R=R+1
A(I,J)=A(I,J)*E*INERTIA(R)/(H*H)
35 CONTINUE
8 CONTINUE

CALL DEVCRG (N, A, LDA, EVAL, EVEC, LDEVEC)

6 CONTINUE

END


The error massages occuring after compilation are:


--------------------Configuration: Buckling Load - Win32 Debug--------------------
Compiling Fortran...
C:\Program Files\Microsoft Visual Studio\MyProjects\Buckling Load\Buckling Load.f90
C:\Program Files\Microsoft Visual Studio\MyProjects\Buckling Load\Buckling Load.f90(18) : Error: The rank of the allocate-shape-spec-list differs from the rank of the allocate-object. [EVAL]
ALLOCATE(EVAL(N))
-----------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\Buckling Load\Buckling Load.f90(19) : Error: The rank of the allocate-shape-spec-list differs from the rank of the allocate-object. [EVEC]
ALLOCATE(EVEC(N,N))
-----------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\Buckling Load\Buckling Load.f90(75) : Error: The type of the actual argument differs from the type of the dummy argument. [EVAL]
CALL DEVCRG (N, A, LDA, EVAL, EVEC, LDEVEC)
--------------------------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\Buckling Load\Buckling Load.f90(75) : Error: The type of the actual argument differs from the type of the dummy argument. [EVEC]
CALL DEVCRG (N, A, LDA, EVAL, EVEC, LDEVEC)
--------------------------------------^
Error executing df.exe.

Buckling Load.obj - 4 error(s), 0 warning(s)
 
Sorry for the late reply. EVAL is declared as a 2D array, EVAC as a 1D array. Your allocations should have been
Code:
    ! the original declarations
    COMPLEX, ALLOCATABLE, DIMENSION(:,:) :: EVAL
    COMPLEX, ALLOCATABLE, DIMENSION(:) :: EVEC
...
    ! (:) = 1D
    ALLOCATE(EVAC(N))
    ! (:,:) = 2D
    ALLOCATE(EVAL(N,N))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top