fimplicit gives a warning ''Function behaves unexpectedly on array inputs.''

3 views (last 30 days)
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 Comments
sajid majeed
sajid majeed on 4 Aug 2023
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 on 4 Aug 2023
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)

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 6 Mar 2019
vectorize your function . use .* instead of * and use .^ instead of ^

More Answers (0)

Categories

Find more on Performance and Memory in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!