Respuesta aceptada

Star Strider
Star Strider el 14 de Nov. de 2020

2 votos

Try this:
syms x y
figure
fimplicit(x^2 + y^2 -1, [-1 1])
axis('equal')
.

8 comentarios

John D'Errico
John D'Errico el 14 de Nov. de 2020
Editada: John D'Errico el 14 de Nov. de 2020
I note that your example has the wrong sign on the y^2 term, which is irrelevant, since your example is perfectly valid. Regardless, fimplicit does not need syms. Just define a function handle.
fun = @(x,y) x.^2 - y.^2 - 1;
fimplicit(fun)
axis equal
grid on
Niklas Kurz
Niklas Kurz el 15 de Nov. de 2020
thx for the correction.
fimplicit(x^2 + y^2 -1, [-1 1])
gives out a circle, whereas
fun = @(x,y) x.^2 - y.^2 - 1;
fimplicit(fun)
gives out the right hyperbola-formula
Star Strider
Star Strider el 16 de Nov. de 2020
As always, our pleasure!
John — Thank you!
Niklas Kurz
Niklas Kurz el 16 de Nov. de 2020
little sidenote: what if I want to express <1 ?
Star Strider
Star Strider el 16 de Nov. de 2020
That would require the fcontour function, defining the 'LevelList' property to go from the minimum plotted contour to 1:
f = @(x,y) x.^2 - y.^2 - 1;
figure
hfc = fcontour(f, 'Fill','on');
hfc.LevelList = min(hfc.LevelList):1;
The contours would then be from the minimum to 1 in steps of 1 here. You can see what difference this creates by commenting-out the last assignment or creating a second fcontour call with out the 'LevelList' assignment and comparing them.
Another option is to just plot the contours without filling them:
figure
hfc = fcontour(f);
LvL = hfc.LevelList;
hfc.LevelList = min(hfc.LevelList):1;
.
Niklas Kurz
Niklas Kurz el 16 de Nov. de 2020
looks pretty funky, thank you!
Star Strider
Star Strider el 16 de Nov. de 2020
As always, my pleasure!
Note that ‘<1’ includes everything from infinitesimally less than +1 to -Inf.
Niklas Kurz
Niklas Kurz el 3 de Nov. de 2021
Digging this out again, how about ?
A kind of solution would go like:
[x,y] = meshgrid(-4:0.008:4);
u = y;
v = x;
w = zeros(size(u));
D1 = (x.^2+y.^2)>1;
D2 = (x.^2+y.^2)<4;
u(~D1) = NaN;
u(~D2) = NaN;
mesh(u,v,w)
But are there other ones, for instance with the aid of a countour plot?

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 14 de Nov. de 2020

1 voto

Try this:
% x^2 - y^2 = 1
% Or y = sqrt(x^2 - 1)
x = linspace(-2, 2, 1000);
y = sqrt(x .^ 2 - 1);
plot(x, y, 'b-', 'LineWidth', 2);
title('y = sqrt(x .^ 2 - 1)', 'FontSize', 15, 'Interpreter', 'none');
xlabel('x', 'FontSize', 15);
ylabel('y', 'FontSize', 15);
grid on;

Categorías

Más información sobre Contour Plots en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 14 de Nov. de 2020

Comentada:

el 3 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by