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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Problem with numeric eval of user written derivation routine

Werner_E
25-Diamond I

Problem with numeric eval of user written derivation routine

Mathcads derivation operator is limited up to the fifth derivative. You would have to nest that operator for higher derivatives.

So I wrote a routine using recursion to calculate the n-th derivative of a function f at position a.

Using a third root of x+1 all works ok up to the fourth derivative. For higher derivatives only symbolical eval works but numeric would run endless (at least a cancelled eval after a while).

I guess that the numeric approximation algorithm for calculating the derivative will have to go through the recursion for every iteration step and thats very inefficient.

But why that abrupt change from fourth to fifth derivative?

4 REPLIES 4
RichardJ
19-Tanzanite
(To:Werner_E)

I am guessing that it's a roundoff problem. There is nothing magic about the fifth derivative: change to f1(x):=x^5 and it works fine.

Werner_E
25-Diamond I
(To:RichardJ)

Richard Jackson wrote:

I am guessing that it's a roundoff problem. There is nothing magic about the fifth derivative: change to f1(x):=x^5 and it works fine.

Yes, I already noticed that other functions like polynomials work OK.

You think the numeric derivation algorithm isn't converging due to roundoffs?

EDIT: Just noticed that I was a bit too impatient. Calculation completes after some time (but disproportionally more than for the fourth derivative) but the result is 0. Is it this what you meant with roundoffs? I was concerned about the calc time.

RichardJ
19-Tanzanite
(To:Werner_E)

I didn't wait for it to complete either

A numerical derivative calculates differences (at least, I can't think how an algorithm would work that didn't do that). So when you have differences of differences of differences of differences of differences, etc, it has to fall apart numerically at some point. Surely either it just ends at zero (what you have observed), or oscillates between bits forever. I don't know that's what the problem is, but that seems to be a strong possibility.

Werner_E
25-Diamond I
(To:Werner_E)

Any ideas how to get the most reliable higher derivative numerically?

Using nested derivative operaters fail from time to time, but the result is not only dependable on the way I nest those operators. Different combinations fail for different values of a.

Also to be honest I don't understand why nesting that operator works at all. The inner one would yield a constant if used on its own and so the outer one should simplify to zero. But the help states you can nest them to get higher derivatives and its true - at least it works most of the time, but I cannot spot a pattern as to when it will fail.

I had in mind a derivation routine which I could use in a program loop with the order as parameter, but there seems to be no reliable way to do without using symbolics.

derivatives2.png

Announcements

Top Tags