What is the MathNet equivalent of MATLAB solve C = A \ B
Asked Answered
P

4

5

I've recently begun using MathNet to implement our linear algebra, however I'm having some trouble translation MATLAB functions to MathNet.

In MATLAB I often use the simple solve using the backslash operator:

C = A \ B

What is the equivalent of this in MathNet?

I get the same results in a small matrix using C = Inv(A) * B, but I don't know if the result is as precise.

Praseodymium answered 9/2, 2012 at 9:22 Comment(0)
W
2

I don't think MathNet has any "equivalent" of Matlab's backslash operator. See this site for some info on how Matlab's backslash works: Matlab manual on mldivide(). I guess you could look at some of the solve methods, like QRSolve, but I don't think they will be as easy to use...

What do you mean by "precise"? Are you asking if MathNet's inv() does exact inversion of a matrix, or are you simply asking if you could calculate C as Inv(A)*(B)?

If you are asking the later, yes, for square matrices Matlab's backslash is roughly the same as Inv(A)*(B).

Wickerwork answered 9/2, 2012 at 10:2 Comment(3)
Im asking the latter yes. Ok, then I'll just use this. When you write that is roughly the same, wherein lies the difference?Praseodymium
The difference is that Matlab does Gaussian elimination when using the backslash operator, thereby reducing computational complexity and increasing numerical stability. Explicit computation of the inverse could be ill-conditioned under some conditions and therefore when working in Matlab you are better of using backslash.Wickerwork
Ok, thank you. I think I need to look into some linear algebra :)Praseodymium
E
5

var C = A.QR().Solve(B); (using QR decomposition)

For square matrices also: var C = A.LU().Solve(B); (using LU decomposition)

Ellsworth answered 29/8, 2012 at 12:47 Comment(0)
W
2

I don't think MathNet has any "equivalent" of Matlab's backslash operator. See this site for some info on how Matlab's backslash works: Matlab manual on mldivide(). I guess you could look at some of the solve methods, like QRSolve, but I don't think they will be as easy to use...

What do you mean by "precise"? Are you asking if MathNet's inv() does exact inversion of a matrix, or are you simply asking if you could calculate C as Inv(A)*(B)?

If you are asking the later, yes, for square matrices Matlab's backslash is roughly the same as Inv(A)*(B).

Wickerwork answered 9/2, 2012 at 10:2 Comment(3)
Im asking the latter yes. Ok, then I'll just use this. When you write that is roughly the same, wherein lies the difference?Praseodymium
The difference is that Matlab does Gaussian elimination when using the backslash operator, thereby reducing computational complexity and increasing numerical stability. Explicit computation of the inverse could be ill-conditioned under some conditions and therefore when working in Matlab you are better of using backslash.Wickerwork
Ok, thank you. I think I need to look into some linear algebra :)Praseodymium
G
1

With the tests I've made using Matlab and Math.Net Numerics:

Matrix A Vector B

Matlab: A \ B Math.Net Numerics: A.QR().Solve(B)

Both give the same results (in my case). I think it will work with B being a Matrix also.

Gustation answered 18/9, 2015 at 13:49 Comment(0)
H
0

If you use ILNumerics.Net Library, You can try ILMath.linsolve(A, B);

Hindenburg answered 3/6, 2014 at 15:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.