Warning using integral function: Function behaves unexpectedly on array inputs
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Dyuman Joshi
2024-1-9
编辑:Dyuman Joshi
2024-1-9
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!