New programming languages

Moderators: None (Apply to moderate this forum)
Number of threads: 111
Number of posts: 329

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Fortran code Segmentation error :( Posted by Sammyboy on 17 Apr 2012 at 9:24 AM
Hi guys I've been stuck on this for the best part of a day now. I'm new to programming (3 days so far) and just can' seem to get this to work!!! My code is below:

Module powermethord
use tri
implicit none
contains

subroutine powerit(a,b,c,E,n)
implicit none

real, intent(in) :: E
real, intent(inout) :: a(:),b(:),c(:)
!real, intent(out) :: x(:)
real,allocatable :: x(:),d(:)
real :: phi_0,lambda_0, lambda, newsum, oldsum, phi
integer :: k, I, j
integer, intent(in) :: n

j = 10
lambda_0 = 1
phi_0 = 1
phi = phi_0
lambda = lambda_0
oldsum = phi_0
allocate(d(I))
d(1)=1
Do k = 1, j-1
print*, d
call tridiag(a,b,c,d,n,x)
d(k) = lambda*(E*x(i))
newsum = sum(x)
lambda = (newsum/oldsum)
print*, k, lambda, x(i)
oldsum = newsum
End do
end subroutine powerit
end module powermethord

the sub routine tridiag is given by:

Module tri
implicit none
contains

subroutine tridiag(a,b,c,d,n,x)
implicit none



integer, intent(in) :: n
real, intent(in) :: a(:),b(:),c(:),d(:)
real, intent(out) :: x(:)
real :: bp(n),dp(n)
real :: dx
integer j,l

l=10
bp(1) = b(1)
dp(1) = d(1)
firstpass: do j = 2,n
dx = a(j)/bp(j-1)
bp(j) = b(j) - dx*c(j-1)
dp(j) = d(j) - dx*dp(j-1)
end do firstpass
x(n) = dp(n)/bp(n)
backsub:do j = l-1, 1, -1
x(j) = (dp(j) - c(j)*x(j+1))/bp(j)
print*, j,x(j)
end do backsub
!print*, i,x(i)
end subroutine tridiag
end module tri

any ideas what's going wrong?! Thanks guys!!!





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.