I need to plot hyperbolas with ellipses

3 ビュー (過去 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 Center および File ExchangeLine Plots についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by