plotting functions with range
조회 수: 1 (최근 30일)
이전 댓글 표시
before i make a question about syntax typing functions but now how plotting these functions, which range that i use? these three functions are: f1=1-x-x.^2./(2+x)-x.^3./(3+x)-x.^4./(4+x) f2 = sinh(x + 1) + tan(x.^2)./tan(x) + abs(1 - sin(1./(x.^2 + 1))) f3=abs(1-x.^2)-exp(3+x.^2)+log10(x.^2)+cos(x/(1+x.^2))
For example for f2 function i used range x=-2:0.1:2 i receive graph
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154754/image.jpeg)
my function have brake. why? when i typed this function i receive graph
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154755/image.jpeg)
where is problem? which range that i use for functions f1, f2, f3. why i use those ranges? i would like that you send me explain? thanks
댓글 수: 0
답변 (3개)
Mischa Kim
2014년 1월 7일
편집: Mischa Kim
2014년 1월 7일
For x = 0 MATLAB interprets the tan-term essentially as a 0 / 0 = NaN (not a number) and not tan(0) = 0 . This is because MATLAB computes the term numerically (as opposed to algebraically).
x = 0;
f2 = sinh(x + 1) + tan(x.^2)./tan(x) + abs(1 - sin(1./(x.^2 + 1)))
f2 =
NaN
As sort of a workaround, you can reduce the step size for x (e.g. x = -2:0.01:2; ) to make the gap between the two data points x = -0.01 and x = +0.01 smaller.
I am not sure I understand your question about range. Are you referring to the range in x values? Could you elaborate?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!