Hey, i want to make an optimization script using the grid search method, this is what i have so far:
syms xsyms yf=input('Write the function in terms of X y Y: ')x1=input ('Write the lower x limit: ' )y1=input ('Write the lower y limit: ')x2=input ('Write the upper x limit: ')y2=input ('Write the upper y limit: ')dx=1000;dy=1000;xi=(x2-x1)/dx;yi=(y2-y1)/dy;max=-10000000;x=x1;for i=0:dx; y=y1; for j=0:dy; f=subs(f,[x,y],[xi,yi]); if f>max max=f; xmax=x; ymax=y; end y=y+yi; end x=x+xi;enddisp('The max value of the function is : ', num2str(max));
But i get the following error:
Conversion to logical from sym is not possible.Error in gsopt (line 18) if f>max
What is wrong with my algorithm? Can you help me?
Thanks in advance.
Best Answer