I need to plot hyperbolas with ellipses

6 次查看(过去 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 中查找有关 Entering Commands 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by