plot (X^2/cosh^​2(v))+(y^2​/sinh^2(v)​)=1

9 visualizaciones (últimos 30 días)
Ali Kareem
Ali Kareem el 15 de Nov. de 2015
Comentada: Walter Roberson el 15 de Nov. de 2015
Hi,
How I can plot this function as v= constant such as for
v=0,pi/2,and pi
(X^2/cosh^2(v))+(y^2/sinh^2(v))=1
Thanks

Respuesta aceptada

Star Strider
Star Strider el 15 de Nov. de 2015

One option (if I understood your Question correctly):

v = pi/2;
f = @(X,Y) (X.^2./cosh(v).^2)+(Y.^2./sinh(v).^2)-1;
x = linspace(-5, 5, 50);
[X,Y] = meshgrid(x);
figure(1)
surf(X, Y, f(X,Y))
grid on
xlabel('X')
ylabel('Y')
title('v = ^{\pi}/_2')
  4 comentarios
Ali Kareem
Ali Kareem el 15 de Nov. de 2015
Hi,
Then how I can combine all plots in one? for different Vs
Regards
Star Strider
Star Strider el 15 de Nov. de 2015
My pleasure.
Use the subplot function. That will plot them in different axes in the same figure. I would not combine all plots in the same axes with surface plots. Try something like this:
f = @(X,Y,v) (X.^2./cosh(v).^2)+(Y.^2./sinh(v).^2)-1;
x = linspace(-5, 5, 50);
[X,Y] = meshgrid(x);
figure(1)
subplot(3,1,1)
surf(X, Y, f(X,Y,0))
xlabel('X')
ylabel('Y')
title('v = 0')
grid on
subplot(3,1,2)
surf(X, Y, f(X,Y,pi/2))
xlabel('X')
ylabel('Y')
title('v = ^{\pi}/_2')
grid on
subplot(3,1,3)
surf(X, Y, f(X,Y,pi))
xlabel('X')
ylabel('Y')
title('v = pi')
grid on
That should work.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 15 de Nov. de 2015
v = [0, pi/2, pi];
for K = 1 : length(v)
f = @(X,y) (X.^2/cosh(v(K))^2) + (y.^2/sinh(v(K))^2) - 1;
figure
ezplot(f, [-15 15])
title(sprintf('v = %g', v(K)));
end
You might note that the v = 0 case comes out blank. That is because sinh(0) is 0 so you have a division by 0, which is going to be infinity (except at y=0 where you have 0/0 which is undefined)
  2 comentarios
Ali Kareem
Ali Kareem el 15 de Nov. de 2015
Thank you for your reply. I tried this code but it is not combine all plot in one diagram.
Regars
Walter Roberson
Walter Roberson el 15 de Nov. de 2015
v = [0, pi/2, pi];
linecolortab = hsv(length(v)); %choose different colors
for K = 1 : length(v)
f = @(X,y) (X.^2/cosh(v(K))^2) + (y.^2/sinh(v(K))^2) - 1;
h(K) = ezplot(f, [-15 15]);
hold on
L{K} = sprintf('v = %.3f', v(K));
try
set(h(K), 'LineColor', linecolortab(K,:));
catch ME
end
end
legend(h, L)
hold off
You will notice that there is a legend entry for v = 0 but there is no corresponding line. This is due to sinh(0) introducing a division by 0 so there is no plot for v = 0.
The colors used for the lines will automatically change if you add or remove values for v.
Technical note:
In R2014a (and probably several releases before that, but might have changed in R2014b), the output of ezplot is a hggroup that includes a LineColor property that can be set. However, there is a listener on the handle that triggers an "Index exceeds matrix dimensions" within scribe.legend/methods>layout_legend_items when the property is set, but does so after setting the property. If the command is repeated, the error does not trigger. The set() will therefore generate an error but will have the desired effect. That is why I put the set() within a try/catch block, so that the stray error message is ignored.

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by