numerical derivatives in case of restricted parameter space

40 Views Asked by At

I want to evaluate numerical partial-derivatives (/Jacobian) of a function $f(x)$ which is a function of two variables $x_1$ and $x_2$. The function is defined only for positive values of $x_1$ and $x_2$. Therefore, it is creating a problem in applying finite-difference method using exisiting MATLAB packages, becuase the finite-difference may need to evaluate the funtion at negative values of $x_1$ and $x_2$.

So, it seems that I have to write a code such that it can avoid the function evaluation at negative values of the variables. The problem is that I am not familiar with numerical methods; so I need a short and clear reference to learn numerical derivative computation. Any suggestions would be helpful.

1

There are 1 best solutions below

2
On

Considering the first order derivative, use Taylor series built at $h=0$ $$f(x+nh)=f(x)+h n f'(x)+\frac{1}{2} h^2 n^2 f''(x)+\frac{1}{6} h^3 n^3 f^{(3)}(x)+O\left(h^4\right)$$ Now, write $$a f(x)+b f(x+h)+c f(x+2h)= (a+b+c)f(x)+h (b+2 c) f'(x)+\frac{1}{2} h^2 (b+4 c) f''(x)+\frac{1}{6} h^3 (b+8 c) f'''(x)+O\left(h^4\right)$$ Then the equations are $$a+b+c=0$$ $$b+2c=1$$ $$b+4c=0$$ leading to $a=-\frac 32$, $b=2$, $c=-\frac 12$. So $$-\frac 32 f(x)+2f(x+h)-\frac 12 f(x+2h)=h f'(x)-\frac{1}{3} h^3 f'''(x)+O\left(h^4\right)$$ $$\frac{-\frac 32 f(x)+2f(x+h)-\frac 12 f(x+2h)} h=f'(x)-\frac{1}{3} h^2 f'''(x)+O\left(h^3\right)=f'(x)+O\left(h^2\right)$$

Using the same process for the second order derivative, the equations would be $$a+b+c=0$$ $$b+2c=0$$ $$b+4c=1$$ leading to $a=\frac 12$, $b=-1$, $c=\frac 12$. So $$\frac 12 f(x)-2f(x+h)+\frac 12 f(x+2h)=\frac{1}{2} h^2 f''(x)+\frac{1}{2} h^3 f^{(3)}(x)+O\left(h^4\right)$$ $$\frac{ \frac 12 f(x)-2f(x+h)+\frac 12 f(x+2h)} {h^2}=\frac{f''(x)}{2}+\frac{1}{2} h f^{(3)}(x)+O\left(h^2\right)$$