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

65 views (last 30 days)
Niklas Kurz on 14 Nov 2020
Commented: Star Strider on 16 Nov 2020
Very simple question to understand I think.

Star Strider on 14 Nov 2020
Try this:
syms x y
figure
fimplicit(x^2 + y^2 -1, [-1 1])
axis('equal')
.

Star Strider on 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 on 16 Nov 2020
looks pretty funky, thank you!
Star Strider on 16 Nov 2020
As always, my pleasure!
Note that ‘<1’ includes everything from infinitesimally less than +1 to -Inf.

Image Analyst on 14 Nov 2020
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;