Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Methods to convert mathematical formulas into code in Matlab, C++, etc?

I have a basic question for all of the math experts out there.

"If I have an academic paper, whats the easiest way to convert a simple mathematical equation into working Matlab (or C++) code?"

Ideally, there would be a Latex >> Matlab (or C++) conversion tool.

However, failing this, is there a "cheat sheet" which contains all of the common mathematical symbols, and their equivalent implementation keywords in Matlab (or R, or C++)?

like image 467
Contango Avatar asked Jul 31 '10 15:07

Contango


3 Answers

Use Mathematica Symbolic Computation.

You can enter mathematical equations straight into Mathematica, then export the result as C code.

Keep tweaking the equation until the rendering looks identical to the original equation in the academic paper. You can then plug your own parameters in, and Mathematica will calculate the result for you.

You can even do cool things such as ask it to differentiate the equation - and it will produce the differential, and printout the resulting equation.

You can call Mathematica from any language, including .NET, Q, Python, Java, etc.

You could even compile the Mathematica program into a .NET assembly and embed it into your app.

Mathematica will also emit Java or C code that matches the mathematical formula you have just entered.

like image 92
Contango Avatar answered Oct 20 '22 15:10

Contango


I've never seen such a thing. Most mathematical notation is written to be understood by a person of (at least) reasonable intelligence, so it frequently omits all sorts of details that would be necessary to produce working code. If you had such a tool, I doubt it would produce usable results more than (maybe) 10% of the time.

The reverse seems a great deal more tenable -- producing readable mathematical notation from code (especially from something like Matlab) sounds much more reasonable. It's much easier to omit information that's present than to try to synthesize information that's missing.

like image 25
Jerry Coffin Avatar answered Oct 20 '22 17:10

Jerry Coffin


There is a codeproject article about Converting math equations to C# expressed as MathML

like image 3
underscore Avatar answered Oct 20 '22 15:10

underscore