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 回表示 (過去 30 日間)
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 件のコメント
sogol bandekian
sogol bandekian 2022 年 5 月 23 日
but they are not optimization solvers like fminsearch.are not they?
Torsten
Torsten 2022 年 5 月 23 日
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).

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2022 年 5 月 22 日
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 件のコメント
Walter Roberson
Walter Roberson 2022 年 5 月 24 日
x = 0:0.2:1;
y = 0:0.2:1;
[X,Y] = meshgrid(x,y);
Z = 2.*X.^3+Y.^3-3.*X.^2-12.*X-3.*Y;
Z = Z + (-0.1+0.2*rand(size(Z)));
fun = @(x)interp2(X,Y,Z,x(1),x(2), 'spline');
fun2 = @(x)-fun(x);
options = optimset('Display','iter','PlotFcns',@optimplotfval);
x0=[x(1),y(1)]
lb = [min(x), min(y)];
ub = [max(x), max(y)];
[xmin,fvalmin] = fmincon(fun, x0, [], [], [], [], lb, ub, [], options); %min
[xmax,fvalmax]= fmincon(fun2, x0, [], [], [], [], lb, ub, [], options); %max
fvalmax = -fvalmax;
surf(X, Y, Z, 'edgecolor', 'none')
hold on
plot3(xmin(1), xmin(2), fvalmin, 'rv')
plot3(xmax(1), xmax(2), fvalmax, 'r^')
hold off

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMonte Carlo Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by