# XLPack API: F# example programs

### How to call XLPack from F#

To call XLPack from F#, it is necessary to use DLL directly.

DLL interface program xlpack_fs.fs is included in SDK, so that the calling program can easily call XLPack like built-in functions without considering the detail DLL interface by declaring “open XLPack”.

Two dimensional array is used for the coefficient matrix a. One dimensional array is used for the right hand matrix b.

### F# example program (Example (1))

```
open XLPack
let TestDgesv() =
let n = 3
let a = array2D [
[ 0.2; -0.32; -0.8 ];
[ -0.11; 0.81; -0.92 ];
[ -0.93; 0.37; -0.29 ] ]
let b = [| -0.3727; 0.4319; -1.4247 |]
let ipiv = Array.create n 0
let info = XLPack.Dgesv(n, a, ipiv, b)
printfn "x = %A, info = %d" b info
TestDgesv()
```

Result

```
x = [|0.86; 0.64; 0.51|], info = 0
```

### F# example program (Example (2))

In Example (2), the integral of f(x) is computed using qk15. qk15 requires the external function defining f(x). It can be coded in F# and qk15 will call it when necessary.

```
open XLPack
let TestQk15() =
let f(x: double) = 1.0/(1.0 + x*x)
let a, b = (0.0, 4.0)
let result, abserr = XLPack.Qk15(f, a, b)
printfn "result = %f, abserr = %g" result abserr
TestQk15()
```

Result

`result = 1.325818, abserr = 0.00148272`