Jonathan Beerhalter
Jonathan Beerhalter

Reputation: 7407

How do I invert a matrix in F#?

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.

Upvotes: 7

Views: 3276

Answers (4)

Benjol
Benjol

Reputation: 66587

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.

Upvotes: 1

Codingday
Codingday

Reputation: 855

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

Upvotes: 6

Craig
Craig

Reputation: 12022

Have you checked out this. It might help.

Upvotes: 0

Brian
Brian

Reputation: 118895

I don't know; in the 1.9.6 version of F# I don't see anything offhand, the docs are here

http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/namespaces.html

and there is Matrix stuff in the Microsoft.FSharp.Math namespace in the FSharp.Powerpack.dll, but I don't see 'invert' offhand, and I don't know about the 'LinearAlgebra' stuff (deprecated? web search suggests it disappeared a few releases back).

Upvotes: 0

Related Questions