cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Generate C++ code from a Mathcad model

siniestro-disab
1-Newbie

Generate C++ code from a Mathcad model

Is it possible to generate C++ code from a Mathcad model? That would be very interesting.
8 REPLIES 8

You are not the first to request that. C has been requested too, and (I think) Fortran. It's not possible though.

Richard
StuartBruff
23-Emerald II
(To:RichardJ)

On 9/22/2005 9:40:33 AM, rijackson wrote:
=Is it possible to generate C++ code from a Mathcad model? That would be very interesting.
>You are not the first to request that. C has been requested too, and (I think) Fortran. It's not possible though.

Well, it's partially possible with a bit of effort and work.

There was a request to convert a Mathcad expression into an equivalent string expression quite recently. I had a quick play with the xmcd format and it looks feasible.

It's on the backburner at the moment, but it's a fairly straight forward job to convert the prefix notation string into an equivalent infix.

From there, it also looks feasible to construct a C or FORTRAN like program (for numerics only - none of your symbolic rough stuff). The major problem is creating the Mathcad libraries

OTOH, it should be possible (and easier) on the symbolic side to export it to something like Maxima and even import Maxima programs.

Stuart
RichardJ
19-Tanzanite
(To:StuartBruff)

On 9/22/2005 10:11:21 AM, stuartafbruff wrote:
> The major
>problem is creating the Mathcad
>libraries

That, I think, is the crux of the problem. Convertng simple expressions may be possible, but writing simple expressions in C is not hard anyway. What people want is to be able to take a complex worksheet that uses Mathcad's built in functions, and convert the whole thing to C. Even creating C that calls the Mathcad DLLs will not be acceptable to many, because the end destination is not a Windoze system: it's, for example, a DSP.

As I understand it, this is something that Matlab can actually do.

Richard




StuartBruff
23-Emerald II
(To:RichardJ)

On 9/23/2005 10:35:05 AM, rijackson wrote:
> The major problem is creating the Mathcad libraries
= That, I think, is the crux of the problem. Convertng simple expressions may be possible, but writing simple expressions in C is not hard anyway.
= What people want is to be able to take a complex worksheet that uses Mathcad's built in functions, and convert the whole thing to C.

I think you can pretty well automate the conversion of the whole of a worksheet into C/FORTRAN/Pascal, even programmed functions ... although I'm not sure about components (including plots) - these appear to be binary encoded by gzip and I haven't looked at how to gunzip them.

= Even creating C that calls the Mathcad DLLs will not be acceptable to many, because the end destination is not a Windoze system:

Agreed, but it may be acceptable to another many.

Most of the mathcad functions are already available in one form or another in many libraries, including the matrix routines. One could either target the code generator at those libraries or write an external converter (I'm not going to do it!) which leads on to the next bit ...

= it's, for example, a DSP.
= As I understand it, this is something that Matlab can actually do.

Yeess, but, AFAIA, you need to buy the (additional) Toolbox that does that and has all of the appropriate libraries for the (supported) families of DSP processors (eg TI C6000).

I know it's a very simplistic view of life, but some enterprising soul might find it worthwhile to do the same thing for Mathcad.

Stuart

I don't think it's anywhere near as simple as that. Converting arithmetic expressions is simple enough -- the main requirement would be an XML parser.

But anything beyond that runs into the problem that Mathcad uses rather different fundamental concepts and constructs. Just the worksheet variables, and the := worksheet assignment is a serious problem. How do you think that would be mapped into C++?

� � � � Tom Gutman
StuartBruff
23-Emerald II
(To:TomGutman)

On 9/23/2005 7:57:58 PM, Tom_Gutman wrote:
==I don't think it's anywhere near as simple as that.

As simple as what "that"? Did I say it was simple?

== Converting arithmetic expressions is simple enough -- the main requirement would be an XML parser.

That's why I gave the conversion functions names of the form 'parsexx' ...

== But anything beyond that runs into the problem that Mathcad uses rather different fundamental concepts and constructs. Just the worksheet variables, and the := worksheet assignment is a serious problem.

Serious? maybe, maybe not; depends on how you define 'serious' 🙂

Showstopper? ...?

== How do you think that would be mapped into C++?

Is a C program a legal C++ program?

Stuart

With a few, not generally important, exceptions, yes.

� � � � Tom Gutman

Given:

<ml:define>
                        <ml:id xml:space="preserve" subscript="EPDM">cp</ml:id>
                        <ml:apply>
                            <ml:mult/>
                            <ml:real>1.00</ml:real>
                            <ml:apply>
                                <ml:div/>
                                <ml:id xml:space="preserve">kJ</ml:id>
                                <ml:apply>
                                    <ml:mult/>
                                    <ml:id xml:space="preserve">kg</ml:id>
                                    <ml:id xml:space="preserve">K</ml:id>
                                </ml:apply>
                            </ml:apply>
                        </ml:apply>
                    </ml:define>

 

The algorithm might be:

search for <ml: define 

take the next <ml:id tag as the left side of the assignment, add subscript="subscript" to the variable name

search for a <ml: apply tag and write the opening parenthesis for it

define an operator from <ml:mult <ml:div etc. -

use the following  <ml:id tags concatenating using the operator

search for the closing of the</ ml: apply tag and write the closing parentheses

 

 

Since the ml: apply tags are nestetd using xslt might not be possibl straighforwardly...

Announcements