« first day (2434 days earlier)      last day (1144 days later) » 

10:27
Hi, I'm doing the forward difference method to calculate the derivative using the first principle.

My code:
'def FD(f, x, h): #forward method
return (f(x + h) - f(x))/h'

However, when I'm printing values using this code, the answers are very different from the exact value.

'import numpy as np

print("Calculated value =", FD(np.cos, 0, 10**(-1)), "Actual Value = -1.52308671*10**(-5)")
print("Calculated value =", FD(np.cos, 0, 10**(-3)), "Actual Value = -1.52308721*10**(-7)") '

I would really appreciate it if someone could tell me what I'm doing wrong.
user16319883
Help me to solve this issue stackoverflow.com/questions/69611677/…
1 message moved from Python
1 message moved from Python
`def FD(f, x, h): #forward method
return (f(x + h) - f(x))/h`
Like this?
1 message moved from Python

« first day (2434 days earlier)      last day (1144 days later) »