Réponse acceptée

Star Strider
Star Strider le 14 Nov 2020

2 votes

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

8 commentaires

John D'Errico
John D'Errico le 14 Nov 2020
Modifié(e) : John D'Errico le 14 Nov 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 le 15 Nov 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 le 16 Nov 2020
As always, our pleasure!
John — Thank you!
Niklas Kurz
Niklas Kurz le 16 Nov 2020
little sidenote: what if I want to express <1 ?
Star Strider
Star Strider le 16 Nov 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 le 16 Nov 2020
looks pretty funky, thank you!
Star Strider
Star Strider le 16 Nov 2020
As always, my pleasure!
Note that ‘<1’ includes everything from infinitesimally less than +1 to -Inf.
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?

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 14 Nov 2020

1 vote

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;

Catégories

En savoir plus sur Contour Plots dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by