I need to perform some basic OLS regression using F#. To do this I need some Linear Algebra functions, but I'm confused as to what's out there. I can't find any way to invert a matrix. There is some documentation for a library called Microsoft.FSharp.Math.LinearAlgebra
, but I don't know if that exists anymore.
To find the inverse of a 2x2 matrix: swap the positions of a and d, put negatives in front of b and c, and divide everything by the determinant (ad-bc).
What is the Inverse of 3x3 Matrix? The inverse of a 3x3 matrix, say A, is a matrix of the same order denoted by A-1 where AA-1 = A-1A = I, where I is the identity matrix of order 3x3. i.e., I = ⎡⎢⎣100010010⎤⎥⎦ [ 1 0 0 0 1 0 0 1 0 ] .
How do you find the inverse of a function? To find the inverse of a function, write the function y as a function of x i.e. y = f(x) and then solve for x as a function of y.
If you add the FSharp Powerpack to your project (in .NET references), you can use various functionality of the matrix library
edit: you also need to add the experimental library Fsharp.Powerpack.MathProviders, then you can call as follows
open Microsoft.FSharp.Math
let m = Matrix.create 10 10 1.2
let m2 = Experimental.LinearAlgebra.Inverse m
FlyingFrog do a Numerics library which contains Matrix inversion amongst many other functions.
Not sure which is preferable, that or the (apparently deprecated) 'experimental' code from the PowerPack. I guess you could always keep the source code for the managed bit of the PowerPack version in a safe place, still available here:
C:\Program Files\FSharp-1.9.6.2\source\fsharp\FSharp.PowerPack\math\lapack\linear_algebra_managed.fs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With