How to plot x^2 - y^2 = 1?

 Accepted Answer

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

8 Comments

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
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
As always, our pleasure!
John — Thank you!
little sidenote: what if I want to express <1 ?
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;
.
looks pretty funky, thank you!
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?

Sign in to comment.

More Answers (1)

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;

Categories

Products

Tags

Community Treasure Hunt

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

Start Hunting!