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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

14-Alexandrite

## Derivative calculated incorrectly

I really don't understand why when using a Symbolic Calculation, the value is obtained more accurately than when checking the value normally. What should I do so that the derivative is calculated correctly?

7 REPLIES 7
17-Peridot
(To:Juanneumann72)

Looks like a bug! Seems to diverge after delta = 287

20-Turquoise
(To:Juanneumann72)

I think its a bug. Use next Tip.

23-Emerald III
(To:Juanneumann72)

You should realise that the numeric and symbolic processors in Mathcad and Prime tackle mathematical problems differently, and sometimes that leads to different results.

So we have (also in Prime 4):

And this is clearly a bug, because the answer should be -1000 exactly. Assuming that the numeric derivatie would be calculated with:

Setting a reasonable value of epsilon, like TOL, gives:

That's closer, but not good. Try:

Hmm:

Now we're getting somewhere.

We can try to find the value of epsilon that Prime would use, if my assumption is correct, with:

Working that around, and using the root function gives, for various guess values of epsilon:

OK, let's try:

Apparently Prime uses a different, buggier method to numerically find the derivative.

So, in case of numerical derivatives, you should better define the derivative yourself, using the symbolics:

Or you can check the numerical derivative with:

Which gives:

Success!
Luc

24-Ruby V
(To:LucMeekes)

Apparently Prime uses a different, buggier method to numerically find the derivative.

Not only Prime, the problem already exists in real Mathcad. Here is a screenshot from MC15

Also interesting and confusing that for values between 2350 and 3600 the algorithm returns the correct result just to fall back to 0 for larger values of delta.

What does it look like in MC11?

Worksheet in MC11 format attached

BTW, as far as I know Mathcads numeric algorithms often followed the ones found in the "Numerical Recipes" (http://numerical.recipes/). Not sure if this would also apply to the numerical derivative. Chapter 5.7 dealing with numerical derivatives can also be found here http://pelusa.fis.cinvestav.mx/tmatos/LaSumA/LaSumA2_archivos/NumeRCPs/Texto/bookcpdf/c5-7.pdf

23-Emerald III
(To:Werner_E)

or, directly:

According to the manual, Mathcad 11 uses the Modified Ridder's method (Press et al., 1992; Lorczak). Then appendix L reveals that Press et al. refers to 'Numerical recipies', and Lorczak refers to 'The Mathcad Treasury'.

They must have broken something between Mathcad 11 and 15...

And of course you have this variant. Note the red star!

Luc

24-Ruby V
(To:LucMeekes)

> And of course you have this variant. Note the red star!

Ah, yes. I completely forgot about Mathcads option to optimize a definition because I seldom/never used it.
In this case its obviously equivalent to symbolically evaluate the derivative when defining the function as ttokoro and you had shown in your previous answers.

24-Ruby IV
(To:Juanneumann72)

When I was little, adults told me that taking a derivative numerically is an operation that is incorrect from the point of view of mathematics. For this, children are punished - they are put in a corner.

Announcements
Top Tags