Primjeri programa u Fortranu

  1. program tangenta
    implicit none
    integer i
    double precision x1, x2, y1, y2, eps, f, df
    5 write (*,*) ‘unesi pocetnu tacku’
    read (*,*) x1
    eps=0.0000001
    y1=f(x1)
    do i=1, 1000
    x2=x1-(y1)/(df(x1))
    if (abs(f(x2)).lt.eps) then
    goto 2
    end if
    x1=x2
    end do
    2 continue
    write (*,*) i, x2, f(x2)
    end

double precision function f(x)
double precision x
f=log(x)*exp(x)-x**2
end

double precision function df(x)
double precision x
df=(log(x)*x*exp(x)+exp(x)-2*x**2)/x
end

2.  program integral
implicit none
integer i,n
real a,b,f,h,pi,int
pi=4.*atan(1.0)
a=0
b=pi/2
write (*,*) ‘unesi broj tacaka’
read (*,*) n
h=(b-a)/N
int=0.
do i=1,n-1
int=int+f(a+i*h)
end do
int=h*(0.5*f(a)+int+0.5*f(b))
write (*,*) ‘vrijednost integrala je:’,int
end

real function f(x)
implicit none
real x
f=cos(x)
end

3.

program tangenta
implicit none
integer i
double precision x1, x2, y1, y2, eps, f, df
5 write (*,*) ‘unesi pocetnu tacku’
read (*,*) x1
eps=0.0000001
y1=f(x1)
do i=1, 1000
x2=x1-(y1)/(df(x1))
if (abs(f(x2)).lt.eps) then
goto 2
end if
x1=x2
end do
2 continue
write (*,*) i, x2, f(x2)
end

double precision function f(x)
double precision x
f=log(x)*exp(x)-x**2
end

double precision function df(x)
double precision x
df=(log(x)*x*exp(x)+exp(x)-2*x**2)/x
end

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *