Complex Calculations in C#
Asked Answered
A

7

13

What are the best tools (most efficient) available in .NET (C#) for calculating:

  • integrals
  • partial derivatives
  • other non-trivial math

Can people please comment on Mathematica and Matlab and their integration into C#?

Arris answered 29/8, 2009 at 21:24 Comment(2)
To clarify your latest edit, are you trying to use Mathematica and/or Matlab functions in C#, or are you trying to call C# classes from Mathematica or Matlab?Seattle
application is written in C# - i need to perform calculations from C# (call external functions)Arris
S
13

Math.NET is a mathematical open source toolkit written in C# for the Microsoft .NET platform that aims to provide a self-contained clean framework for both numerical scientific and symbolic algebraic computations. In particular, Math.NET Numerics is the result of the merger of dnAnalytics with Math.NET Iridium and includes the following features:

  • real and complex, dense and sparse linear algebra (with LU, QR, eigenvalues, ... decompositions)
  • numerical function integration (quadrature) routines
  • integral transforms
Seattle answered 29/8, 2009 at 21:53 Comment(0)
T
1

I can't vouch for it being the best or more efficient, but a couple of days ago I learned that Luca Bolognese has developed a library of financial functions for .NET

You can find it here: http://code.msdn.microsoft.com/FinancialFunctions

Maybe it'll be usefull for you.

Truancy answered 29/8, 2009 at 21:29 Comment(0)
H
1

I don't have experience with the Mathematica/.NET bridge, but I have used the Mathematica/Java bridge, which, judging from the documentation is pretty similar. Of course, one question I can't answer is how good the implementation of the interface is in terms of stability and performance.

Conceptually, I've found the Java interface for calling out to Mathematica be pretty good. You have a set of objects and methods that let you start Mathematica sessions and send Mathematica expressions to them to be evaluated. You can either send text (which is easy in simple cases but tricky if you want something non-trivial) or more structured Expr objects that mirror the syntax tree structure. These expressions will allow you to do just about anything: evaluate integrals numerically or symbollically, take derivatives, solve ODEs, and so on.

The one area where it falls down some is in error handling. Mathematica doesn't have exceptions per se; instead it produces "messages" when it runs into trouble and continues trying to evaluate the expression it's working on. This makes some sense in light of Mathematica's rather unusual semantics (where it operates on expressions with repeated rule rewrites) but the default set of methods for communicating with Mathematica doesn't allow you to easily monitor those messages from within Java (or, it appears, .NET), though it is possible to write your own methods that do a better job of this.

Hersh answered 31/8, 2009 at 14:6 Comment(1)
Mathematica's MathLink.NET also struggles with complex numbers and Mathematica itself is not particularly good at these kinds of problems (e.g. Mathematica's Fourier was about 4× slower than FFTW last I looked and Mathematica's multicore support is awful).Pecker
P
1

Microsoft's Visual F# programming language was specifically designed for this kind of work so you probably just want to call an existing F# solution from your C# code. For example, in Visual Studio 2010 with our F# for Numerics library installed you can integrate x3-x-1 from -3 to 3 interactively as follows:

> Functional.integrate (fun [x] -> x**3.0 - x - 1.0) [-3.0, 3.0];;
val it : float = -6.0

and compute that function's partial derivative with respect to x at x=2 as follows:

> Functional.d (fun x -> x**3.0 - x - 1.0) 2.0;;
val it : float = 11.0
Pecker answered 22/4, 2010 at 23:6 Comment(0)
W
0

You might check out http://www.dmoz.org/Science/Math/Software/ - they list several C# ones. I'd say try a few (demo editions if commercial) and do some profiling to see if they meet your requirements. You could also use MATLAB - see the Limitations and Alternatives section of that entry. (I have no personal experience with these tools.)

Wherefore answered 29/8, 2009 at 21:30 Comment(0)
M
0

Have a look at f# http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/

It will be part of Visual Studio 2010.

Micah answered 31/8, 2009 at 14:19 Comment(0)
D
0

If you have an add-on product MATLAB Builder for .NET, you can package MATLAB code into a .NET assembly that can be called from C#.

Dede answered 24/6, 2013 at 21:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.