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

how to import an equation from an editor?

ekrem-disabled
1-Newbie

how to import an equation from an editor?

I use a software that generates equation in ascii format (I can see it, for example, in Notepad). The equation is rather long and I want to copy and paste in Mathcad in equation format. I have attached an example file that contains an equation. At the moment I have to copy it to mathcad manually. I want mathcad to read the equation from a text file. How do I do it?

Ekrem.
41 REPLIES 41

On 2/2/2007 6:16:15 PM, ekrem wrote:
> I want
>mathcad to read the equation
>from a text file. How do I do
>it?

You can't. This has come up before. See

http://collab.mathsoft.com/read?88817,11e#88817

Depending on your needs, you might be able to use something from this thread to execute your expressions, even if they are not in Mathcad format:

http://collab.mathsoft.com/read?47441,63e#47441

Richard

http://collab.mathsoft.com/read?55439,11 is an example of a Mathcad worksheet that reads equations (and other stuff) from a file and processes the data using the equation. It might need some adaptation, depending on exactly what can appear in your equations.

� � � � Tom Gutman

On 2/2/2007 6:16:15 PM, ekrem wrote:
>I use a software that
>generates equation in ascii
>format (I can see it, for
>example, in Notepad). The
>equation is rather long and I
>want to copy and paste in
>Mathcad in equation format. I
>have attached an example file
>that contains an equation. At
>the moment I have to copy it
>to mathcad manually. I want
>mathcad to read the equation
>from a text file. How do I do
>it?
>
>Ekrem.
_________________________

The immediate answer is: forget it...

You give values to the software, for doing some task (i.e: a tool), it returns some packaging displayed in a format that only that software understands ... that is for you to modify for instance to customize. You must know exactly the base algorithm it is running (or debug for it) then make the equivalent in Mathcad format.

The packaging the software returns depends upon the numeric engine design. With good tutorial, and understanding of the maths under the hood, sometimes it's possible to convert info from the web into Mathcad executable.

That software of yours, is it a toy or a tool ?
What does it do ?
Why to convert in Mathcad ?
Is it a scientific software ? industrial ? Edu ?

Are you in the transition from your software into Mathcad ?
How do you feed informations into it ?


jmG


Ekrem,

Maybe this is of any help. It works in MathCad 11.2, I've saved it as MathCad 2000.
It's based upon the excellent work done by Martin Schmid (mos).

It does not do exactly the formula you provided, but I think it is extremely powerful.

Regards,
Luc

P.S. I've checked, and it does not work in MathCad 2000.

On 2/8/2007 11:29:37 AM, Luc_Meekes wrote:
>Ekrem,
>
>Maybe this is of any help. It
>works in MathCad 11.2, I've
>saved it as MathCad 2000.
>It's based upon the excellent
>work done by Martin Schmid
>(mos).
>
>It does not do exactly the
>formula you provided, but I
>think it is extremely
>powerful.
>
>Regards,
>Luc
But it not work in Mathcad 12/13/14/15 and Prime
For Mathcad 12/13 see attach

Val
http://twt.mpei.ac.ru/ochkov/v_ochkov.htm

Thank You, Ekrem, for the point on our forum (and me personally) in the article - http://twt.mpei.ac.ru/ochkov/Mathcad-15/Software-Transfer-Functions.pdf

MikeArmstrong
5-Regular Member
(To:ValeryOchkov)

Valery,

Can you provide a image of the function working.

Mike

The function text2equation works here

http://twtmas.mpei.ac.ru/mas/Worksheets/Text2Equation.mcd

It will be very very good to have this built function in Mathcad ** and Mathcad Prime.

Now this function works only un Mathcad 11 and partly in Mathcad 12/13

http://twtmas.mpei.ac.ru/mas/MC_MP_Hole.gif

MikeArmstrong
5-Regular Member
(To:ValeryOchkov)

Very nice, cheers.

Is this down to Mupad?

Mike

Luc,

Have you tried to get this to work in the later versions of Mathcad?

Mike

Mike,

As Valery has nicely pictured, it works due to a narrow hole, existent in Mathcad 11 and 2001i.

I've had access to Mathcad 13 at one time, and I do not recollect it works there; some people have reported that the hole was closed in Mathcad 12 already.

I certainly know it does not work in Mathcad 14 and beyond, because it relies on the symbolic engine being Maple (rather than Mupad).


Luc

