Why Does fplot() Show a Phantom Pole?

2 次查看(过去 30 天)
Example of fplot() showing a pole where clearely one does not exist. I know I can get rid of the dased line with the ShowPoles option, but that would eliminate all of the vertical lines, even for actual poles should there be any. Any idea why fplot() can't handle such a seemingly simple function?
syms t real
s(t) = piecewise(t<-1,0, t>2,0, exp(-abs(t)))
s(t) = 
figure;
fplot(s(t),[-3 3])
  9 个评论
Walter Roberson
Walter Roberson 2021-11-10
For the second of those:
===
Reference:
Suppose you have a symbolic formula that you want to turn into an anonymous function, such as
syms x
A = randi([-2 2], 1, 5);
for K = 1 : 5; F{K} = matlabFunction(A(K)*x, 'vars', {x}); end
for K = 1 : 5; result(K) = integral(F{K}, 0, 1); end
This works fine, calculating the integrals as needed. Unless, that is, that one of the A entries happens to be 0.
Because then A(K)*x -> 0*x -> 0 (symbolic) and
matlabFunction(sym(0), 'Vars', {x})
will generate
@(x) 0.
which is a problem because integral() requires that the result of executing the function on a vector of values is to return a vector the same size, but the result of executing @(x) 0. on a vector of values is to return the scalar constant 0.
The workaround is to know that use 'ArrayValued', true in integral -- which also reduces efficiency for all the integrations. If your symbolic expression does not use int() or piecewise() then matlabFunction will probably be able to vectorize the calculation, and that can be important for calculation purposes.
The improvement needed for matlabFunction is that functions of a single variable but constant value, should automatically use
zeros(size(Variable)) or constant*ones(size(Variable)) .
If the user did not specify 'vars' and the expression has no variables, then returning the scalar is perhaps still warranted.
If the function has more than one variable and the user specified 'vars', with {} with a single entry, and that single entry is a row vector, then matlabFunction is going to vectorize along columns, so the return should be constant*ones(size(Variable,1),1) . Likewise if the single entry is a column vector then matlabFunction is going to vectorize along rows, so the return should be
constant*ones(1,size(Variable,2)) .
Other 'vars' with cell cases lead to ambiguity about what to vectorize over, I think.
If the function has more than one variable and the user specified 'vars' without a cell, or if the user did not specify 'vars', then you have potential ambiguity about what size to return. For example, if the code would have normally been
@(x,y) constant .* x .* y
except that the constant was 0 so matlabFunction received only a 0 to know about, then it could be incorrect to use either x or y as the size, because of implicit expansion. You could make guesses such as
@(x,y) constant .* ones(max(size(x), size(y)))
but by that point it might be best to simply add an additional option indicating which variable to extract the size information from.
Walter Roberson
Walter Roberson 2021-11-10
The second one about incorrect size also refers to some of the details about the problems when using piecewise() with to a File with optimization turned on, which is a messy complicated one.

请先登录,再进行评论。

采纳的回答

Chunru
Chunru 2021-11-8
The default number of t points (23) is not big enough to show the details around t=0. Change it to a larger value.
syms t real
s(t) = piecewise(t<-1,0, t>2,0, exp(-abs(t)))
s(t) = 
fplot(s(t),[-3 3], 'MeshDensity', 200)
  3 个评论
Chunru
Chunru 2021-11-8
it "adaptively" setting the evaluation points based on the defaults. I am afraid there is no fool-proof methods for determining the pole locations for all possible scenarios.
Paul
Paul 2021-11-10
MeshDensity seems to be working well for the cases I'm interested in. Thanks.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by