A bug of function fplot (the figure is inconsistent with the one got by 'plot')

syms t_d % input variable
% the expression I would like to plot↓
f(t_d)=((6848549883207071*t_d)/70368744177664 + 619810600876641/147573952589676412928)/((6848549883207071*t_d)/35184372088832 - (exp(-6000000000000*t_d)*(6000000000000*t_d - exp(6000000000000*t_d) + 1))/60000 - (4102889305024308125000000*exp(-(7843586636568035*t_d)/16384)*((7843586636568035*t_d)/16384 - exp((7843586636568035*t_d)/16384) + 1))/2460874053013946398635327350449 + 619810600876641/73786976294838206464);
t_d_lb=0; % lower bound of t_d
t_d_ub=6e-10; % upper bound of t_d
order_t_d_lb=floor(log10(t_d_ub));
t_d_axis=t_d_lb:10^(order_t_d_lb-3):t_d_ub;
figure();% the left figure
plot(t_d_axis,f(t_d_axis));% the left figure
figure();% the right figure
fplot(f(t_d),[t_d_lb t_d_ub]); % the right figure
I often use ‘fplot’ to get the figure of an expression, but today I’ve got different curves plotted by function ‘fplot’ and ‘plot’. As the figure shown below, the left one is got by plugging in sampled inputs and drawn by ‘plot’, which is correct. However, the curve seems disappear at t_d=1.3e-10 at the right figure. I’ve checked the expression value at t_d=1.3e-10/1.6e-10/2e-10, etc, and I can make sure the left figure, which is got using ‘plot’, is correct.
Could anyone tell me if there’s a bug with ‘fplot’, and why there’s a dashed line in the right figure? What should I do to make ‘fplot’ work properly?

 Accepted Answer

You are correct. The bug is somewhere inside
toolbox/matlab/graphics/function/+matlab/+graphics/+function/@ParameterizedFunctionLine/ParameterizedFunctionLine.p
Work-around:
nF = feval(symengine, 'normal', f);
fplot(nF, [t_d_lb t_d_ub])

4 Comments

Thanks for answering, and your codes work!
Can you please expalin the purpose of the codes:
nF = feval(symengine, 'normal', f);
Did you convert the symfun to a sym by using this piece of code?
feval(symengine, 'normal', f)
"normalizes" f and returns the normalized value.
The normalized form of an expression is one expressed as a ratio (possibly with implied denominator 1). It takes the sum of fractions and brings them to a common denominator . This will typically not be the "simplest" form of the expression.
Normalized form does, however, have the advantage that if you were wanting to solve for the expression equalling zero, then you can just take the numerator and solve for that, after which you would double check that the solutions do not lead to singularities in the denominator.
(It is common when you are trying to find zeros, that you ignore the solutions that correspond to the denominator becoming infinite while the numerator is finite. Some of those are true solutions, but those solutions tend to lead to singularities, and cross-checking the cases usually requires taking limits... and typically to resolve such cases properly you have to go back to the original formula instead of the normalized form.)
fplot() was suggesting a singularity at about 1.8127e-10 . When you take the normalized form and extract the denominator, and plot it near there, you can see there is no zero of the function near there, and we can also see that there cannot be any signularity in the numerator near there. So the singularity that fplot sees is a false alarm.
Your explanation makes sense!
Could you please tell he how you found the singularity(at about 1.8127e-10) suggested by fplot()?
I did a bunch of fplot() with smaller intervals, reading off from the graphs to see what new limits I could use.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!