## I need to plot hyperbolas with ellipses

Luis Miguel López Santamaría

### Luis Miguel López Santamaría (view profile)

님이 질문을 제출함. 30 Oct 2019
최근 활동 John D'Errico

### John D'Errico (view profile)

님이 댓글을 추가함. 30 Oct 2019
Hello I need to plot the next figure: I already plot the ellipses but I don't know how to plot the hyperbolas. I have the next piece of code which plot the ellipses:
R = {1, 3, 5, 7};
t=0:0.0001:10;
for i=1:length(R)
x = 2*R{i}*sin(2*pi*t);
y = R{i}*cos(2*pi*t);
hold on;
plot(x,y);
axis equal;
grid on;
end

John D'Errico

### John D'Errico (view profile)

on 30 Oct 2019
I do need to laugh, just a bit. I see these lines:
t=0:0.0001:10;
...
x = 2*R{i}*sin(2*pi*t);
y = R{i}*cos(2*pi*t);
I have a very funny feeling that you have no idea that this plots 10 ellipses, right on top of each other? Or, perhaps I should say that it plots the same ellipse, 10 times on top of itself.
The functions sin(2*pi*t) (and cos too) are periodic on the interval [0,2*pi]. So you are plotting the same line, 10 times, since you are going all the way out to 2*pi*30.
t needs to go out only as far as 1 at the top end, NOT 10, and you will get the same result.

로그인 to comment.

R2018b

## 답변 수: 1

### John D'Errico (view profile)

on 30 Oct 2019
Edited by John D'Errico

### John D'Errico (view profile)

on 30 Oct 2019

Well, first, you need to write down the equation for the hyperbola. Seems silly, or maybe obvious, but you can't do anything without an equation. And we cannot tell you what the equation of a hyperbola is, when we are not given the equation. The mind reading toolbox is just too buggy still.
Then it is simplest to just use fimplicit. For example...
fun = @(x,y) x.^2 - y.^2 + x.*y + 2
fimplicit(fun)
You could as easily have used fimplicit to plot the ellipses too, but who cares what vehicle you use to get where you need to go?

로그인 to comment.