필터 지우기
필터 지우기

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
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 CenterFile Exchange에서 Monte Carlo Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by