MATLAB Answers

I need to plot hyperbolas with ellipses

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

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

Answer by John D'Errico
on 30 Oct 2019
Edited by John D'Errico
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?

  댓글 수: 0

로그인 to comment.



Translated by