vakho

Prog. Langs (Fortran) 3

Mar 26th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ! x^3 - 8 = 0 (1 --- 4)
  2. function f(x) result(y)
  3.  
  4.     real(16), intent(in)::x
  5.     real(16)::y
  6.    
  7.     y = x*x*x - 8
  8.  
  9. end function
  10.  
  11. function df(x) result(y)
  12.  
  13.     real(16), intent(in)::x
  14.     real(16)::y
  15.    
  16.     y = 3*x*x
  17.  
  18. end function
  19.  
  20. program hello
  21.  
  22.     real(16)::f
  23.     real(16)::df
  24.     real(16)::a, b, c, d, e
  25.     a = 1
  26.     b = 4
  27.    
  28.     do while ((b - a) > 0.000000000001)
  29.         c = f(a)
  30.         d = f(b)
  31.         e = df(b)
  32.         a = -f(a)*(b-a)/(f(b)-f(a))+a
  33.         b = -f(b)/df(b) + b
  34.     end do
  35.    
  36.     Print *, a
  37.     Print *, b
  38.    
  39. end program Hello
  40.  
  41. ! SECONDS EXAMPLE
  42. program hello
  43.  
  44.     real(8)::x
  45.     real(8)::y
  46.    
  47.     x = .75
  48.     y = dsqrt(x)
  49.    
  50.     do while (dabs(y-x) > 0.00000000000001)
  51.         x = y
  52.         y = dsqrt(x)
  53.     end do
  54.    
  55.     Print *, y
  56.    
  57. end program Hello
Add Comment
Please, Sign In to add comment