Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module lab1
- open System
- open System.Net
- open System.IO
- open System.Collections.Specialized
- // почтовый адрес
- let email = "annafedyushkina@gmail.com"
- // общий тип для возвращаемых вашими функциями значений, где первая часть кортежа это само значение функции, вторая - кол-во операций
- type Result = float * int
- let delta = 1e-10
- // *** Первая часть
- let fTailor x : float = (1 + x ** 2) / 2 * atan x - x / 2 // функция, которую раскладываем
- let n, a, b = 20., 0.1, 0.6 // интервал
- let tailor x : Result =
- let rec tailor_function x result i =
- let current = ((-1)**(float(n) + 1))*(x**(2*(float(n)) + 1))/(4*((float(n))**2) - 1)
- if abs (current) < delta
- then (result, i)
- else
- tailor_function x (result + current) (i + 1)
- tailor_function x 0. 1
- let tailorA x : Result =
- let rec tailor_function x result prev i =
- let current = prev*(-1)*(x**2)*(4*((i-1)**2) - 1)/(4*(n**2 - 1)
- if abs (current) < delta
- then (result, i)
- else
- tailor_function x (result + current) current (i + 1)
- tailor_function x 0. x 1
- 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 )
- // *** Вторая часть
- let fSolve = [ (fun x -> x + (x ** (1./2.)) + (x ** (1./3.)) - 2.5); // функции, решения которых ищем
- (fun x -> x - 1. / (3. + sin(3.6*x)));
- fun x -> 0.1*(x**2) - x*(log(x))]
- let diap = [(0.4, 1.); (0., 0.85); (1., 2.)]
- let iter f a b : Result = (42., 0)
- let touch = (b-a) / (f b - f a)
- let rec iterA i f x =
- let x1 = x - touch * (f x)
- if abs (x1 - x) < delta
- then (x1, i)
- else
- iterA (i + 1) f x1
- iterA 0 f ((a + b) / 2.)
- let newton f a b : Result =
- let rec newtonA i f x xprev =
- if abs (x - xprev) < delta then
- (x, i)
- else
- newtonA (i + 1) f (x - (f x) * (x - xprev) / ((f x) - (f xprev))) x
- newtonA 0 f ((a + b) / 2.) a
- let dichotomy =
- let rec dichotomyA i f a b : Result =
- let t = (a + b) / 2.
- if b - a < delta
- then (t, i)
- else
- if (f t) * (f a) < 0.
- then dichotomyA (i+1) f a t
- else dichotomyA (i+1) f t b
- dichotomyA 0
- let printSolve () =
- [iter; newton; dichotomy]
- |> List.map (fun f -> f fSolve a b)
- |> List.iter (fun (res, cou) -> printf "%f\t%d\n" res cou)
- let main () =
- let values = new NameValueCollection()
- values.Add("email", email)
- values.Add("content", File.ReadAllText(__SOURCE_DIRECTORY__ + @"/" + __SOURCE_FILE__))
- let client = new WebClient()
- let response = client.UploadValues(new Uri("http://mipt.eu01.aws.af.cm/lab1"), values)
- let responseString = Text.Encoding.Default.GetString(response)
- printf "%A\n" responseString
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement