Discrete approximations to partial derivatives
Andy Long
MAT329

To explain: the difference between := and =

discretepartialx[x_,y_,h_]:=(f[x+h,y]-f[x-h,y])/(2h)
discretepartialy[x_,y_,h_]:=(f[x,y+h]-f[x,y-h])/(2h)
discretepartialxx[x_,y_,h_]:=(f[x+h,y]-2f[x,y]+f[x-h,y])/(2h^2)
discretepartialyy[x_,y_,h_]:=(f[x,y+h]-2f[x,y]+f[x,y-h])/(2h^2)
discretepartialyx[x_,y_,h_,k_]:=(f[x+h,y+k]-(f[x+h,y-k]+f[x-h,y+k])+f[x-h,y-k])/(4h k)

f[x_,y_]:=x y
Plot3D[f[x,y],{x,-2,2},{y,-2,2}]
discretepartialx[0,0,.1]
discretepartialy[0,0,.1]
discretepartialxx[0,0,.1]
discretepartialyy[0,0,.1]
discretepartialyx[0,0,.1,.1]

f[x_,y_]:=x^2+y^2
Plot3D[f[x,y],{x,-2,2},{y,-2,2}]
discretepartialx[0,0,.1]
discretepartialy[0,0,.1]
discretepartialxx[0,0,.1]
discretepartialyy[0,0,.1]
discretepartialyx[0,0,.1,.1]

fx[x_,y_]=D[f[x,y],x];
fy[x_,y_]=D[f[x,y],y];
fxx[x_,y_]=D[fx[x,y],x];
fyy[x_,y_]=D[fy[x,y],y];
fxy[x_,y_]=D[fx[x,y],y];
fyx[x_,y_]=D[fy[x,y],x];
Plot3D[fyx[x,y],{x,-2,2},{y,-2,2}]

f[x_,y_]:=x y
Plot3D[fyx[x,y],{x,-2,2},{y,-2,2}]

fx[x_,y_]=D[f[x,y],x];
fy[x_,y_]=D[f[x,y],y];
fxx[x_,y_]=D[fx[x,y],x];
fyy[x_,y_]=D[fy[x,y],y];
fxy[x_,y_]=D[fx[x,y],y];
fyx[x_,y_]=D[fy[x,y],x];
Plot3D[fyx[x,y],{x,-2,2},{y,-2,2}]

f[x_,y_]:=x y^3-x^2y^2
fx[x_,y_]=D[f[x,y],x];
fy[x_,y_]=D[f[x,y],y];
fxx[x_,y_]=D[fx[x,y],x];
fyy[x_,y_]=D[fy[x,y],y];
fxy[x_,y_]=D[fx[x,y],y];
fyx[x_,y_]=D[fy[x,y],x];
Plot3D[fyx[x,y],{x,-2,2},{y,-2,2}]
Plot3D[discretepartialyx[x,y,.01,.01],{x,-2,2},{y,-2,2}]