Take a random set of coordinates (x, y, z) that will become the center of my 3x3x3 matrix (also consider a local minimum). I have a J function that takes these coordinates, performs calculations, and returns me a number. If any of these 26 points is less, this will become the focus for my next matrix. In case I do not find a smaller value, the radius of the matrix increases by 1, and we start the cycle again. My question is: how to quote only through the "shell" of the cube and not call the function for previously checked values?
I tried to illustrate this below (this is in 2d here, but you understand). Dots are those values ββthat have been checked, "?" these are the ones that need to be calculated and compared with the local minimum.

here is the code
minim=100; %%the initial size of the search matrix 2*level +1 level=1; x=input('Enter the starting coordinate for X : '); y=input('Enter the starting coordinate for Y : '); z=input('Enter the starting coordinate for Z : '); %%The loop if(level<=10) for m=x-level:x+level for n=y-level:y+level for p=z-level:z+level A(m,n,p)=J(m,n,p); if A(m,n,p)<minim minim=A(m,n,p); x=m;y=n;z=p; level=1; else level=level+1; %<<----shell loop here ---->> end end end end else %Display global min display(minim, 'Minim'); %Coordinates of the global min [r,c,d] = ind2sub(size(A),find(A ==minim)); display(r,'X'); display(c,'Y'); display(d,'Z'); end
source share