Я собрал функцию для вычисления сливающейся гипергеометрической функции (Куммера), которая по сути является усеченным степенным рядом (код ниже).Кажется, что это векторизация, то есть:
xx = linspace(0, 40, 100);
yy = kummer(0.5, 1.5, xx);
all(size(xx) == size(yy))
% Returns true for this case and any other size (up to 4D) of xx that I've tested
Однако, когда я пытаюсь построить функцию, используя fplot fplot(@(x) kummer(0.5, 1.5, x), [0 40])
, я получаю предупреждение NotVectorized fplot.
Warning: Function fails on array inputs. Use element-wise operators to increase speed.
> In matlab.graphics.function.FunctionLine>getFunction
In matlab.graphics.function.FunctionLine/set.Function_I
In matlab.graphics.function.FunctionLine/set.Function
In matlab.graphics.function.FunctionLine
In fplot>singleFplot (line 223)
In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 182)
In fplot>vectorizeFplot (line 182)
In fplot (line 153)
Я знаючтобы я мог просто отключить предупреждение при вызове kummer
и снова включить его в конце функции, но я бы хотел этого избежать.Любые мысли о том, что проблема может быть здесь?Код для kummer
показан ниже, я использую R2016a и проверил его в R2017a с тем же результатом:
function conf_hyper = kummer(a, b, z)
%kummer : Confluent hypergeometric (Kummer) function
% Compute the confluent hypergeometric function, 1F1(a; b; z)
%
% Parameters
% ----------
% a : scalar
% b : scalar
% z : Up to n-D matrix
% Elements must be numeric, non-negative, and less than
% 50 in magnitude (i.e., -50 < z < 50)
%
% Returns
% -------
% conf_hyper : n-D matrix
% Confluent hypergeometric function for all values of
% input z
%
% Raises
% ------
% Error KM:InvalidValue:abInput if a or b is not a numeric,
% real, positive, scalar
% Error KM:InvalidValue:zInput if z is not numeric, real,
% and less than 50 in magnitude
% Validate inputs
errorID = 'KM:InvalidValue:abInput';
errormsg = 'inputs a and b must be real, numeric, positive scalars';
validate_ab = @(x) isnumeric(x) && isscalar(x) && (x > 0) && isreal(x);
assert(validate_ab(a) && validate_ab(b), errorID, errormsg)
errorID = 'KM:InvalidValue:zInput';
errormsg = 'input z must be a numeric matrix of values in (-50, 50)';
assert(isnumeric(z) && isreal(z) && all(abs(z(:)) < 50), errorID, errormsg)
% Implement power series
% Initialize term (T), output (M), factorials (a and b), and index (i)
T = z * a / b;
M = 1 + T;
ai = a;
bi = b;
i = 1;
while any(abs(T(:)./M(:)) >= 1e-10)
% Increment index
i = i + 1;
% Update rising factorials
ai = ai + 1;
bi = bi + 1;
% Update term
T = z .* T * ai / bi / i;
% Update output
M = M + T;
end
% Write output
conf_hyper = M;
end
Спасибо!