plot (X^2/cosh^2(v))+(y^2/sinh^2(v))=1
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Walter Roberson
2015년 11월 15일
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
Ali Kareem
2015년 11월 15일
Walter Roberson
2015년 11월 15일
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.
카테고리
도움말 센터 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!)%20(y'2%E2%80%8B%C3%B7sinh2(v)%E2%80%8B)-1%20-%202015%2011%2014.png)
