MATLAB: Partial Derivatives function numerical computing

numerical computingpartial derivatives

So I have the following problem:
There is an equation for B(x,y,z), which I have calculated.
Let's say it's B = [3x.^2 – y.^2 5zy 3xz]
I have taken the partial derivatives as follows using the diff function (as everything is symbolic) and have calculated analytically the partial derivatives.
Gxx = diff(Bx, x)
Gxy = diff(Bx, y)
Gxz = diff(Bx, z)
etc.
What I want to do is create a separate function that will take in (x,y,z) values and spit out the numerical computing of Gxx, Gxy (since the partial derivative analytically has already been calculated).
I have been able to numerically compute using vpa and sub, but I have to put the x,y,z values into the sub function…I wanted something like:
function G = computerDerivatives(x,y,z) that will taken in x,y,z and give me the numerical computing of Gxx, Gxy.
If someone can provide guidance, that will be much appreciated.

Best Answer

function [Gx,Gy,Gz] = computerDerivatives(c,Gxx,Gxy,Gxz)
x=c(1);
y=c(2);
z=c(3);
Gx=subs(Gxx);
Gy=subs(Gxy);
Gz=subs(Gxz);
end