Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Learn more about F# at http://fsharp.org
- // See the 'F# Tutorial' project for more help.
- open System
- let contFraction (a:float[]) =
- let l = Array.length a
- let mutable x = a.[l-1]
- let mutable i = l-2
- for i = l-2 downto 0 do
- x <- a.[i] + 1.0/x
- x
- let mainP1() =
- let array1 = [| 3; 7; 15 |]
- let array1f = Array.map (fun x -> float x) array1
- let array2 = [| 3; 7; 15; 1; 292; 1 |]
- let array2f = Array.map (fun x -> float x) array2
- printfn "Val lui pi este:\t%A" System.Math.PI
- printfn "Val fractiei este:\t%A" (contFraction array1f)
- printfn "Val fractiei este:\t%A" (contFraction array2f)
- //printfn "Val fractiei este:\t%A" array2f
- let rec fact n =
- if n <= 1 then 1
- else n * fact (n-1)
- //let exp' (x : float) =
- // let seqinf = Seq.initInfinite(fun i x -> x/i * (Math.Pow(x, i-1))/fact (i-1))
- // seqinf
- //
- //
- //let mainP1() =
- // let x = 2.0
- // let p = 1e-5
- //
- // printfn"Serie:\t%.6f" exp' x
- let multiplyl (a:int[,]) (b:int[,]) =
- let mutable i=1
- let mutable j=1
- let mutable k=1
- let n=a.GetLength(0)
- let m=a.GetLength(1)
- let p=b.GetLength(0)
- let q=b.GetLength(1)
- if p<>m then
- Array2D.zeroCreate 1 1
- else
- let mutable c = Array2D.zeroCreate n q
- for i = 0 to n-1 do
- for j = 0 to q-1 do
- for k = 0 to m-1 do
- c.[i,j] <- a.[i,k] * b.[k,j] + c.[i,j]
- c
- let mainP3() =
- let rand = System.Random()
- let a = Array2D.init 2 3 (fun x y -> rand.Next(10))
- let b = Array2D.init 3 4 (fun x y -> rand.Next(10))
- let c = multiplyl a b
- printfn "A = \n%A\n\nB = \n%A\n * B =\n%A" a b c
- let d = multiplyl b a
- printfn "\nB * A = \n%A" d
- [<EntryPoint>]
- let main argv =
- printfn"-----------P1-----------"
- //mainP1()
- mainP3()
- printfn "%A" argv
- Console.ReadKey()
- 0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement