Numerical approximation of a dx/dy derivative

489 Views Asked by At

I have to find numerical approximation of the derivative of dx/dy where y(x)=exp(sin^2(x)+cos(x)exp(x^2)) at the point Xo=0.5. As far as I understand, I have to pick a close point to X0 for example 0.501 and calculate the function f'(0.5)=(f(0.501)-f(0.5))/(0.501-0.5) but it is very complicated. Any help?

2

There are 2 best solutions below

0
On

If you just need the derivative, then you can calculate it using the chain rule. In that case, if you are unable to find the derivative, you should say so in the question.

If your task is to specifically calculate a numerical approximation, then simply take your favorite programming language or tool and write a function that calculates $f(x)$. In Python, the function can be written in one line, and it looks something like

import math

def f(x):
    return math.exp(math.sin(x)**2.....)

then take some small value of $h$ and calculate the approximation of the derivative:

h=0.001
x=0.5
print (f(x+h) - f(x)) / h
0
On

If you want to calculate an approximate derivative, it is better to use $\frac{f(x+h)-f(x-h)}{2h} $ rather than $\frac{f(x+h)-f(x)}{h} $, because its error is $O(h^2)$ compared with the $O(h)$ of the standard form.