Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Chords

real function f(x,p,q,t)
   real x, p, q, t
   f=p*x*x+q*x+t
end function f

program root
   real p, q, t, a, b, e
   open (1,file='data.txt')
   read (1,*) p, q, t, a, b, e
   print "('f(x)=(',f4.0,')x^2+(',f4.0,')x+(',f4.0,')')", p, q, t
   call Chords(a,b,e,p,q,t)
end program root

subroutine Chords(a,b,e,p,q,t)
   real, external :: f
   real a, b, e, p, q, t, k
   integer :: m=0
   print "(/6x,'МЕТОД ХОРД'//'Поиск корня по формуле: x = (a+b)/2'//&
   2x,'Итерационный процесс:'/)"
   if (2.*p*f(a,p,q,t)>0.) then
      print "('fxx(a)*f(a) =',f9.4,' > 0'/'=> конец a неподвижен'/&
      3x,'x(0) = b =',f8.4/&
	  'Поиск корня по формуле: x = x-f(x)/(f(x)-f(a))*(x-a)'//&
	  'Итерационный процесс:'/)", 2.*p*f(a,p,q,t), b
	  x=b
      do
         k=x
         x=k-f(k,p,q,t)/(f(k,p,q,t)-f(a,p,q,t))*(k-a)
         m=m+1
		 print "(i2,') x =',f8.4/4x,'|x(n)-x(n-1)| =',f7.4)", m, x, abs(k-x)
         if(abs(k-x)<e) exit
      end do
   else
      print "('fxx(a)*f(a) =',f9.4,' > 0'/'=> конец b неподвижен'/&
      3x,'x(0) = a =',f8.4/&
	  'Поиск корня по формуле: x = x-f(x)/(f(b)-f(x))*(b-x)'//&
	  'Итерационный процесс:'/)", 2.*p*f(a,p,q,t), a
      x=a
      do
         k=x
         x=k-f(k,p,q,t)/(f(b,p,q,t)-f(k,p,q,t))*(b-k)
         m=m+1
         print "(i2,') x =',f8.4/4x,'|x(n)-x(n-1)| =',f7.4)", m, x, abs(k-x)
         if(abs(k-x)<e) exit
      end do
   end if
print *,'Ответ: x =', x
end subroutine Chords

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.