Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module roots
- contains
- subroutine kas(f,df,d2f,x1,x2,xk,eps,i,mm2,m1) !Метод касательных
- implicit none
- real(8)::f,df,d2f,x1,x2,eps,xk,mm2,m1
- integer::i,imax=100
- if (d2f(x1)*f(x1) .GT. 0) then !Определяем, с какого конца отрезка начать
- xk=x1
- else if (d2f(x2)*f(x2) .GT. 0) then
- xk=x2
- else
- print*,'Error, choose different x1 and x2'
- stop
- end if
- do while ((mm2/(2*m1)*(xk-xi)**2 .GT. eps) .AND. (i .LT. imax))
- xi=xk
- xk=xk-f(xk)/df(xk)
- i=i+1
- end do
- end subroutine kas
- subroutine hord(f,x1,x2,xk,eps,i,mm1,m1) !Метод хорд
- implicit none
- real(8)::f,x1,x2,x0,eps,xk,xi,mm1,m1
- integer::i,imax=100
- x0=x2
- x2=x1-(f(x1)*(x1-x0))/(f(x1)-f(x0))
- do while (((mm1-m1)/m1*abs(x2-x1) .GT. eps) .AND. (i .LT. imax))
- x1=x2
- x2=x1-(f(x1)*(x1-x0))/(f(x1)-f(x0))
- i=i+1
- end do
- xk=xi
- end subroutine hord
- subroutine sec(f,x1,x2,xk,eps,i,m1) !Метод секущих
- implicit none
- real(8)::f,x1,x2,eps,xk,xi,temp,m1
- integer::i,imax=100
- xi=x1
- xk=x2
- do while ((abs(f(xk))/m1 .GT. eps) .AND. (i .LT. imax))
- temp=xk
- xk=xi-(f(xi)*(xk-xi))/(f(xk)-f(xi))
- xi=temp
- i=i+1
- end do
- end subroutine sec
- subroutine iter(f,x1,x2,xk,eps,i,m1,mm1) !Метод простой итерации
- implicit none
- real(8)::f,x1,x2,eps,xk,lambda,m1,mm1
- integer::i,imax=100
- lambda=1/mm1
- q=1-m1/mm1
- x0=(x1+x2)/2
- xk=x0+lambda*f(x0)
- do while ((q/(1-q)*abs(xk-x0) .GT. eps) .AND. (i .LT. imax))
- x0=xk
- xk=xk+lambda*f(xk)
- i=i+1
- end do
- end subroutine iter
- end module roots
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement