I get the warning 'Function behaves unexpectedly on array inputs.' when using fplot()

19 ビュー (過去 30 日間)
Why do I get a warning when using fplot() in my code:
function solution_heat_equation(t)
f = @(x,y) (exp((-abs(x-y).^2)./(4.*t))).*u_0(y);
a = -10;
b = 10;
z = @(x) integral(@(y) f(x,y) , a,b);
u = @(x) (1/sqrt(4*pi*t))*z(x)
fplot(u)
function val = u_0(x)
if abs(x)<1
val = 1;
else
val = 0;
end
I get the following warning and I don't get a plot of my function:
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly
vectorize your function to return an output with the same size and shape as the input
arguments.
> In matlab.graphics.function.FunctionLine>getFunction
In matlab.graphics.function/FunctionLine/updateFunction
In matlab.graphics.function.FunctionLine.set.Function_I
In matlab.graphics.function.FunctionLine.set.Function
In matlab.graphics.function.FunctionLine
In fplot>singleFplot (line 245)
In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 200)
In fplot>vectorizeFplot (line 200)
In fplot (line 166)
In solution_heat_equation (line 8)

採用された回答

Star Strider
Star Strider 2020 年 2 月 2 日
With a scalar ‘t’, there are no problems provided that ‘z’ sets 'ArrayValued' to true in the integral call, and ‘u’ is vectorised:
z = @(x) integral(@(y) f(x,y) , a,b, 'ArrayValued',1);
u = @(x) (1./sqrt(4*pi*t)).*z(x);
The rest of your code is unchanged.
  2 件のコメント
LM
LM 2020 年 2 月 2 日
I still get the warning but the plot is working. Thanks a lot!
Star Strider
Star Strider 2020 年 2 月 2 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by