function [ x_curr,y_curr,x_hist,y_hist,z_hist ] = SteepestDescent_Random( x_curr,y_curr,z_curr,z,x_hist,y_hist,z_hist ) %UNTITLED3 Summary of this function goes here % Detailed explanation goes here for i = 1:500 %Check our surrounding area checkArea = [z(x_curr-1,y_curr+1), z(x_curr,y_curr+1), z(x_curr+1,y_curr+1); z(x_curr-1,y_curr), z(x_curr,y_curr), z(x_curr+1,y_curr); z(x_curr-1,y_curr-1), z(x_curr,y_curr-1), z(x_curr+1,y_curr-1)] - z_curr; %Find position of smallest element [a,b] = min(checkArea); [a2,b2] = min(a); %Define increments based on position of smallest element %With 60% probability use the steepest option %With 40% probability just #YOLO it if round(rand-0.1) x_inc = (b2-2); y_inc = -(b(b2)-2); else %Random walk (i.e. equal probability of +1 / 0 / -1 x_inc = round(3*rand()-1.5); y_inc = round(3*rand()-1.5); end %Update current position by incrementing x & y %Implement bounds so that we just run up against a corner if we run out %of room x_curr = min(99,max(2,x_curr + x_inc)); y_curr = min(99,max(2,y_curr + y_inc)); %Update current height z_curr = z(x_curr,y_curr); %Update history x_hist = [x_hist,x_curr]; y_hist = [y_hist,y_curr]; z_hist = [z_hist,z_curr]; end end