필터 지우기
필터 지우기

MATLAB plotting undefined points

조회 수: 4 (최근 30일)
Patrick Faulkner
Patrick Faulkner 2023년 10월 17일
댓글: Patrick Faulkner 2023년 10월 17일
I'm trying to generate plots with trigonometric functions, but MATLAB keeps drawing points that are undefined. In this case, for csc(x), it is generating vertical lines (not simply asymptotes) at all positive multiples of pi.
I have tried modifying my code so it only plots up to pi-0.1, the starts again at pi+0.1. I have gone to several decimals, but this way I can't get asymptotes, only gaps. I'm trying to get functions with the asymptotes and without those undefined points being graphed.
Bad plot:
fairly normal code:

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 10월 17일
An alternative is to use the corresponding numeric functions -
figure
fplot(@csc, [-10 10], 'b')
hold on
fplot(@sin, [-10 10], 'r')
As to the reason, why the output from the symbolic csc function is such, I do not have an explaination at the moment.
And, the plot/behaviour of symbolic csc function with one of the plot interval specified as a multiple of pi is weird -
syms x
figure
%Example taken from the documentation of symbolic csc function
fplot(csc(x),[-4*pi 4*pi],'b')
grid on
  댓글 수: 1
Patrick Faulkner
Patrick Faulkner 2023년 10월 17일
I would love to know the reason, but at the very least this works for what I need.
In order to integrate it into my symbolic code (just because I prefer symbolic for its functionality), I was able to replace:
f1 = fplot(y1, [startCount, stopCount], '-r');
f2 = fplot(y2, [startCount, stopCount], '-b');
with:
f1 = fplot(matlabFunction(y1), [startCount, stopCount], '-r');
f2 = fplot(matlabFunction(y2), [startCount, stopCount], '-b');
so that it turns symbolic y1 = csc(x) into y1 = @csc for the purpose of plotting. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by