I would like to know how I could plot a hyperbolic function of x and y.

3 views (last 30 days)
I was recently given an assignment for my intro to LaTeX class where I needed to plot the given function: x^(2)/9 - y^(2)/4 = 1. I know that this function is a hyperbola, but I can't seem to get it to work properly. The assignment also asked us to generate a list of no more than 6 values to test. I used the linspace function to come up with an evenly spaced matrix for my x values. This is my code:
function graph_1
clear;
x = linspace(-10,10);
y1 = (2*sqrt(x.^(2)/9)/3);
y2 = -(2*sqrt(x.^(2)/9)/3);
figure(1); clf;
plot(y1, y2, 'b')
set(gca, 'fontsize', 12)
title('(x^2)/9 - (y^2)/4 = 1')
grid on
print(figure(1), '-dpng') % They also asked that we save the figure in documents and then use LaTeX to reference it later.
end
  2 Comments
John D'Errico
John D'Errico on 25 Oct 2020
Edited: John D'Errico on 25 Oct 2020
Do you see that these lines:
y1 = (2*sqrt(x.^(2)/9)/3);
y2 = -(2*sqrt(x.^(2)/9)/3);
do NOT allow you to solve that equation fot y? They simply do not correspond to the equation of the hyperbola you have given us. So try again. Basic algebra here, no question about MATLAB.
So write the equation on paper, and solve for y.
Oh, by the way, if you were asked to generate no MORE than 6 points, why would use use 21 points on that curve?
Mehmet Arslan
Mehmet Arslan on 26 Oct 2020
I fixed my code, and managed to get the hyperbola plotted correctly using fimplicit. I think I mistyped, the assignment was asking to test no less than 6 x-values, which is what I thought I was doing.

Sign in to comment.

Accepted Answer

Mehmet Arslan
Mehmet Arslan on 26 Oct 2020
Edited: Mehmet Arslan on 26 Oct 2020
To graph a hyperbola, I used the fimplicit function. The fimplicit by default uses the values between [-5,5] for both variables.
function hyperbola
clc; clear;
f1 = @(x,y) x.^(2)/9 - y.^(2)/4 - 1; % As long as you have the original equation for your hyperbola.
fimplicit(f1, 'b');
grid on;
title('x^2/9 - y^2/4 = 1')
xlabel('X')
ylabel('Y')
xticklabels({-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}) % To clearly illustrate where the hyperbola crosses the x-axis.
print(figure(1), '-dpng')
end

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!