I need to plot hyperbolas with ellipses

조회 수: 6 (최근 30일)
Luis Miguel López Santamaría
Luis Miguel López Santamaría 2019년 10월 30일
댓글: John D'Errico 2019년 10월 30일
Hello I need to plot the next figure:
Captura.PNG
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
  댓글 수: 1
John D'Errico
John D'Errico 2019년 10월 30일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

John D'Errico
John D'Errico 2019년 10월 30일
편집: John D'Errico 2019년 10월 30일
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?

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by