Hi,

I was wondering if anyone has run into an easy way to convert a math expression in matlab to a c++ expression. For example:

In MATLAB you have a symbolic expression like:

"(x+y)^2+1/(2*x+y)^(1/2)"

In C++ this would be something like:

"pow((x+y),2.0) + 1/pow((2*x+y),1.0/2.0)"

(this assumes of course the user is smart enough to include math.h and define the variable x and y)

I am faced with converting several dozen math expressions that span several lines each into a c++ code and was wondering if others have found an easy solution for this other than to manually switch out expressions like "^" and transform them to "pow(,)".

Thanks in advance for any help with this.

PS: If it wasn't obvious from the question, I am trying to re-write a matlab code in c++ and was faced with converting lots of math equations. I could use the mcc function but I would like a more clean and perhaps more optimized code, hence the reason for no using mcc or other such converters.

If you really mean you have an expression created using sym objects from

Symbolic Math Toolbox when you say "a symbolic expression" then look here:

http://www.yqcomputer.com/

If you mean that you have a string that you'd like to convert, I don't

believe there's a ready-made function to do what you want, though creating

the correct patterns [the hard part] and applying REGEXP to your expression

should do the trick.

--

Steve Lord

XXXX@XXXXX.COM

comp.soft-sys.matlab (CSSM) FAQ: http://www.yqcomputer.com/

Wow never knew that command existed! THANKS A BUNCH STEVE! This is exactly what I needed! You saved me hours upon hours of work. :D

1. Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2)

2. Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2)

3. Is there a way to have math that is not "display math" look like display math?

4. Is there a way to have math that is not "display math" look like ?display math?

5. FA: 1-Day-Left: 6 Math Books - 4 Math CDROMs - Algebra, Discrete Math, Calculus, more...

6. Is there a way to have math that is not "display math" look like display math?

7. Error on Book: Advanced Eng Math using Math and Matlab ???

8. changing math operations for math operations with = sign

9. Lucida math (NOT Lucida new math) style

10. producer/converter from clickable natural display math to inline math

11. unicode-math with Cambria Math on Linux

12. math.h trig functions questions (and some forgotten high school math)

13. XML::Simple + Math::Currency / Math::BigInt problem

14. sprintf() for Math::BigInts and Math::BigFloats

15. [PHP] Math problems (No not high school math!)

3 post • Page:**1** of **1**