Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Set up a solver for a school assignement, but the good Professor threw a curve ball at us: the point given for evaluation is smack in the middle of a discontinuity and the unhappy solver returns "no solution found".
The evaluation point can be varied manually until the solver wakes up, to find the boundaries of the discontimuity, but would like to automate the process (keep in mind though that my programming skills do not go much further than some of the most basic examples in the users manual!).
Is it possible to use ON ERROR for looping? Is there an example somewhere I could look at?
I don't know how to set up the solver within a program, but can wrap it up in a function and just call the function in the program, so should be OK there. It is mainly the structure for the ON ERROR feed back that is not very clear to me, for incrementing up and down the value to be solved for, until the solver doesn't trigger ON ERROR anymore.
Thanks.
One example.
If we use the built-in function rkfixed we can not see where is an error
If we use the user function rkfixed with an on error operators we can see it:
This is beautiful! You can feel the iteration going Tic Tac Tic Tac, at the rythm of the Mathcad clock, probably mesmerizing some of the occupants of the Ward.
Thanks a lot for the example. I am starting to see now how "on error" works: Not at all how I thought it was, but in fact just what I need! Very хорошо.
Laurent Muller wrote:
This is beautiful! You can feel the iteration going Tic Tac Tic Tac, at the rythm of the Mathcad clock, probably mesmerizing some of the occupants of the Ward.
Which Ward of this - http://communities.ptc.com/groups/mathcad-paradoxes ?
Lovely example Valery.
Mike
I deleted a file posted earlier that had a blatant flaw. Attachement now shows my issue with implementing "on error" in a program. It works for Valery but not for me....
There must be something wrong with my syntax, because "on error" in the program correctly returns the "on error" value but returns "0" for non error values, instead of the value of the function.
This looks like it could be another one for Valery's "how can you do that file"...
The statement is either X<- NaN if the result of f(x) creates an error or X is undefined.
I would have expected that the program report an error because X does not have a definition, but it appears that it is initialised with 0
Modified program shows the difference
Regards
Andy
Thanks Andy. I fell straight in Valery's trap. He was probably waiting for me to knock at the door of the Ward on this one! I see now that it was not enough just to try to make it look like Val's....
I got going with my piddly program by defining an external function with the "on error" syntax and calling the function in the program. That should have tipped me on what was wrong with my "on error" usage inside of the program.
Thanks again.
Laurent Muller wrote:
Thanks Andy. I fell straight in Valery's trap. He was probably waiting for me to knock at the door of the Ward on this one! I see now that it was not enough just to try to make it look like Val's....
I think you have clicked at first break and than on error!
We must click at first on error and than break!
There is a special Ward for users with this case in Mathcad House here http://communities.ptc.com/groups/mathcad-paradoxes
Ward Warden,
The Ward is the first place I went to (there are surprisingly very few programming examples of "on error" in the litterature, main use seems to be with functions) . But I missed the "on error" case there. Maybe it is similar to the "Return" Ward?
Anyhow, Andy managed to ward me off this one!
Not sure what the right "click" sequence is to get the expected behavior. But here is what worked for me:
-- Noting that creating an "on error" function and cutting and pasting it into the program would work
-- Did the same with the "on error" statement
-- First insert the variable and assign arrow in the program
-- Complete the "on error" statement outside of the program
-- Cut and paste the complete "on error" statement to the right of the assignement arrow.
There must be for sure a quicker way, but this is in a form that makes sense to me and might be able to remember.
Thank you.
Laurent Muller wrote:
It works for Valery but not for me....
Sorry, see the Mathcad 15 sheet in attach!
Thanks....Andy just got me straight on that puzzle.
Laurent Muller wrote:
...Is there an example somewhere I could look at?..
Some examples can be found in the e-book for Mathcad: "Inside Mathcad: Programming".
Now I don't feel so bad about having allocated some of my slim student budget to a 15 Student Licence: It helps me dowload the forum's attachements and read the eBooks! Thanks for the link to the page set up by Mrs Zeftel. Much appreciated.
Too bad though that I got 15 before Prime came out. Looks like I am missing out on a lot of fun! But I can hardly imagine what working in Mathcad without floating toolbars would be.
Mathcad 15 IMO is still the best version to have. Prime 2 hasn't got all the features that M15 has.
Mike
Mike Armstrong wrote:
Mathcad 15 IMO is still the best version to have. Prime 2 hasn't got all the features that M15 has.
Mike
I guess you do not have M11 then...
On the "on-error" usage:
the syntax is
<this statement is executed> on error <(only) when this statement produces any error>
In general to program it, first put the 'on error' on the programming line, so you get:
# on error # (where # are placeholders)
then insert the statements on the placeholders.
Luc
Looks like the "Ward" thing happens with the sequence used to assign the "on error"statement value to a variable. The program line may look exactly like Valery's example, but behaves differently depending on the sequence used to enter it.
Laurent Muller wrote:
Looks like the "Ward" thing happens with the sequence used to assign the "on error"statement value to a variable. The program line may look exactly like Valery's example, but behaves differently depending on the sequence used to enter it.
In Mathcad Prime this operator has a new name - try!
The University must have sold me the last 15 on campus that didn't come bundled with Prime! So no luck there.
I got the little program running using "on error" to get a solver function to crawl out of the hole of a discontinuity. Although it works, it is a total waste as the Solver tries for too long to find a solution before capitulating and it takes for ever to trigger "on error". It is faster to search for the edge of the hole manually.
However, setting CTOL to a high value returns a perfectly useable result in one short stroke. What is great, is that the solver function can be used anywhere below its definition, it still uses the CTOL setting at the Solve Block definition and still works under the level where CTOL is reset to a smaller value.
A quick question on that. When reassigning a smaller value to CTOL in the sheet, is there a way to assign to it the value that is defined under the Worksheet Options instead of assigning a fixed value to it?
EDIT: Never mind, that was easy. Sorry.
Thanks
Laurent Muller wrote:
The University must have sold me the last 15 on campus that didn't come bundled with Prime! So no luck there...
But you can install the 30-day trial version of Mathcad Prime 2.0:
http://www.ptc.com/product/mathcad/free-trial/thank-you.htm
Mathcad Prime 2.0 installation guide for 30-day trial:
http://www.ptc.com/WCMS/files/137577/en/Mathcad_Prime_2_0_Installation_Guide.pdf