Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- How to extract a symbolic only function to the num...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-20-2013
10:18 AM

02-20-2013
10:18 AM

Some functions are only recognized by the symbolic processor. I am looking for a way to encapsulate some of these functions so they are available to the numeric processor via a normal function call. An example with one such function - Si(x) - is shown in the attachments, with various schemes I have tried. The element-by-element approach in item 2 works for assigning values to an array of arguments, but is a bit more awkward than I prefer. My attempts at defining a function in items 4-6 haven't worked.

Is there a way to define a function that is recognized by the numeric processor that does effectively what is in item 4, but works? If it can be done for a scalar, then I would assume that vectorizing this function would allow evaluation with array arguments, since the symbolic encapsulation is isolated in the scalar function definition.

If responding with a file, please save in mcd11 format.

Thanks,

Lou

Solved! Go to Solution.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-20-2013
10:57 AM

02-20-2013
10:57 AM

As you can see in the attached pdf the behaviour of your sheet is differently in Mathcad15 - we get an error in item 2.

Nevertheless I seem to have found a way to turn Si into a numeric function which at least works in Mathcad15, hopefully in Mathcad 11, too.

I have just played around with it and you can even make the precision (now fixed to 10) a second parameter of the function SiNum.

20 REPLIES 20

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-20-2013
10:57 AM

02-20-2013
10:57 AM

As you can see in the attached pdf the behaviour of your sheet is differently in Mathcad15 - we get an error in item 2.

Nevertheless I seem to have found a way to turn Si into a numeric function which at least works in Mathcad15, hopefully in Mathcad 11, too.

I have just played around with it and you can even make the precision (now fixed to 10) a second parameter of the function SiNum.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-20-2013
11:21 AM

02-20-2013
11:21 AM

Re: How to extract a symbolic only function to the numeric processor

Werner - the paste of the full symbolic line into the program works as you suggested in mcd11. It then implements a scalar function. In mcd11, the vectorize is not implicit, as you show for Shi(v), but this is easy to resolve by modifying the program or just explicitly using vectorize.

While I have used symbolic manipulation and functions a fair amount, I have not created programs including them; they've been somewhat of a mystery to get working (as my attempts show). The help documentation wasn't helpful, as I expected, but I read through it anyway. Your hint about copying/pasting the full underlying symbolic line was key, and I expect to get my more complicated real work moving now that you pointed me in the right direction.

Thanks,

Lou

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-20-2013
11:55 AM

02-20-2013
11:55 AM

Re: How to extract a symbolic only function to the numeric processor

Glad that it worked for you in Mathcad 11, too.

The copy and past thing is a real tricky one. I've learned it here (where else) when I was trying to write a program to solve a first order DE symbolically and no matter what the variable is named (should be a parameter of my function). While beeing quite tricky I succeeded but never tackled to expand to second order DEs since then.

You may even simplify SiNum by omitting the return line, BTW, making it a one-liner.

Its especially hard to see that the symbolic evaluation only affects the invokement of the Si-function an not the whole program/local assignment as you would get without copying.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-20-2013
12:31 PM

02-20-2013
12:31 PM

Re: How to extract a symbolic only function to the numeric processor

Or still another simplification getting rid of he local assignment, too (the brackets are mandatory, though).

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-20-2013
01:17 PM

02-20-2013
01:17 PM

Re: How to extract a symbolic only function to the numeric processor

In order to get rid of having to specify the number of digits for the numeric processor, while knowing that it can work with at maximum 17 digits, here is another simplification (works in MathCad 11), assign the result of the symbolic expression to any variable (here 'r' )

Now the numeric function behaves like a normal numeric function regarding formatting its results.

In defining the SiNum() function you have to first type the symbolic expression as:

Si(x)[CTL >]

then type the numeric function as:

SiNum(x):r{

then copy the symbolic expression and paste it into the placeholder of the numeric function definition. Done

Success!

Luc

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-20-2013
01:43 PM

02-20-2013
01:43 PM

Re: How to extract a symbolic only function to the numeric processor

The point of the posting is to indicate that a precision of 18 is sufficiently (if you stick to numeric evaluations), right?

In my first post there was already a fixed precision of 10 (taken from Lou's original sheet). The precison as second parameter being meant as an option.

In your step by step explanation of how to retype my function you forgot about the float command - it won't work without. BTW, if you look at the last post of me which you answered at you can see that even the local variable is not necessary.

The behaviour concerning formatting seems to be different between Mathcad 11 and 15. In 15 I see the "full" precision (even more than 18 if specified in the function or via second parameter). So despite of using the numeric equal sign it seems to be somewhat seen as a symbolic result. Only if I verctorize (again) the normal numeric behaviour is seen. Strange and while its not important I do not understand, why.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-20-2013
01:51 PM

02-20-2013
01:51 PM

Re: How to extract a symbolic only function to the numeric processor

In the simp[le example I had given, there is no need to keep more precision in the symbolic result than the numeric processor can maintain, and there is no need to pass it as an argument, as you point out. In the real, more complicated case I'm working on, the symbolic expression to be evaluated is in fact a small difference of two quite large numbers. Here, the symbolic calculation must have high enough precision (~60-100) so that the relatively small difference is calculated accuratey. I may pass the symbolic precision as a parameter, or just leave it at the max of what I think I need. I do remember the many admonitions on the forum that the precision is the accuracy of all numbers in the symbolic calc, not the precision of the final result. Regardless, the normal numeric precision of this difference is then adequate for further work.

Lou

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-20-2013
02:41 PM

02-20-2013
02:41 PM

Re: How to extract a symbolic only function to the numeric processor

I do remember the many admonitions on the forum that the precision is the accuracy of all numbers in the symbolic calc, not the precision of the final result.

Yes. I keep pointing this out. The float keyword should be used very sparingly. And by that I mean almost never.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-20-2013
02:55 PM

02-20-2013
02:55 PM

Re: How to extract a symbolic only function to the numeric processor

Richard Jackson schrieb:

I do remember the many admonitions on the forum that the precision is the accuracy of all numbers in the symbolic calc, not the precision of the final result.

Yes. I keep pointing this out. The float keyword should be used very sparingly. And by that I mean almost never.

This application seems to be one of the spare exceptions as it won't work without float.