数学建模社区-数学中国
标题:
【fittype问题】fittype接受的匿名函数中带有阶乘相,MATLAB提示错误
[打印本页]
作者:
sinpen
时间:
2015-4-12 15:54
标题:
【fittype问题】fittype接受的匿名函数中带有阶乘相,MATLAB提示错误
先贴代码:
t = 1:1:11;
h = [0.0572 0.0572 0.0572 0.0714 .1143 .1429 .1571 .1429 .1143 .1000 .0714 ];
plot(t, h, 'or'), hold on
s = fitoptions('Method', 'LinearLeastSquares');
ffun = fittype(@(lambda,n)(((lambda.^n)./factorial(n)).*exp(-lambda)),...
'Coefficients', {'lambda'},...
'Independent', 'n'...
);
[cfun, gof, output] = fit(t', h', ffun,...
'StartPoint', [7]);
plot(cfun,'b')
复制代码
这段script运行到 fittype 函数这里,会提示说传入的函数句柄为不可计算的MATLAB表达式:
Error using fittype (line 356)
Expression (((lambda.^n)./factorial(n)).*exp(-lambda)) is not a valid MATLAB expression, has non-scalar coefficients,
or cannot be evaluated:
Error while trying to evaluate FITTYPE function :
N must be a matrix of non-negative integers.
Error in poissonFit (line 7)
ffun = fittype(@(lambda,n)(((lambda.^n)./factorial(n)).*exp(-lambda)),...
复制代码
但是,我直接将这个函数句柄拿出来用,是可以加算的。
作者:
sinpen
时间:
2015-4-12 16:07
我深深地怀疑是不是那个factorial阶乘并不适合使用fittype?
欢迎光临 数学建模社区-数学中国 (http://www.madio.net/)
Powered by Discuz! X2.5