plotting functions with range
2 次查看(过去 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!