fimplicit gives a warning ''Function behaves unexpectedly on array inputs.''
4 ビュー (過去 30 日間)
古いコメントを表示
I just wanna plot a dispersion equation according to the paper.
here is my code, really simple.
clc,clear all,
fimplicit(@(x,y) 9*y^4-((1-9)*9+2*9^2*10*(1-cos(x)))*y^2+2*9^2*10*(1-cos(x)),[-3 3 0 20]);
But the plot is not accurate near 0. What is going on and how can I fix it?
Warning message:
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.ImplicitFunctionLine>getFunction
In matlab.graphics.function.ImplicitFunctionLine/updateFunction
In matlab.graphics.function.ImplicitFunctionLine/set.Function_I
In matlab.graphics.function.ImplicitFunctionLine/set.Function
In matlab.graphics.function.ImplicitFunctionLine
In fimplicit>singleFimplicit (line 185)
In fimplicit>@(f)singleFimplicit(cax,f,limits,extraOpts,args) (line 148)
In fimplicit>vectorizeFimplicit (line 148)
In fimplicit (line 126)
In Test (line 2)
>>
2 件のコメント
sajid majeed
2023 年 8 月 4 日
fp = fimplicit(@(q,E) gamma(1/4-E/2).*hypergeom(1/4-E/2,1/2,q.^2) - 2*gamma(3/4-E/2).*hypergeom(3/4-E/2,3/2,q.^2).*q);
This is my code but errors occur. i.e.
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.ImplicitFunctionLine>getFunction
In matlab.graphics.function/ImplicitFunctionLine/updateFunction
In matlab.graphics.function/ImplicitFunctionLine/set.Function_I
In matlab.graphics.function/ImplicitFunctionLine/set.Function
In matlab.graphics.function.ImplicitFunctionLine
In fimplicit>singleFimplicit (line 193)
In fimplicit>@(f)singleFimplicit(cax,f,limits,extraOpts,args) (line 152)
In fimplicit>vectorizeFimplicit (line 152)
In fimplicit (line 126)
In tuntitled (line 1)
can any one please guide me
Walter Roberson
2023 年 8 月 4 日
The difficulty is that hypergeom expects vectors for the first two parameters. The vectors control what is to be calculated, and the calculation is vectorized only with respect to the third parameter. For example, hypergeom([1 2], 1/2, 1/3) is not at all the same as [hypergeom([1], 1/2, 1/3), hypergeom([2], 1/2, 1/3)]
When fimplicit is called, it expects the function to be vectorized with respect to both parameters -- it expects that fun(A,B) is the same as [fun(A(1),B(1)), fun(A(2),B(2)), ...] But since vectors for the first two parameters change what is calculated for hypergeom, hypergeom(A,1/2,q) for vector A is not the same as [hypergeom(A(1),1/2,q(1)), hypergeom(A(2),1/2,q(2))...]
fimplicit specifcally probes to ensure that the function is properly vectorized... and your function fails because of way hypergeom is used.
You will need to manually vectorize, such as
arrayfun(@(e,Q) hypergeom(1/4-e/2,1/2,Q.^2), E, q)
instead of hypergeom(1/4-E,1/2,q.^2)
採用された回答
Walter Roberson
2019 年 3 月 6 日
vectorize your function . use .* instead of * and use .^ instead of ^
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Performance and Memory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!