Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program lab1
- use roots
- implicit none
- real(8)::x1,x2,xk,eps
- real(8),parameter::mm1=1.4455,m2=0.5368,m1=1.0194,mm2=0.8813
- integer::i=0,method
- interface !If a procedure has another procedure as dummy argument then one has to specify its type, just as the type of other parameters.
- !An interface block is used for this case. It consists of the procedure statement with the definitions of its arguments.
- real(8) function f(x)
- real(8) :: x
- end function f
- real(8) function df(x)
- real(8) :: x
- end function df
- real(8) function d2f(x)
- real(8) :: x
- end function d2f
- end interface
- print*, 'Input x1,x2,and eps'
- read(*,*) x1,x2,eps
- if (f(x1)*f(x2).GT.0) then
- print*,'Error, f(x1)*f(x2)>0'
- stop
- else
- continue
- end if
- print*,'Choose method (1-Newtons,2-Chord,3-Secant,4-Fixed-point iteration)'
- read(*,*) method
- select case (method) !Выбор метода
- case (1)
- print*,'Newtons'
- call kas(f,df,d2f,x1,x2,xk,eps,i,mm2,m1)
- case (2)
- print*, 'Chord'
- call hord(f,x1,x2,xk,eps,i,mm1,m1)
- case (3)
- print*,'Secant'
- call sec(f,x1,x2,xk,eps,i,m1)
- case (4)
- print*, 'Fixed-point iteration'
- call iter(f,df,x1,x2,xk,eps,i)
- case default
- print*, 'Error'
- end select
- print*, 'Results::'
- print*, 'xk=',xk
- print*, 'f(xk)=',f(xk)
- print*, 'iterations-',i
- end program lab1
- function f(x)
- implicit none
- real(8)::f,x
- f=exp(-x)-cos(x+4)
- end function f
- function df(x)
- implicit none
- real(8)::df,x
- df=sin(x+4)-exp(-x)
- end function df
- function d2f(x)
- implicit none
- real(8)::d2f,x
- d2f=exp(-x)+cos(x+4)
- end function d2f
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement