Hi All,
Ive writen this function that computes the gradient vector for a function, but it only gives me a single value output. What am I doing wrong?
gradlandscape(3, 3);function [retx, rety] = gradlandscape(x, y)h = 0.1;retx = (landscape(x+h, y)-landscape(x-h, y))/(2*h);rety = (landscape(x, y+h)-landscape(x, y-h))/(2*h); function M = landscape(x, y) M = H1(x, y) + H2(x, y); function h1 = H1(x, y) R1 = 2; s1 = [-2;2]; n1 = 2; h1 = (1./(1+(R1./sqrt((x-s1(1)).^2+(y(:)-s1(2)).^2)).^n1)); end function h2 = H2(x, y) R2 = 1; s2 = [3;-1]; n2 = 1; h2 = (1./(1+(R2./sqrt((x-s2(1)).^2+(y(:)-s2(2)).^2)).^n2)); end endend
Best Answer