Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open System
- let epsilon = 0.000001
- // 14, 15, 16
- let f1 = fun x -> (Math.Tan(x/2.) - (1./Math.Tan(x/2.)) + x)
- let f2 = fun x -> 0.4 + Math.Atan(sqrt(x)) - x
- let f3 = fun x -> (3.*sin(sqrt(x)) + 0.35*x - 3.8)
- let f1' = fun x -> (1./2.)*(2. + (sin(x/2.)*sin(x/2.)) + (cos(x/2.)*cos(x/2.)))
- let f2' = fun x -> -1. + 1./(Math.Sqrt(x)*(2. + 2.*x))
- let f3' = fun x -> 0.35 + (1.5*cos(sqrt(x)))/sqrt(x)
- let phi1 = fun x -> x - (1./(f1' x))*f1 x
- let phi2 = fun x -> x - (1./f2' x)*f2 x
- let phi3 = fun x -> x - (1./f3' x)*f3 x
- let rec dichotomy f a b =
- let m = (a + b) / 2.
- if (b - a) < epsilon then m
- else
- if (f a) * (f m) < 0. then dichotomy f a m
- else dichotomy f m b
- let rec iterations phi x0 =
- let xn = phi x0
- if abs(xn - x0) < epsilon then x0
- else iterations phi xn
- let rec newthon f f' x0 =
- let xn = x0 - (f x0) / (f' x0)
- if abs(xn - x0) < epsilon then x0
- else newthon f f' xn
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement