Warning using integral function: Function behaves unexpectedly on array inputs
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
DONGUK KIM
am 9 Jan. 2024
Kommentiert: Dyuman Joshi
am 9 Jan. 2024
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.
0 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 9 Jan. 2024
Bearbeitet: Dyuman Joshi
am 9 Jan. 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)
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
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Mobile Fundamentals finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