MikeArmstrong
5-Regular Member
(To:LucMeekes)

Cheers for the explanation.

Mike

Hi Ekrem,

you could try to use a VBscript.

For example ...

1.) make a file (e.g. test.vbs) with this content:

set shl = createobject("wscript.shell")

wscript.sleep 3000

shl.sendkeys"{(}{(}R1{*}R2{+}R1{*}R3{+}R2{*}R3{)}{+}{(}R1{*}R2{+}R1{*}R3{+}R2{*}R3{)}{)}{*}V1{^}2 {+}1"

2.) open a mathcad worksheet

3.) open a command shell

4.) in the command shell type

%yourpath%> wscript.exe test.vbs ENTER

5.) put the cursor in the mathcad document and wait a few seconds

After a while ther should appear a mathematica expression you can work witrh in Mathcad.

Note: Most operators have to be put in brackets (e.g. {+}). If you have an expression from another application you can solve this using an other script or editor.

Greetings,

Michael

Hi Michael,

I just saw your reply recently as a coincidence after more than a year you posted it.

What you described here is very interesting to me and I can use it. This is what I was looking for. However, the equation that I have may be long and it maybe tedious to put each operator in a curly bracket. I have copied below an example equation to show you the format that my equations are in (my equatiuons are much longer than this one in general):

((-d*Vap/R)+(-d*Vap/C*R*Resr)*s)/((-rL-R)+(-C*rL*Resr-C*R*Resr-C*R*rL-L)*s+(-C*L*Resr-C*L*R)*s^2)

The above equation displays in Mathcad as below. Note that division has precedence over multiplication.

equation.jpg

Is there a way to input the above equation into mathcad as is without modification? I don't know VB at all.

Ekrem.

Ekrem
1-Newbie
(To:Ekrem)

I posted the eqaution in string format wrong in my reply above. So, the string form and mathcad form of it do not match. I corrected it below:

((-d*Vap*R)+(-d*Vap*C*R*Resr)*s)/((-rL-R)+(-C*rL*Resr-C*R*Resr-C*R*rL-L)*s+(-C*L*Resr-C*L*R)*s^2)

The mathcad form of the eqaution is correct in my post above.

Ekrem.

Hi Ekrem,

I did not use the VBscript-way very intensively because I found out, that mathematica is capable to import these strings with less effort.

For using the VBscript-way I just have load the original formula string into a text editor, which is capable to replace text. I replaced

"(" by "{(}"

")" by "{)}"

"^" by "{^}"

and so on and so on.

