How to plot a set as the constraint in 2D?

조회 수: 5 (최근 30일)
Nasim
Nasim 2022년 4월 2일
댓글: Nasim 2022년 4월 2일
Hello All,
I want to find the optimal solution to an optimization problem in 2D by plotting the constrain set. The constraint sets are
and . I need to plot this area in 2D. I know that using meshgrid and surf does not do what I need. I tried the following piece of code after doing some searching on the similar questions.
syms x y
f(x, y) = sqrt(x^2+y^2 );
ezplot(f, [0, 10,0 10]
However, this method does not work as well. I would appreciate it if any one can help with this problem.

채택된 답변

John D'Errico
John D'Errico 2022년 4월 2일
편집: John D'Errico 2022년 4월 2일
Think clearly about what you are asking to plot.
sqrt(x1^2 + x2^2) < x1
Do you agree that x2^2 is ALWAYS a positive number, as long as x2 is real? In that case, is it true that x1^2 + x2^2 is ALWAYS strictly greater than x1^2, unless x2 is zero, in which case you just get x1^2?
Next, look at sqrt(x1^2 + x2^2). I just essentially proved that is is NEVER less than sqrt(x1^2). Do you understand that?
And what is sqrt(x1^2)? Yep. x1. well, unless you take the negative branch of the sqrt. But since you did not say that, then you have to recognize that
sqrt(x1^2+ x2^2) >= x1
But you are asking to plot the set of values for x1 and x2, that yield a result where EXACTLY the opposite happens. So the ONLY valid solution locus to your equations comes from the fairly limited set:
x2 == 0
x1 >= 0
That is, x2 MUST be EXACTLY zero.
Again, all of this applies IF you are taking the positive branch of the square root function. Since you never said differently, that is what I must assume.
But if you allow the negative branch of the square root, then ANY values of x and y will yield a valid solution, as long as x1>=0 and x2>-=0.
It is a pretty boring solution locus
  댓글 수: 1
Nasim
Nasim 2022년 4월 2일
Thank you! that makes a lot of sense! I had think deeper about the question!

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

추가 답변 (1개)

Torsten
Torsten 2022년 4월 2일
syms x y
f = sqrt(x^2+y^2);
ezplot(f, [0 10 0 10])
  댓글 수: 3
Torsten
Torsten 2022년 4월 2일
편집: Torsten 2022년 4월 2일
I think you mean
fimplicit(@(x,y) sqrt(x.^2 + y.^2) - x,[-10 10 0 10])
You'll get x = [-10 10], y = 0 as result.
Nasim
Nasim 2022년 4월 2일
Thank you!

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

카테고리

Help CenterFile Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by