How to find the x, y range of values for a multivariable function using optimization?

조회 수: 7 (최근 30일)
Haider
Haider 2022년 12월 14일
편집: Sam Chak 2022년 12월 15일
I'm trying to solve this question by giving a range for x and y specified by me as the following:
x = -5:0.1:5; y = -5:0.1:5;
[x, y] = meshgrid(x, y);
z = 1-(exp(-((x.^2)+(y.^2))) + (((x.^2)+(y.^2))/20));
surf(x, y, z);
but I'm having a problem finding the global minimum when I use:
z = @(x) 1-(exp(-((x(1).^2)+(x(2).^2))) + (((x(1).^2)+(x(2).^2))/20));
Gmin = fminsearch(z, [-5 -5]);
The problem is that the function exits with a message:
Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
Current function value: -13541624843901191000000000000000000000000000000000000000000000000000000000000000000000000.000000
and the results are:
1.0e+44
-5.1163 -0.9523
When I asked the professor about it, he told me that I have to find the correct range of x,y using optimization but i didn't quite understand what does he mean. So what should I do? Is there a function that I can use to get the correct range?
  댓글 수: 5
Haider
Haider 2022년 12월 14일
Not global optimization? then what did he mean by using optimization to find the range of x, y? I remember him saying something like that we have to find the range that makes the function zero or approaches zero but didn't quite understand him but I thought about the function fzero but it only works with single-variable functions as far as I know. (sorry If what I'm saying isn't correct or doesn't make any sense but I'm totally lost in this question).
Torsten
Torsten 2022년 12월 14일
편집: Torsten 2022년 12월 14일
I think it does not need a mathematical proof that your function tends to -Inf as abs(x), abs(y) tend to Inf.
So the global infimum of the function is -Inf.
But I'm quite sure that the error in the assignment is the sign I already mentionned. It should read
f(x,y) = 1 + (exp(-(x^2+y^2)) + (x^2+y^2)/20)
instead of
f(x,y) = 1 - (exp(-(x^2+y^2)) + (x^2+y^2)/20)
Or you should be told to maximize
f(x,y) = 1 - (exp(-(x^2+y^2)) + (x^2+y^2)/20)
instead of minimize it.

댓글을 달려면 로그인하십시오.

답변 (1개)

Sam Chak
Sam Chak 2022년 12월 15일
편집: Sam Chak 2022년 12월 15일
It is probably best to show your professor these plots and asks for guidance. A picture is worth a thousand words; two pictures are worth a million words. Sometimes, assignments and exam papers contain typos.
With educated guess and the structure of the function is clearly known, you can justify whether global minima or maxima of the function exist.
x = -5:0.1:5;
y = -5:0.1:5;
[x, y] = meshgrid(x, y);
z = 1 - (exp(-((x.^2) + (y.^2))) + (((x.^2) + (y.^2))/20));
figure(1)
surf(x, y, z, 'FaceColor', 'interp', 'EdgeColor', 'none', 'FaceLighting', 'gouraud');
fun = @(x) - (1 - (exp(-((x(1).^2) + (x(2).^2))) + (((x(1).^2) + (x(2).^2))/20)));
[Gmax, fval] = fminsearch(fun, [2 2])
Gmax = 1×2
1.2765 1.1689
fval = -0.8002
Now, look at the underside of the surface. The local minimum exists at the origin .
figure(2)
surf(x, y, z, 'FaceColor', 'interp', 'EdgeColor', 'none', 'FaceLighting', 'gouraud');
view(70, -40)
  댓글 수: 2
Haider
Haider 2022년 12월 15일
Hello Sam, so from what I understood from you, there should be a typo in the assignment just like what maybe 5 people also told me. And for this function there's no global minimum? Also how can I specify a range for x and y? Why did you make the range from -5 to 5? Did you use any function or method to find the best range of values for this function or did you choose those values because you wanted to? The prof. told us that we have to find the range of x, y values for this function so I don't think that I can pick any range I want ain't I right?
Thanks.
Sam Chak
Sam Chak 2022년 12월 15일
편집: Sam Chak 2022년 12월 15일
Hi @Haider, I used your MATLAB code. However, you can seek for clarity from the professor.
Mathematics and graphs speak louder than words. But you must save the professor's face.
Show these two plot and asks about the purpose of finding the range (which is not officially specified in the assignment). Ask if this is an optimization problem or a range-finding problem (for some unspecified purposes).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by