If I would need to use VBscript to define expressions in Mathcad more often, I would create a "search-and-replace"-macro for the Editor or would look for possibilities to do this in VBscript. (I'm a beginner to VBscript, too.)

So, I'm very sorry, but have to tell you, that I would have to look for a way to cope with this either.

Sincerely,

Michael

Hi Michael,

Thanks for your replies. I have no idea what this Wscript.exe does. Does the requirement of putting operators in curly brackets come from Wscript.exe?

Ekrem.

In Mathcad Prime (Polish notation😞

EquText.png

Hi Valery,

You wrote a code that translates string to Equation that works for MC13. I need very similar code for MC14 or later editions with MuPAD symbolic engine. Please see my reply to Michael Hackner above for an example equation in string format.

Ekrem.

C:\Program Files\Mathcad\Mathcad 15\mupad\mathcad\lib\keywords.mu

keywords::keyword_experimentally := proc(expression)

option hold;

save optionExperimentally;

begin

// This keyword is sometimes used by the development staff for

// debugging in controlled situations and might be expanded for

// use in the product in the future, but at this time it MUST NOT

// be used by end-users nor edited in any way by users.

error(errorBadSyntax);

checkKeywordArgs("experimentally", args(0), 1);

optionExperimentally:=TRUE;

eval(expression);

end_proc:

replace with and restart

keywords::keyword_experimentally := proc(expression)

local var;

option hold;

save optionExperimentally;

begin

checkKeywordArgs("experimentally", args(0), 1);

optionExperimentally:=TRUE;

var := coerce(expression, DOM_STRING);

var := stringlib::remove(var, "mc_");

var := stringlib::remove(var, "mcad_");

var := stringlib::subs(var, "_3A__3A_" = "::");

var := stringlib::subs(var, "_5B_" = "[");

var := stringlib::subs(var, "_5D_" = "]");

var := stringlib::subs(var, "_28_" = "(");

var := stringlib::subs(var, "_29_" = ")");

var := stringlib::subs(var, "_7B_" = "{");

var := stringlib::subs(var, "_7D_" = "}");

var := stringlib::subs(var, "_2C_" = ",");

var := stringlib::subs(var, "_5F_" = ".");

var := stringlib::subs(var, "_20_" = " ");

var := stringlib::subs(var, "_24_" = "$");

var := stringlib::subs(var, "_2F_" = "/");

var := stringlib::subs(var, "_5E_" = "^");

var := stringlib::subs(var, "_2A_" = "*");

var := stringlib::subs(var, "_3D_" = "=");

var := stringlib::subs(var, "_2B_" = "+");

var := stringlib::subs(var, "_2D_" = "-");

var := stringlib::subs(var, "_3A_" = ":");

// var := stringlib::subs(var, "_22_" = numlib::fromAscii([22]));

eval(text2expr(var));

// eval(expression);

// eval(text2expr(expression));

end_proc:


Source: Аналог Maple-интерпретатора в MC14 (Пт Мар 30, 2007)


MC15_screen0.png

Thats very interesting and it works up to a certain degree.

But how could we use this to create a function??

experimentally.png

On first sight it looks like we could have a window to undocumented MuPad features like the window to Maple in MC11, but it seems the resulting expression is taken as a unit and cannot be evaluated, etc. So it would only be for looking at 😞

Does this mean we have the full source of the interface to the Mupad kernel to change and experiment with?

experimentally2.png

This is possible only if you add a prefix to all the names of variables and functions like here:

keywords::keyword_experimentally := proc(expression)

local var;

option hold;

save optionExperimentally, optionRaw;

begin

checkKeywordArgs("experimentally", args(0), 1);

optionExperimentally:=TRUE;

optionRaw := TRUE;

var := coerce(expression, DOM_STRING);

var := stringlib::remove(var, "mc_");

var := stringlib::remove(var, "mcad_");

var := stringlib::subs(var, "_3A__3A_" = "::");

var := stringlib::subs(var, "_5B_" = "[");

var := stringlib::subs(var, "_5D_" = "]");

var := stringlib::subs(var, "_28_" = "(");

var := stringlib::subs(var, "_29_" = ")");

var := stringlib::subs(var, "_7B_" = "{");

var := stringlib::subs(var, "_7D_" = "}");

var := stringlib::subs(var, "_2C_" = ",");

var := stringlib::subs(var, "_5F_" = ".");

var := stringlib::subs(var, "_20_" = " ");

var := stringlib::subs(var, "_24_" = "$");

var := stringlib::subs(var, "_2F_" = "/");

var := stringlib::subs(var, "_5E_" = "^");

var := stringlib::subs(var, "_2A_" = "*");

var := stringlib::subs(var, "_3D_" = "=");

var := stringlib::subs(var, "_2B_" = "+");

var := stringlib::subs(var, "_2D_" = "-");

var := stringlib::subs(var, "_3A_" = ":");

// var := stringlib::subs(var, "_22_" = numlib::fromAscii([22]));

//eval(text2expr(var));

eval(mcad_sin(mc_x));

end_proc:

That is, it is theoretically possible, but practically need a very good understanding of the interaction of Mathcad and MuPAD. 6 years ago I didn't have such a need. Now, as I can see, there are not many people who need this.

Werner Exinger wrote:

Does this mean we have the full source of the interface to the Mupad kernel to change and experiment with?

Yes, you have access to MuPAD symbolic engine so as if you're a developer.

P.S. Once more example.

keywords::keyword_experimentally := proc(expression)

local var;

option hold;

save optionExperimentally;

begin

checkKeywordArgs("experimentally", args(0), 1);

optionExperimentally:=TRUE;

var := coerce(expression, DOM_STRING);

// var := stringlib::subs(var, "_22_" = numlib::fromAscii([22]));

eval(text2expr(var));

end_proc:

MC15_screen1.png

For MC15 it works without mcad_ prefix for functions:

MC15_screen2.png

So text2expr() will be good for displaying an expression only?

If a real function is demanded, it had to be hardcoded in keywords.mu like your sin(x)?

I guess there is no doc available.

I've updated the post above. Not all that bad. You need to change only the names of the variables (MC15).

Viacheslav Mezentsev wrote:

I've updated the post above. Not all that bad. You need to change only the names of the variables (MC15).

I just saw it, thanks.

This question here is related to Valery's question there http://communities.ptc.com/message/205199#205199

It would mean that again some sort of mini-parser would have to be written either in vbscript or MC to prepend that "mc_" in front of the variables (and I guess in front of user defined function names, too) inside the string.

Anyway thanks again for sharing that information which, at least to me, was exciting new.

Not sure at the moment if it would be worth the time digging deeper into this - would take quite some time to figure things out, I guess.

Werner Exinger wrote:

It would mean that again some sort of mini-parser would have to be written either in vbscript or MC to prepend that "mc_" in front of the variables (and I guess in front of user defined function names, too) inside the string.

Yes, but you can write it right in keywords.mu.

Simple example, but you need to do this with all identifiers in the expression.

keywords::keyword_experimentally := proc(expression)

local var;

option hold;

save optionExperimentally;

begin

checkKeywordArgs( "experimentally", args(0), 1 );

optionExperimentally := TRUE;

var := coerce( expression, DOM_STRING );

result := text2expr( "mc_".var );

eval( result );

end_proc:

MC15_screen3.png

P.S. To see what is Mathcad waiting for, you can use this way:

keywords::keyword_experimentally := proc(expression)

local var;

option hold;

save optionExperimentally;

begin

checkKeywordArgs( "experimentally", args(0), 1 );

optionExperimentally := TRUE;

var := coerce( expression, DOM_STRING );

fprint( Text, "log.txt", var );

result := text2expr( var );

eval( result );

end_proc:

For this line:

sin(x) + f(x) experimentally -> sin(x) + f(x)

we get:

C:\Program Files\Mathcad\Mathcad 15\log.txt

"op_add(mcad_sin(mc_x), mc_f(mc_x))":

So its going to get useable.

Many thanks for your detailed explanations.

A last (for now) question: Is it possible to use thinhgs like text2expr() without modifying the file keywords.mu?

I'm asking as I saw in your first screenshot you used txt2expr() in the Mathcad sheet on the left of the symbolic evaluation but still in conjunction with (the modified) keyword "experimentally".

I see that "experimentally" is written on purpose to throw an error in every case, but are there keywords which would evaluate "text2expr()"? I tried some, including undocumented ones like "raw" but to no avail.

Thanks again

Werner

Werner Exinger wrote:

A last (for now) question: Is it possible to use thinhgs like text2expr() without modifying the file keywords.mu?

I'm asking as I saw in your first screenshot you used txt2expr() in the Mathcad sheet on the left of the symbolic evaluation but still in conjunction with (the modified) keyword "experimentally".

You have to understand that Mathcad inserts a prefix to each identifier, so we get:

keywords::keyword_experimentally := proc(expression)

local var;

option hold;

save optionExperimentally;

begin

checkKeywordArgs( "experimentally", args(0), 1 );

optionExperimentally := TRUE;

var := coerce( expression, DOM_STRING );

fprint( Text, "log.txt", var );

result := text2expr( var );

eval( result );

end_proc:

"mc_text2expr(\"123\")":

MuPAD doesn't know about this function. So in my first example I removed this prefix

keywords::keyword_experimentally := proc(expression)

local var;

option hold;

save optionExperimentally;

begin

checkKeywordArgs("experimentally", args(0), 1);

optionExperimentally:=TRUE;

var := coerce(expression, DOM_STRING);

var := stringlib::remove(var, "mc_");

var := stringlib::remove(var, "mcad_");

...

end_proc:

Removing prefixes I can use real names for MuPad functions in Mathcad. In other words, if you want to use MuPad сommands in Mathcad, you need somehow to remove prefixes.The only way that I know - it's editing keywords.mu file. MC11 didn't add anything to the maple function, so it was possible to call the function directly. This is done on purpose so as not to mix the namespaces of the two math programs.

Removing prefixes I can use real names for MuPad functions in Mathcad. In other words, if you want to use MuPad сommands in Mathcad, you need somehow to remove prefixes.The only way that I know - it's editing keywords.mu file.

Think I understand, thank you!

So the command coerce( expression, DOM_STRING ) is a forced type conversion from Mathcad's expression to the left of the symbolic eval into a MuPad string for MuPads further calculations. If the expression is a (MC) string itself its left unchanged I guess. Am just a little confused as coericon is an implicit type conversion in my understanding, not an explicit one as its obviously here.

Announcements