Setting to use matlab `integral` with a (only) scalar function? -
i have function cannot written take vector input , return vector output. builtin integral
function seems expect this, , evaluating number of locations @ same time. there way turn off?
i.e., simplest test case is
f = @(x) x * x; % intended univariate integral(f, 0, 1); %i want have call univariate inputs.
where purposefully not setting function x .* x
in order test univariate input. obviously, function lot more complicated , cannot vectorized.
you can use array-valued flag that's mentioned in help:
>> f = @(x) x * x; >> integral(f,0,1,'arrayvalued',true) ans = 0.3333
the description bit misleading:
array-valued function flag, specified comma-separated pair consisting of
'arrayvalued'
, eitherfalse
,true
,0
, or1
. set flagtrue
indicatefun
function accepts scalar input , returns vector, matrix, or n-d array output.the default value of
false
indicatesfun
function accepts vector input , returns vector output.
so notice doesn't explicitly specify input scalar , output scalar, it's clear intent use scalar input.
Comments
Post a Comment