Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
Hi,
For long time, I was looking for a way to convert an eqaution in the form of a string into a Mathcad equation. I thought that it can be done with Mathcad Prime 3. However, I have no programming experince with Mathcad.
I have mathematical equations saved in Notepad in Windows. They are rather long equations. I don't want to manually convert them into Mathcad since it is not practical. In Mathcad Prime I have realized that if I write an equation in double quotation, delete the double quotations and replace the math operators (+, -, *, /) manually afterwards, then Mathcad treats it as equation. I was hoping that a program can be written in Mathcad Prime that takes an equation in the form of string as an input, replaces the math operators; then Mathcad Prime treats the resultant expression as equation. Please see the attached Mathcad Prime 3 file.
Thanks for the help.
Mark.
I have used a long time for this text boxes of Mathcad 11
See please one example http://twtmas.mpei.ac.ru/mas/worksheets/Euler.mcd
We can convert this files into Prime.
Valery,
It looks like my problem can be solved by programming in Mathcad Prime. Is it possible that you write a program in MC Prime 3 to solve my problem? Thanks.
Mark.
You can do almost the same thing in Mathcad 15. Type "1" to get a math region, paste a+b+c after the 1, delete the 1 and change the operators.
In principle a string could be changed to a math region in Mathcad 12 or later (including all versions of Prime) by editing the XML of the file. Writing a program (an external program; I see no way to do it from within Mathcad) would be a very large amount of work though.
Hi Richard,
I verified it in MC15, as you explained. Thanks for pointing this out. Once the formula in string format is pasted next to a number (in MC15) and the math operators are replaced manually, MC starts treating the formula as Mathcad equation. I thought that a program within Mathcad can be written to avoid replacing the math operators manually so that the resultant expression is a Mathcad equation. Is it a big deal to write such a program in Mathcad?
Mark.
There are no built in commands that allow you to manipulate text or math regions. In MC12 through 15 it's possible to manipulate math regions via the automation interface, using a scripted component. There is no access to text regions though. Prime does not even have scripted components. So I see no way to do this except via an external program, and writing such a program would be a lot of work. I suspect far more work than just manually entering your equations in Mathcad.
Ok, Richard. Thanks. I thought I was close to converting the text to math equation.
Mark.
mark neil wrote:
Valery,
It looks like my problem can be solved by programming in Mathcad Prime. Is it possible that you write a program in MC Prime 3 to solve my problem? Thanks.
Mark.
Try please to convert into Prime the Mathcad 15 sheet in attach.
Hi Valery,
I opened it in MC15. But I don't understand how this file is related to my question...
Mark.
mark neil wrote:
Hi Valery,
I opened it in MC15. But I don't understand how this file is related to my question...
Mark.
You can input in the text box any formyla as text and get equation.
ok, Valery. Thanks.
Mark.
Hi Valery,
This file has other things that I don't need. Do you have a version of this file that takes the formula in as string and shows the formula as Mathcad equation? I don't need Newton method of root finding. I try to modify it but it is too complex for me. I am not good at programming in Mathcad. If the file also shows the variables of the equation, it would be even better.
Many thanks.
Mark.
Sorry,
see the picture and the Mathcad 15 sheet in attach
May by this help you.
Valery,
For some reason, it didn't work on my MC15. Please see the attached file.
Mark.
Valery Ochkov wrote:
Sorry,
see the picture and the Mathcad 15 sheet in attach
May by this help you.
Thats a real interesting approach from Viacheslav Mezentsev but this won't work with an untampered installation. You would need to edit at least the file keywords.mu.
@Mark: You might be interested in this discussion http://communities.ptc.com/message/205925#205925 but I guess you will have to accept that what you demanded is still not possible to achieve.
Thanks, Werner. However, the file Newton.xmcd.zip worked on my untempered installation of MC15, in which string is transformed to Mathcad equation. I wonder how it worked in Newton.xmcd.zip
Mark.
mark neil wrote:
Thanks, Werner. However, the file Newton.xmcd.zip worked on my untempered installation of MC15, in which string is transformed to Mathcad equation.
Sure, I never had doubt it. I was referring to Valery's last post about the symbolic "experimental" command which has nothing to do with the Newton-file Valery posted first hand. And, no! - in that Newton file there never is a string transformed to a Mathcad equation (or rather: expression) as you wrote. All thats used here (in the collapsed area "Calculator") is that the string is fed into a parser, written in Mathcad, and is evaluated for the given argument. This interpretation is done for every single argument and thats the reason calculation and plotting is so slow. You may also notice that the function y(x) cannot be evaluated symbolically, so you never will see a symbolic Mathcad expression representing the function. This parser is around here for a very long time and I forgot who created and posted it first, but it can be that the originator is Viacheslav, again. If you search the forum you possibly may be able to download a version with English comments and variable names (not sure, though). The parser may not be complete and have the one or other quirk (e.g. try to use a number like "4.", using a decimal point but don't privide any decimals ) but it sure was a lot of work to develop.
Thanks for the explanation, Werner. It looks like the only way to transform an equation in string format to Mathcad equation is to temper with the Mathcad installation as explained in the link you posted.
I have a plan to write an engineering analysis book using Mathcad, in which I need to transform equations in string format to Mathcad equation. The equations are rather long. I need to automate this; manually typing formulas don't work. I don't think it would be legal to ask the readers of my book to temper with their Mathcad installations for this string to equation translator to work. I don't know what to do. I don't want to use some other math software in my book because my target audience mostly use Mathcad and I am fan of Mathcad.
Mark.
Thanks for the explanation, Werner. It looks like the only way to transform an equation in string format to Mathcad equation is to temper with the Mathcad installation as explained in the link you posted.
I am not sure that this approach would do what you want as you sure are interested to use those expressions and not just look at them.
The other way was sketched by Richard. Use an external program which reads the expressions in text format and create the correct Mathcad XML represenation of them. You may have to look in the "schema" directory of yout Mathcad 15 installation to get the correct syntax. Quite some work to do!
I am also not sure about the approach Michael Hackner suggested in the thread I pointed you to using VBasic and the sendkeys command but it looks interesting.
I have a plan to write an engineering analysis book using Mathcad, in which I need to transform equations in string format to Mathcad equation. The equations are rather long. I need to automate this; manually typing formulas don't work. I don't think it would be legal to ask the readers of my book to temper with their Mathcad installations for this string to equation translator to work.
So you provide those expressions in string format to your readers? Then you could as well provide the expressions in Mathcad format for them!?
Hi Werner,
I will study Hackner's suggestion.
The formulas in the string format are not useful as is. I need to manupulate them in Mathcad to put them in useful forms.
Mark.
mark neil wrote:
Hi Werner,
I will study Hackner's suggestion.
The formulas in the string format are not useful as is. I need to manupulate them in Mathcad to put them in useful forms.
So do it once yourself the hard way and provide your readers the results in Mathcad format?!
Maybe you provide examples of what you are trying to do as there may be an aletrnative approach.
The other way was sketched by Richard. Use an external program which reads the expressions in text format and create the correct Mathcad XML represenation of them.
If this is something that is to be provided to readers of the book, even that is not foolproof. PTC does not make the schema public because then they can change it at will, and of course they do that with every release. The format of math regions is probably pretty stable, but it is not guaranteed that it will not change at some point in the future.
Thanks Werner and Richard.
Werner: Some other guy used the same approach as my analysis approach before. See the article athis link: http://twt.mpei.ac.ru/ochkov/Mathcad-15/Software-Transfer-Functions.pdf. Author of this article obtains equations with some other software in string format and converts them to Mathcad equation using a scripts written by Valery (see page 19, right hand column). I pretty much need the same thing. Valery's code is available here: http://communities.ptc.com/message/206079#206079. This code works with MC13, not for the later versions of Mathcad.
I don't want to force my readers to work with MC13 since because this code works with only MC13. Would it be possible to make a standalone exe file with this str2equ function of Valery working with MC13? If so, I can provide this exe file to the readers of my book to convert string to MC equations, then the converted equations can be used with any versions of MathCad.
Mark.
The link you posted points to a clever parser by Tom Gutman which got broken when Valery tried to convert to Prime format. It looks like recursive evaluation of the vector arguments does not work anymore for some reason. At first glance I haven't seen anything used which was available in older versions only, so I guess it should be able to repair that routine, but that sure would require quite some time until its clear how Tom's routine (should) work together. Why do you think it works in MC13 and not in MC14? Can it be that you mix this up with another routine available which uses the symbolic engine? This engine used to be Maple in former times but was changed to muPad in version 14..
We still don't know about your actual needs, though. I am confused that you'd like to compile that parser to an exe file (which as far as I am aware of is not possible) because you always wrote that you need an "equation" in mathcad. That parser would never provide a symbolic expression, it would just act as a (slow) numerical function.
What about the program which generates the functions you'd like to convert - is that proggy written by you and could it be modified? We don't know what you intend to do with the functions in Mathcad but if numerical calcs are all you need, your program may just output just a bunch of data points, vectors of x- and y values and you may act on those in Mathcad.
Like Werner, I'm a little confused about what you are pointing to. In that thread there are a couple of offerings for version 11 that do what you want. They are based on the Maple symbolic engine and will not work in any later version of Mathcad. I believe that one of these is what the article refers to. There's the method for MC15 and Prime proposed by Viacheslav that will do what you want, but requires hacking some files. Then there is Tom's expression parser. It was written for MC11, but it does not work in versions 12 through 15 because of static type checking. I'm not sure if there's a way to work around that, but IIRC Tom said doing so would at least be too much work to make it worthwhile. It doesn't work correctly in Prime for some other reason, and it would probably be a lot of work to fix it. It doesn't do what you want anyway, because it can only be evaluated numerically, not symbolically.
Werner and Richard,
Sorry for confusing you. The link I provided is a long thread. If you roll up the page of this thread, you will see a file "str2equ" written by Valery that only works in MC13. It doesn't work for MC14 and on becasue the symbolic engine changed to MuPAD from MC14 on. I attached Valery's file in this message.
I wondered if a stand alone exe file can be compiled with "str2equ" so that people who don't have MC13 can still run this file to convert string to MC equation and use them in MC versions that they have. I got the feeling that it is not possible to make an exe file of this file "str2equ".
Werner: I want to pass equations into MC in analytical forms to analytically manupulate them using the symbolic engine of MC. Then assign values to the parameters to provide the readers with numeric examples. So, my analysis will provide the reader analytical as well as numerical solutions.
Mark.
You are correct, that does work in MC13 (but actually does not work in MC11). I just checked. There is no way to compile this into an executable file though.
Sorry, but I can think of no way to do what you want in MC15 (other than what Viacheslav proposed).
When I enter an equation in MC, it corresponds to a specific xml code (I see the code when I open the MC file in Wordpad). Is this code unique to Mathcad, or does some other math software use exact same xml code? Just in case it is possible to convert a string to math equation using some other math software and open it in MC.
Mark.
The schema is specific to Mathcad, and is not even the same for every version. My guess is that the format of the math regions is very similar or identical for versions 12 through 15, and separately for Prime versions 1.0-3.0.
Writing a program to convert the string to the corrrect XML is certainly possible. If you only have to deal with a limited subset of operators and functions that would make it a lot easier (and probably a lot more robust in terms of future versions of Mathcad), but it would still be a fair amount of work.
Richard,
I meant to ask if any other math software (like matlab, mathematica, maple, etc.) use similar xml code? Just in case I can make an exe file with that math software to convert the string into an equation that I can open in MC?
Mark.