% Program to plot the hyperbola
% y^2/a^2 - x^2/b^2 = 1
% The hyperbolae are open up/down, so that x is the independent variable
% for plotting. (Using the form x^2/a^2 - y^2/b^2 = 1 requires that y be
% the independent variable, which is awkward programming-wise.)
clear % all variables
figure(1), hold off % start a new figure
set(gca,'FontSize',14) % adjust fontsize
xmax = 30; ymax = 20;
x = linspace(-xmax,xmax,1001); % array of x values for plot : This function generates vector with 1001 points equally distributed between -xmax and xmax.
%1001 is probably to have 500 points on one side (>0), 500 on another side (<0) and to include 0 itself. So you will have
%more natural numbers.
a = 5; b = 3;
y=sqrt(((x.^2)./(b^2)+1).*a^2); % corresponding y values
plot(x,y)
hold on % add to current plot
plot(x,-y) % Plot other half of hyperbola
% plot the elipse
% y^2/a^2 - x^2/b^2 = 1
y=sqrt(((-x.^2)./(b^2)+1).*a^2); % corresponding y values
plot(x,y)
plot(x,-y) % Plot other half of elipse
axis([-xmax xmax -ymax ymax]) % specify axis limits
xlabel('x')
ylabel('y')
title(['Hyperbola and elipse $y^2/a^2 - x^2/b^2 = 1$;$y^2/a^2 + x^2/b^2 = 1$; $a$ = ', num2str(a), ...
', $b$ = ', num2str(b),';'],'Interpreter','latex')
% Add axes
plot([0 0],[-ymax ymax],'k') % y axis (black line - k)
plot([-xmax xmax],[0 0],'k') % x axis
f1=sqrt(a.^2+b.^2);
f2=-(sqrt(a.^2+b.^2));
plot([0 0],[f1 f2],'.')
text(0,f1,'\leftarrow +d','VerticalAlignment','middle','HorizontalAlignment','left')
text(0,f2,'\leftarrow -d','VerticalAlignment','middle','HorizontalAlignment','left')
f3=sqrt(a.^2-b.^2);
f4=-(sqrt(a.^2-b.^2));
plot([0 0],[f3 f4],'.')
text(0,f3,'\leftarrow +c','VerticalAlignment','middle','HorizontalAlignment','left')
text(0,f4,'\leftarrow -c','VerticalAlignment','middle','HorizontalAlignment','left')
text(0,a, '\leftarrow +a')
text(0,-a, '\leftarrow -a')
function [xout,yout] = xfm1(xin,yin,theta,x_offset,y_offset)
% Program to rotate and translate x,y values from x",y" to x,y space.
% Written to plot hyperbolas for time of arrival code.
% theta value assumed to be in radians.
% rotation matrix
xfm = [cos(theta) sin(theta); ...
-sin(theta) cos(theta)];
% make x,y values into a column vector
r_in = [xin; yin];
% rotate
r_out = xfm*r_in;
x = r_out(1,:); y = r_out(2,:);
xout = x + x_offset;
yout = y + y_offset;
theta=1; % in radians, 1 radian = 180/pi degrees
xoff=0;
yoff=0;
[xout,yout] = xfm1(x,y,theta,xoff,yoff);
plot(xout,yout)
% Program to plot the hyperbola
% y^2/a^2 - x^2/b^2 = 1
% The hyperbolae are open up/down, so that x is the independent variable
% for plotting. (Using the form x^2/a^2 - y^2/b^2 = 1 requires that y be
% the independent variable, which is awkward programming-wise.)
clear % all variables
figure(1), hold off % start a new figure
set(gca,'FontSize',14) % adjust fontsize
xmax = 30; ymax = 20;
x = linspace(-xmax,xmax,1001); % array of x values for plot : This function generates vector with 1001 points equally distributed between -xmax and xmax.
%1001 is probably to have 500 points on one side (>0), 500 on another side (<0) and to include 0 itself. So you will have
%more natural numbers.
a = 5; b = 3;
y=sqrt(((x.^2)./(b^2)+1).*a^2); % corresponding y values
plot(x,y)
hold on % add to current plot
plot(x,-y) % Plot other half of hyperbola
% plot the elipse
% y^2/a^2 - x^2/b^2 = 1
y=sqrt(((-x.^2)./(b^2)+1).*a^2); % corresponding y values
plot(x,y)
plot(x,-y) % Plot other half of elipse
axis([-xmax xmax -ymax ymax]) % specify axis limits
xlabel('x')
ylabel('y')
title(['Hyperbola and elipse $y^2/a^2 - x^2/b^2 = 1$;$y^2/a^2 + x^2/b^2 = 1$; $a$ = ', num2str(a), ...
', $b$ = ', num2str(b),';'],'Interpreter','latex')
% Add axes
plot([0 0],[-ymax ymax],'k') % y axis (black line - k)
plot([-xmax xmax],[0 0],'k') % x axis
f1=sqrt(a.^2+b.^2);
f2=-(sqrt(a.^2+b.^2));
plot([0 0],[f1 f2],'.')
text(0,f1,'\leftarrow +d','VerticalAlignment','middle','HorizontalAlignment','left')
text(0,f2,'\leftarrow -d','VerticalAlignment','middle','HorizontalAlignment','left')
x1=10;
y1=sqrt(((x1.^2)./(b^2)+1).*a^2);
line([0 x1], [f1 y1],'color','r')
line([0 x1], [f2 y1],'color','r')
f3=sqrt(a.^2-b.^2);
f4=-(sqrt(a.^2-b.^2));
plot([0 0],[f3 f4],'.')
text(0,f3,'\leftarrow +c','VerticalAlignment','middle','HorizontalAlignment','left')
text(0,f4,'\leftarrow -c','VerticalAlignment','middle','HorizontalAlignment','left')
text(0,a, '\leftarrow +a')
text(0,-a, '\leftarrow -a')
theta=1; % in radians, 1 radian = 180/pi degrees
xoff=0;
yoff=0;
[xout,yout] = xfm1(x,y,theta,xoff,yoff);
plot(xout,yout)
clear % all variables
figure(1), hold off % start a new figure
set(gca,'FontSize',14) % adjust fontsize
xmax = 30; ymax = 20;
x = linspace(-xmax,xmax,1001);
a = 5; b = 3;
theta=60*pi/180; % in radians, 1 radian = 180/pi degrees
xoff=10;
yoff=5;
y=sqrt(((x.^2)./(b^2)+1).*a^2); % corresponding y values
[xout,yout] = xfm1(x,y,theta,xoff,yoff); % rotation and shift
plot(xout,yout)
hold on % add to current plot
[xout,yout] = xfm1(x,-y,theta,xoff,yoff); % rotation and shift of negative part
plot(xout,yout) % Plot other half of hyperbola
axis([-xmax xmax -ymax ymax]) % specify axis limits
xlabel('x')
ylabel('y')
% Add axes
plot([0 0],[-ymax ymax],'k') % y axis
plot([-xmax xmax],[0 0],'k') % x axis
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Setup specific permissions in Microsoft Access | 9 | 57 | |
tenRun challenge | 28 | 101 | |
firstChar challenge | 13 | 115 | |
What language/protocol is the Angular Chat? | 2 | 77 |
Join the community of 500,000 technology professionals and ask your questions.