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

15 次查看(过去 30 天)
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 个)

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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Classical Control Design 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by