×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Jacobi iteration

## Jacobi iteration

(OP)
Hello, i'm studying geology and i have problems with making simple program in fortran.

we have a system of n equations
ai1x1 + ai2x2 + · · · + aiixi + · · · + ainxn = bi
Solve this equation for xi.
xi = [bi − (ai1x1 + ai2x2 + · · · + ai,i−1xi−1 + ai,i+1xi+1 + · · · + ainxn)]/aii
Summation notation greatly simplifies this statement.
xi = ( bi - suma (i/=j)aij*xj)/aii

program jacobi
real A(50,50), B(10), xold, xnew,suma
integer i,j,n

open (5, file='input.txt')
open (6, file='output.txt')

do 70 k=1,100
xold=0
do 10 i=1,n
suma=0
do 20 j=1,n
if (j.ne.i) go to 20
suma=suma+A(i,j)*xold(j)
20 continue
xnew(i)=(b(i)-suma)/(A(i,i))
10 continue
if (A(i,i).eq.0) then
write (6,100)
go to 40
else go to 10
if (abs(xnew-xold).LT.10**(-5)) then
go to 40
else xold(j) = xnew(i)
end if
write (6,200) i, (xnew(i), i=1,n)
70 continue
100 format ('nije moguce izracunati xnovi zbog dijeljenja s nulom')
200 format ('x',I1,'=',10F8.4)
40 close (5)
close (6)
end

### RE: Jacobi iteration

A few things

You have declared xnew and xold as scalars; yet, you are using them as if they were arrays.

I don't think "if (A(i,i).eq.0) then" is going to work well...the chances of a real number being exactly zero are very low...you'd better use some tolerance as in the other "if" (and 'abs' if it can be negative).

Regarding the other "if", I wouldn't bother evaluating a power inside a loop, let alone a known result: instead of evaluating 10**(-5), simply write 0.00001

Lastly, please stay away from unit numbers 5 and 6 to attach your own files; these are predefined for standard input and output and you may need for that. There are many other number to choose from, pick two.

### RE: Jacobi iteration

(OP)
Thank you very much for help!

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!