Advertisement
Guest User

Untitled

a guest
Oct 1st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.95 KB | None | 0 0
  1. open System
  2.  
  3. let epsilon = 0.000001
  4.  
  5. // 14, 15, 16
  6. let f1 = fun x -> (Math.Tan(x/2.) - (1./Math.Tan(x/2.)) + x)
  7. let f2 = fun x -> 0.4 + Math.Atan(sqrt(x)) - x
  8. let f3 = fun x -> (3.*sin(sqrt(x)) + 0.35*x - 3.8)
  9.  
  10. let f1' = fun x -> (1./2.)*(2. + (sin(x/2.)*sin(x/2.)) + (cos(x/2.)*cos(x/2.)))
  11. let f2' = fun x -> -1. + 1./(Math.Sqrt(x)*(2. + 2.*x))
  12. let f3' = fun x ->  0.35 + (1.5*cos(sqrt(x)))/sqrt(x)
  13.  
  14. let phi1 = fun x -> x - (1./(f1' x))*f1 x
  15. let phi2 = fun x -> x - (1./f2' x)*f2 x
  16. let phi3 = fun x -> x - (1./f3' x)*f3 x
  17.  
  18. let rec dichotomy f a b =  
  19.     let m = (a + b) / 2.
  20.     if (b - a) < epsilon then m
  21.     else
  22.         if (f a) * (f m) < 0. then dichotomy f a m
  23.         else dichotomy f m b
  24.  
  25. let rec iterations phi x0 =  
  26.     let xn = phi x0
  27.     if abs(xn - x0) < epsilon then x0
  28.     else iterations phi xn
  29.  
  30. let rec newthon f f' x0 =
  31.    let xn = x0 - (f x0) / (f' x0)
  32.     if abs(xn - x0) < epsilon then x0
  33.     else newthon f f' xn
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement