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 Center および File ExchangeSurrogate Optimization についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by