I tried to show effect of uncertain parameters on bi-variate function with color map and aslo highlight changes to max and min,I am not sure the function I wrote is right!!!

1 view (last 30 days)
for i=1:length(x)
x=lhsdesign(10,1,"iterations",2);
for j=1:length(y)
y=lhsnorm(50,10,10,"on");
Z=[x,y];
Z(i,j)=2.*x(i).^3+y(j).^3-3.*x(i).^2-12.*x(i)-3.*y(j);
end
end
options = optimset('Display','iter','PlotFcns',@optimplotfval);
x0=[x(1),y(1)]
[xmin,fval]=fminsearch(@(xy)Z(xy(1),xy(2)),x0,options); %min
[xmax ,fval]=fminsearch(@(xy) -1 *Z(xy(1),xy(2)),x0,options); %max
[X,Y]=meshgrid(x,y);
surf(X,Y,Z(i,j),'EdgeColor',"interp","FaceAlpha",0.5);
hold on
plot(xmin(1),xmin(2), f(xmin(1),xmin(2)),'MarkerSize',6);
hold on
plot(xmax(1),xmax(2), f(xmax(1),xmax(2)),'MarkerSize',6);
hold off
xlabel("optimum valeus for x")
ylabel("optimum valeus for y")
colormap(parula(6));%default colormap with 6 colors
colorbar
can anyone help me for correcting this function?
  11 Comments
Torsten
Torsten on 23 May 2022
No. It's a search for a minimum or maximum of a functrion on a discrete set of (x/y) values. The function is evaluated on a (fine enough) grid and the point where this evaluation is minimal (or maximal) is taken as the minimum (or maximum) of the function. It's an alternative to fminsearch and other optimizers if the region where minimum (or maximum) is is approximately known and if the function is badly behaved (not differentiable etc).

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 22 May 2022
y=lhsnorm(50,10,10,"on");
[xmin,fval]=fminsearch(@(x)Z(x,y),x0,options) %min
The y referred to there is being "captured" from the workspace variable y which is the lhsnorm that you defined earlier.
With y being non-scalar, your multinomial Z function is going to return multiple values for each input x value, but for fminsearch you need to return a vector.
Perhaps what you need is
[xmin,fval]=fminsearch(@(xy)Z(xy(1),xy(2)),x0,options) %min
  9 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by