Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 3.18 KB | None | 0 0
  1. let rec iter f i a b =
  2.     if a<=b then
  3.         f (iter f i (a+1.) b) a
  4.     else i
  5.    
  6. let sum a b = iter (+) 0. a b
  7.  
  8.  
  9. let fact n = iter (*) 1. 1. n
  10.  
  11.  
  12.  
  13.  
  14. sum 1. 2.
  15.  
  16. fact 5.
  17.  
  18. //stepen
  19. let rec f1 x n =
  20.     if n>0. then
  21.         x * (f1 x (n-1.))
  22.     else 1.
  23.  
  24.  
  25. //1 член послед втупом методе
  26. let f2 x n = (f1 x (2. * n)) / (fact n)
  27.  
  28.  
  29.  
  30. //DUMB
  31. let rec tylerSum x n=
  32.     if ((f2 x n) = (f2 x (n+1.))) then (f2 x n)
  33.     else
  34.         (+) (f2 x n) (tylerSum x (n+1.))
  35.    
  36. tylerSum 0.2 0.
  37.  
  38.  
  39. let rec myfor a b=
  40.     if a<b then
  41.         printfn("%f %f") a (tylerSum a 0.)
  42.         myfor (a+0.1) b
  43.  
  44. myfor 0. 1.
  45.  
  46. //smart
  47. let rec tylerSum2 x n NUM=
  48.     let F1=(float)NUM*x*x/n
  49.     if (NUM = F1) then NUM
  50.     else
  51.         (+) NUM (tylerSum2 x (n+1.) F1)
  52.  
  53. //tylerSum2 0.1 1. 1.
  54.  
  55.  
  56. open System
  57. open System.Numerics
  58.  
  59.  
  60.  
  61.  
  62. //function!!!!!!!!!!!!!!
  63.  
  64. let func111 x = Math.Pow ( Math.E , x*x )
  65.  
  66.  
  67. func111 0.1
  68.  
  69.  
  70.  
  71.  
  72.  
  73. let rec myfor2 a b=
  74.     if a<b then
  75.         printfn("%f  %f  %f  %f") a (tylerSum a 0.) (tylerSum2 a 1. 1.) (func111 a)
  76.         myfor2 (a+0.1) b
  77.  
  78. myfor2 0. 1.
  79.  
  80.  
  81. /////////////////////////////////////////////////////
  82.  
  83.  
  84. let FUNC x= Math.Cos(x/2.) - 2.* Math.Sin(1./x) + 1./x
  85.  
  86. FUNC 1.8756
  87.  
  88.  
  89. let rec solve a b =
  90.     let avg=(a+b)/2.
  91.     let znach=FUNC avg
  92.     if (b-a)<0.000001 then printfn("%f") avg
  93.     else
  94.         if znach>0. then (solve avg b)
  95.         else
  96.             if znach<0. then (solve a avg)
  97.  
  98. let koren=solve 1. 2.
  99.  
  100. let proizv x=(2.*Math.Sin(2./x)+2.*Math.Cos(1./x)-1.)/x/x
  101.  
  102. proizv 2.
  103.  
  104. let rec solve1 a b x0=
  105.     let x1=x0-((FUNC x0)/(proizv x0))
  106.     if Math.Abs(x0-x1)<0.001 or x1>b or x1<a then printfn("%f") x0
  107.     else solve1 a b x1
  108.  
  109.  
  110. solve1 1. 2. 2.
  111. /////метод итераций
  112. let min=proizv 2.
  113. let max=proizv 1.
  114. let c = 2. /(min + max)
  115.  
  116.  
  117. let rec solve3 a b x0=
  118.     let x1=x0-c*(FUNC x0)
  119.     if Math.Abs(x0-x1)<0.001 or x1>b or x1<a then printfn("%f") x1
  120.     else solve3 a b x1
  121.  
  122. solve3 1. 2. 2.
  123.  
  124. ////////////////////////////////////////////////////////SEMMINAR
  125.  
  126.  
  127. open System
  128. open System.IO
  129.  
  130.  
  131. let s=File.ReadAllLines("D:\\FSharpCodingDojo-master\\FSharpCodingDojo-master\\DigitRecognizer\\validationsample.csv")
  132.  
  133. let m=(s |> Array.map(fun x-> x.Split(','))).[1] |> Array.map(int)
  134.  
  135. //for i in 1 .. s.Length-1 do
  136. //    let SS=s.[i].Split(',') |> Array.map(int)
  137.  
  138.  
  139.  
  140. let a=[1;2;3;4]
  141.  
  142. let b =[5;6;7;8]
  143.  
  144.  
  145.  //[1;2;3;4]@[5;6;7;8]
  146.  
  147.  let rec append L M=
  148.     match L with
  149.     |[]-> M
  150.     |h::t->h::(append t M)
  151.  
  152. let c = append a b
  153.  
  154.  
  155. let print X=
  156.     List.iter(printf "%A ") X
  157.  
  158. print c
  159.  
  160. let d = List.filter(fun x -> x%2=0) c
  161.  
  162. List.map(fun x -> x*2) d
  163.  
  164. let gen n=
  165.     let mutable x=n
  166.     fun()->
  167.         x <- x+1
  168.         x
  169.  
  170. let a = Seq.unfold (fun(u,v) -> Some (u,(v,v+u))) (1,1)
  171.  
  172. //////////////////////
  173.  
  174. seq{1..100}
  175.  
  176. let ss=(Seq.append [1;2;4] [2;3;4;5]) |> List.map(fun x->x*2)
  177.  
  178.  
  179. //////////////////////////
  180. type formatText=
  181.     | Str of string
  182.     | Bullet_item of List<formatText>
  183.     | Bold_text of formatText
  184.     | Italic_text of formatText
  185.     | Headers of formatText
  186.  
  187.  
  188. let rec render formatText =
  189.     match formatText with
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement