Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# adding foci points to my hyperbola in Matlab

Posted on 2009-03-30
Medium Priority
973 Views
Please find the matlab code below;

ok... I figured out that my foci points : d=+/- sqrt(a) +sqrt(b)
Is this ok?

and how do I add this to my code below

``````% 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
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
axis([-xmax xmax -ymax ymax]) % specify axis limits
xlabel('x')
ylabel('y')
title(['Hyperbola \$y^2/a^2 - x^2/b^2 = 1\$; \$a\$ = ', num2str(a), ...
', \$b\$ = ', num2str(b),'; (WR 1/21/08)'],'Interpreter','latex')
plot([0 0],[-ymax ymax],'k') % y axis (black line - k)
plot([-xmax xmax],[0 0],'k') % x axis

% Program to 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,real(y))
hold on % add to current plot
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')
plot([0 0],[-ymax ymax],'k') % y axis (black line - k)
plot([-xmax xmax],[0 0],'k') % x axis
``````
0
Question by:jtiernan2008
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3

LVL 15

Expert Comment

ID: 24023169
Are those points at x=0? Then you can add them with
plot([0 0], [-sqrt(a)+sqrt(b) sqrt(a)+sqrt(b)],'o')

Are you sure it's correct? May be this?
plot([0 0], [-sqrt(a^2+b^2) sqrt(a^2+b^2)],'ro')

Or this?
plot([0 0], [-a a],'go')

Please define what are foci points?

0

LVL 1

Author Comment

ID: 24023262
http://mathworld.wolfram.com/Hyperbola.html

foci is focus plural

I actually done as follows.

f1=sqrt((a.^2))+sqrt((b.^2));
f2=-(sqrt((a.^2))+sqrt((b.^2)));
text(0,f1,'\leftarrow +d')
text(0,f2,'\leftarrow -d')

Is this correct?
0

LVL 15

Accepted Solution

yuk99 earned 2000 total points
ID: 24023521
If c^2=a^2+b^2, then c=+-sqrt(a^2+b^2). Is it focus points?

I'd also add VerticalAlignment and HorizontalAlignment to make sure the pointers positions are closest.

``````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')
``````
0

LVL 15

Expert Comment

ID: 24023528
Or f2=-f1;
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to implement Singleton Design Pattern in Java.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
###### Suggested Courses
Course of the Month10 days, 1 hour left to enroll