Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

!

program ite
FUNCTION F(X)
F=exp(-x)
return
end
read(*,*)x0
10 eps=0.000001
if(ABS((F(x0)-x0)/F(x0)).LT.EPS) then
write(*,*)F(x0)
STOP
else
x0=F(x0)
go to 10
endif
end

! program ite
FUNCTION F(X)
F=(2*x+3)**(0.5)
return
end
read(*,*)x0
10 eps=0.005
if(ABS((F(x0)-x0)/F(x0)).LT.EPS) then
write(*,100)F(x0)
100 format(1pe12.5)
STOP
else
x0=F(x0)
go to 10
endif
end

! program ite
FUNCTION F(X)
F=4*exp(-0.5*x)
return
end
read(*,*)x0
10 eps=0.08
if(ABS((F(x0)-x0)/F(x0)).LT.EPS) then
write(*,*)F(x0)
c 100 format(1pe12.5)
STOP
else
x0=F(x0)
go to 10
endif
end

1
dimension v(i)
integer::i
real::c,g,m,h,v
c parameter (c=12.5, g=9.81, m=68.1, h=2)
data c,g,m,h/12.5,9.81,68.1,2/
v(0)=0
do i=0,100
v(i+1)=v(i)+(g-(c*v(i)/m))*h
write(*,*) i,v(i)
enddo
end

program example
implicit none
real x,y
real radius
external distance
print *,'Input X,Y'
read *, x,y
call distance (x,y,radius)
print *, 'distance=', radius
end program
subroutine distance (a,b,r)
implicit none
real a,b,r
r=sqrt(a**2+B**2)
end subroutine distance

2
Program Newton Raphson
implicit none
real, external :: F,DFDX
real, parameter :: tolerance=1.0E-6
integer, parameter :: itermax=200
real X
real Fvalue
integer :: Iter=0
print *,'Input initial X'
read *,X
Fvalue=F(X)
print *, 'X, F(X)=', X, Fvalue
do while (ABS(Fvalue)>tolerance .and. iter<=itermax)
X=X-fvalue/DFDX(X)
fvalue=f(X)
iter=iter+1
print *, 'X, F(X)=',X, Fvalue
end do
if (ABS(Fvalue)>tolerance) then
print *, 'not converged'
else
print *,'Answer=',X
end if
end program Newton Raphson
real function F(X)
real X
F=(2.1*10**9)*(2.718**(-111/((8.314*10**-3)*X))-1.2*10**-12)
end function F
real function DFDX(X)
implicit none
real X,A,E,R
A=2.1*10**9
E=111
R=8.314*10**(-3)
DFDX=(A*E*(e**(-E/(R*X))))/(R*(X**2))
end Function DFDX

You might also like