Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. // Learn more about F# at http://fsharp.org
  2. // See the 'F# Tutorial' project for more help.
  3. open System
  4.  
  5. let contFraction (a:float[]) =
  6. let l = Array.length a
  7. let mutable x = a.[l-1]
  8. let mutable i = l-2
  9. for i = l-2 downto 0 do
  10. x <- a.[i] + 1.0/x
  11. x
  12.  
  13. let mainP1() =
  14. let array1 = [| 3; 7; 15 |]
  15. let array1f = Array.map (fun x -> float x) array1
  16. let array2 = [| 3; 7; 15; 1; 292; 1 |]
  17. let array2f = Array.map (fun x -> float x) array2
  18.  
  19. printfn "Val lui pi este:\t%A" System.Math.PI
  20. printfn "Val fractiei este:\t%A" (contFraction array1f)
  21. printfn "Val fractiei este:\t%A" (contFraction array2f)
  22. //printfn "Val fractiei este:\t%A" array2f
  23.  
  24. let rec fact n =
  25. if n <= 1 then 1
  26. else n * fact (n-1)
  27.  
  28. //let exp' (x : float) =
  29. // let seqinf = Seq.initInfinite(fun i x -> x/i * (Math.Pow(x, i-1))/fact (i-1))
  30. // seqinf
  31. //
  32. //
  33. //let mainP1() =
  34. // let x = 2.0
  35. // let p = 1e-5
  36. //
  37. // printfn"Serie:\t%.6f" exp' x
  38.  
  39.  
  40. let multiplyl (a:int[,]) (b:int[,]) =
  41. let mutable i=1
  42. let mutable j=1
  43. let mutable k=1
  44. let n=a.GetLength(0)
  45. let m=a.GetLength(1)
  46. let p=b.GetLength(0)
  47. let q=b.GetLength(1)
  48. if p<>m then
  49. Array2D.zeroCreate 1 1
  50. else
  51. let mutable c = Array2D.zeroCreate n q
  52. for i = 0 to n-1 do
  53. for j = 0 to q-1 do
  54. for k = 0 to m-1 do
  55. c.[i,j] <- a.[i,k] * b.[k,j] + c.[i,j]
  56. c
  57.  
  58.  
  59. let mainP3() =
  60. let rand = System.Random()
  61. let a = Array2D.init 2 3 (fun x y -> rand.Next(10))
  62. let b = Array2D.init 3 4 (fun x y -> rand.Next(10))
  63. let c = multiplyl a b
  64. printfn "A = \n%A\n\nB = \n%A\n * B =\n%A" a b c
  65. let d = multiplyl b a
  66. printfn "\nB * A = \n%A" d
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. [<EntryPoint>]
  75.  
  76.  
  77. let main argv =
  78. printfn"-----------P1-----------"
  79. //mainP1()
  80. mainP3()
  81.  
  82. printfn "%A" argv
  83. Console.ReadKey()
  84. 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement