After computing the gradient of z along the entire computational grid, I want to calculate Z0=Z(X0,Y0) and gradient(Z0) using cubic interpolation. I'm unsure of the best way to do this but it is essential that X0 and Y0 are set outside of the function. They are coordinates of an arbitrary starting point to begin the Gradient Descent algorithm.
Below is the problem part of my code with some attempted statements:
function [xi, yi, Z] = gradient_descent2(Z,X0,Y0,gamma,tau)
x = -9:0.2:9;
y = -8:0.2:8;
[Xg, Yg] = meshgrid(x,y);
[px,py] = gradient(Z);
Z0 = griddata(Xg,Yg,Z,X0,Y0,'cubic');
t = (x == X0) & (y == Y0);
indt = find(t);
Z0_grad = [px0(indt) py0(indt)];
This is supposed to be a function that implements a 2D Gradient Descent method. x, y & z are related as follows:
and is computed outside the function.