How to improve the accuracy of drawing, especially for infinite functions?

1 view (last 30 days)
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])

Accepted Answer

Walter Roberson
Walter Roberson on 13 May 2019
Use fplot() instead of ezplot()
And skip using inline(): inline() has been recommended against since MATLAB 5.1
  11 Comments
Walter Roberson
Walter Roberson on 13 Jan 2022
If you have discontinuities and you want to use plot(), then you need to take one of two approaches:
  1. Detect the discontinuities (somehow) and insert a nan at that location so that MATLAB stops drawing there; OR
  2. 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
f = 
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])

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!