C2_W2_Derivatives

When we reduce the epsilon value further, the expectation is that k should approach 6 but why is the value of k moving away from 6 as the epsilon approaches 0?

The problem is numerical precision.

In the 2nd example, computing (J_epsilon - J) gives an extremely tiny number (because the square of 3 + 0.0000000001 is going to be very close to exactly 9.0), and the floating point format used here doesn’t provide enough precision when dividing by an extremely small number (0.0000000001).

1 Like

Here’s another thread from a while back where I did some systematic experiments to give a concrete example of the point that Tom is making here. The problem is that we hit the limits of accuracy in floating point and things go off the rails. There’s a big difference between dealing with finite representations like 64 bit floating point versus the abstract beauty of \mathbb{R} and what happens when you’re doing “pure math”.

3 Likes

Thank you. At first, I had the same idea and attempted to utilize the Decimal module, but I didn’t achieve the result I anticipated. After seeing your response, I gave it another try and realized my mistake was not passing ‘0.00000000000001’ into the Decimal function during my initial attempt.

4 Likes

Hi mentor
I’ve noticed that we don’t need write print() to output something here (just to better understand Python coding), can this apply to all case?


Thanks
Christina

1 Like

No, those are not correct expressions.

Hello @Christina_Fan,

It actually is only going to print the last expression, and you can experiment it by inserting a few lines of J for example, and see that no matter how manys lines there are, only one get printed out. So, in this case, if you want multiple lines of that, we need print.

Cheers,
Raymond

1 Like

Thank you for the detailed explanation Raymond. Very helpful and I really appreciate it.

2 Likes

You are welcome, @Christina_Fan!

Cheers,
Raymond

1 Like

Thanks for the tip of using Decimal. It can also be simplified just by setting only epsilon as Decimal, and then operate normally.

1 Like