Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Result = float * int
- let delta = 1e-10
- // *** Первая часть
- let fTailor x : float = cosh x // функция, которую раскладываем
- let n, a, b = 20., 0., 1. // интервал
- let rec factorial n =
- match n with
- | 0 -> 1
- | n -> n * factorial (n-1)
- let tailorone' x n = x ** (float) n / (float)(factorial n)
- tailorone' (1., 0) 2
- let tailor x : Result = (x,0)
- let tailorA x : Result =
- let rec tailorA' (y : Result) n one =
- if one < delta then y else
- let ans = tailorone' x n
- tailorA' ((fst y) + ans, (snd y) + n + 1) (n + 2) ans
- tailorA' (x, 0) 3 x
- tailorA 0.5
- abs(0. - (fTailor 0.)) < delta
- let printTailor () =
- [a .. (b-a)/n .. b]
- |> List.map (fun x -> let (firstRes, firstCou), (secondRes, secondCou) = tailor x, tailorA x in (x, firstRes, firstCou, secondRes, secondCou, fTailor x))
- |> List.iter (fun (a,b,c,d,e,f) -> printf "%f\t%f\t%d\t%f\t%d\t%f\n" a b c d e f )
- printTailor ()
Advertisement
Add Comment
Please, Sign In to add comment