Warning using integral function: Function behaves unexpectedly on array inputs

1 visualizzazione (ultimi 30 giorni)
fplot(@(E) Current(E))
Current(1)
function test_integral = Current(V)
test_integral = integral(@(E) temp(E,V), -inf, inf);
function tempf = temp(E,V)
tempf = V.*exp(-(E.^2));
end
end
This is basically my code. Running this gives an error message of
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 test4 (line 4)
I think this has something to do with the integral function and fplot function colliding, but I don't know how any of the two functions can be substituted. Perhaps there is a way to vectorize the results of the Current function? Again, I don't know if this is even the right direction.
Help would be very much appreciated. Thanks in advance.

Risposta accettata

Dyuman Joshi
Dyuman Joshi il 9 Gen 2024
Modificato: Dyuman Joshi il 9 Gen 2024
Set the 'ArrayValued' property to 1 for the integral, so that it evaluates the integral of an array/vector valued function/integrand.
Current(1:4)
ans = 1×4
1.7725 3.5449 5.3174 7.0898
fplot(@(E) Current(E))
function test_integral = Current(V)
test_integral = integral(@(E) temp(E,V), -inf, inf, 'ArrayValued', 1);
function tempf = temp(E,V)
tempf = V.*exp(-(E.^2));
end
end

Più risposte (0)

Categorie

Scopri di più su Data Type Identification in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by