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

5 visualizaciones (últimos 30 días)
Nasim
Nasim el 2 de Abr. de 2022
Comentada: Nasim el 2 de Abr. de 2022
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.

Respuesta aceptada

John D'Errico
John D'Errico el 2 de Abr. de 2022
Editada: John D'Errico el 2 de Abr. de 2022
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 comentario
Nasim
Nasim el 2 de Abr. de 2022
Thank you! that makes a lot of sense! I had think deeper about the question!

Iniciar sesión para comentar.

Más respuestas (1)

Torsten
Torsten el 2 de Abr. de 2022
syms x y
f = sqrt(x^2+y^2);
ezplot(f, [0 10 0 10])
  3 comentarios
Torsten
Torsten el 2 de Abr. de 2022
Editada: Torsten el 2 de Abr. de 2022
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 el 2 de Abr. de 2022
Thank you!

Iniciar sesión para comentar.

Categorías

Más información sobre Surrogate Optimization en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by