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