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
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
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
Walter Roberson 2019년 3월 6일
vectorize your function . use .* instead of * and use .^ instead of ^

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by