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

How to extract a symbolic only function to the numeric processor

SOLVED
Regular Member

How to extract a symbolic only function to the numeric processor

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

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.

symbolic escape_2.png

View solution in original post

20 REPLIES 20

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

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.

symbolic escape_2.png

View solution in original post

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

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.

symbolic+escape_3.png

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).

symbolic escape_4.png

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' )

Image2.gif

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

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.

symbolic+escape_5.png

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

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.

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.

Announcements