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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

displaying (and exporting) the formula of a function

cberceanu
2-Guest

displaying (and exporting) the formula of a function

Hello all,

Hopefully this is something you could help me with. I am using Mathcad14, but I do have access also to Mathcad15 if needed (but not any Prime versions).

 

Suppose I have a sheet with this simple function:

a(b,f):=b+f

 

I need to:

a) display again lower in the sheet the exact formula of function a (meaning, I want to be able to type somewhere lower in the sheet "a(b,f)=" and then for Mathcad to automatically add after this "b+f")

 

b) I want to "export" a(b,f):=b+f (or even at least b+f) as a string to a file (excel preferrably)

 

I do have some (limited) scripting ability and I did manage to export data to excel files, but I can only do so with strings or simple variables. I have not found yet a way to do this for formulas. I am not even sure if it is possible. I do realize "formula to string" is a BIG thing, due to the many possible formats a formula may appear as, but atm I am really dealling with very simple expressions, like a*b+c (single row, basic operators).

 

Best regards,

Cristian

 

P.S. I would even be happy if I could export (through a script)  the specific a(b,f):=b+f math region to clipboard as a picture and then (still through the script) paste it in excel, if that is easier.

1 ACCEPTED SOLUTION

Accepted Solutions

You can use the symbolic processor (in 14 aand/or 15) to do this:

equals.PNG

Note that if you have assigned values to b and f you will need to put b:=b and f := f above the symbolic values.  If you right-click on the symbolic expression you can alter its appearance.

 

Exporting to a file or EXCEL is more problematic.

View solution in original post

7 REPLIES 7

You can use the symbolic processor (in 14 aand/or 15) to do this:

equals.PNG

Note that if you have assigned values to b and f you will need to put b:=b and f := f above the symbolic values.  If you right-click on the symbolic expression you can alter its appearance.

 

Exporting to a file or EXCEL is more problematic.

LucMeekes
23-Emerald III
(To:cberceanu)

The first part is easy. Make sure b and f are undefined at the point where you wnat to display the function definition of a (e.g. by undefining them with b:=b and f:=f),. Now you can display the definition of a with the symbolic evaluation:

a(b,f)->

 

You find the symbolic evaluation operator '->' on the symbolic operators pad, or using the keystroke [Ctl]. (That is pressing the Ctl key down and while it is pressed down, hitting the '.' key.)

 

The other part is very difficult, if not impossible. You cannot determine from any variable a string containing its name.

 

Success!
Luc

LucMeekes
23-Emerald III
(To:LucMeekes)

As said, the expression (variable or function) to string conversion is not available in Mathcad, although it has been asked for.

The other way around was found over 10 years ago , but only works in mathcad 11 (not before, not after).

This is what it can do:

LM_20171106_Str2exp.png

That way you can even import an expression contained in a string from excel, and convert it to a mathcad expression.

 

Luc

RichardJ
19-Tanzanite
(To:LucMeekes)


@LucMeekes wrote:

The other part is very difficult, if not impossible. You cannot determine from any variable a string containing its name.

You could do this, in principle, by using a scripted component to get the XML of the region. It would be a lot of work though, because it would need an interpreter that could parse the XML to the desired string. Here, for example, is the XML for a(b,f):=x+b

 

<ml:define xmlns:ml="http://schemas.mathsoft.com/math30">
            <ml:function>
                        <ml:id xml:space="preserve">a</ml:id>
                        <ml:boundVars>
                                    <ml:id xml:space="preserve">b</ml:id>
                                    <ml:id xml:space="preserve">f</ml:id>
                        </ml:boundVars>
            </ml:function>
            <ml:apply>
                        <ml:plus/>
                        <ml:id xml:space="preserve">b</ml:id>
                        <ml:id xml:space="preserve">f</ml:id>
            </ml:apply>
</ml:define>

 

LucMeekes
23-Emerald III
(To:RichardJ)

I guess you meant to say: here's the XML for the function:

a(b,f):=b+f

{  not f(b,f)  }

 

Luc

RichardJ
19-Tanzanite
(To:LucMeekes)

It looks to me like that's what is says Smiley Wink

Thank you very much everybody, for the great help. Point a solved succesfully.

 

For point b, I came up with the following workaround (very specific to my current needs). I have the function:

1.png

and I can convert it to string using the following trick:

2.pngOf course, it only works for this particular shape of the function formula, but for the mooment, that is sufficient for me.

 

Thank you again.

Top Tags