How to improve the accuracy of drawing, especially for infinite functions?
조회 수: 2 (최근 30일)
이전 댓글 표시
in some plot assignments,we can use 'ezplot' to plot the more accurate figure but for infinite functions the 'ezplot' still can't plot it accurately,so how can we improve the accuracy of drawing, especially for infinite functions?
functions and codes are as this
syms m1;
g=9.8;
h=20;
hgang=20;
omega=2;
nu=omega^2*hgang/g;
g = @(m1) (i*m1)*tanh(i*m1)-nu;
fplot(g,[-10,20])
ylim([-60,40])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/219149/image.png)
댓글 수: 0
채택된 답변
Walter Roberson
2019년 5월 13일
Use fplot() instead of ezplot()
And skip using inline(): inline() has been recommended against since MATLAB 5.1
댓글 수: 11
Walter Roberson
2022년 1월 13일
If you have discontinuities and you want to use plot(), then you need to take one of two approaches:
- Detect the discontinuities (somehow) and insert a nan at that location so that MATLAB stops drawing there; OR
- Use your knowledge of the formulas to draw the lines in pieces, using hold on
If you use the Symbolic Toolbox and you write in terms of piecewise() then fplot() will detect the discontinuities and use vertical lines.
syms a b c d x real
part0 = piecewise(x<=a | x >= d, 0, 0);
part1 = piecewise(x>b & x < c, 1, 0);
part2 = piecewise(x > a & x <= b, (x-a)./(b-a), 0);
part3 = piecewise(x > b & x <= d, (d-x)./(d-c), 0);
f = part0 + part1 + part2 + part3
m = 10;
v1=unifrnd(0,1,1,m);
l1=unifrnd(0,1,1,m);
u1=unifrnd(1,2,1,m);
A = 0.1*l1';
B = 2*v1';
C = 3*v1';
D = 4*u1';
y = subs(f,{a,b,c,d}, {A,B,C,D});
fplot(y, [-1 3])
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!