Solved

Please help to merge these two matlab programs

Posted on 2009-03-30
2
323 Views
Last Modified: 2016-02-10
Totally new to Matlab here so your help would be greatly appreciated
I have done two related matlab programs below. one is a hyperbola and the other is the elipse. How can I get the two of these as just one .m program. I want the elipse to be in the middle of the hyperbola.

thanks in advance.
% 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 (why 1001?)

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

% Add axes

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
 

clear

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 (why 1001?)

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 elipse

axis([-xmax xmax -ymax ymax]) % specify axis limits

xlabel('x')

ylabel('y')

title([elipse$y^2/a^2 + x^2/b^2 = 1$; $a$ = ', num2str(a), ...

', $b$ = ', num2str(b),'; (WR 1/21/08)'],'Interpreter','latex')

% Add axes

plot([0 0],[-ymax ymax],'k') % y axis (black line - k)

plot([-xmax xmax],[0 0],'k') % x axis

Open in new window

0
Comment
Question by:jtiernan2008
2 Comments
 
LVL 15

Accepted Solution

by:
yuk99 earned 500 total points
ID: 24022109
Just comment (or delete) lines 28 to 33.

And don't forget to change the title.
0
 
LVL 1

Author Closing Comment

by:jtiernan2008
ID: 31597470
thanks a million
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with my python script 6 154
bigDiff challenge 17 84
zeroMAx challenge 20 88
bunnyEars challenge 6 103
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now