我正在研究两个具有共同变量和自变量的方程的曲线拟合。代码如下:
function F = myfun(params,c, tt, hh)
F =[tt - params(2) - params(3) ./ (1 + params(3).^2 .* params(1).^2 .* (2.* pi.* freqs).^2),...
hh +((2.* pi.* freqs) .* params(4) - params(3).^2 * params(1) .* (2.* pi.* freqs) ./ (1 + params(3).^2 .* params(1).^2 .* (2.* pi.* freqs).^2))];
end
曲线拟合为:
lb = [0, 0, 0, 0, 1e10, 0, 0];
up = [inf,inf,inf,inf,inf,inf,inf];
params0 = [ 6e-8, 1.07e-7, 15, 10, 27e10, 0.29, 0.43e-6];
% options = optimoptions(@lsqnonlin,'Algorithm','trust-region-reflective');
params = lsqnonlin(@myfun, params0, lb, up);
错误是:
Not enough input arguments.
Error in Untitled>myfun (line 98)
F =[real_new - params(2) - params(3) ./ (1 +
params(3).^2 .* params(1).^2 .* (2.* pi.*
freqs).^2),...
Error in lsqnonlin (line 206)
initVals.F =
feval(funfcn{3},xCurrent,varargin{:});
Error in Untitled (line 32)
params = lsqnonlin(@myfun, params0, lb, up);
Caused by:
Failure in initial objective function
evaluation. LSQNONLIN cannot continue.
我试图检查已定义的功能,应该正确。 如何处理错误? 任何帮助或建议,表示赞赏!
...................................
Not enough input arguments
通过更改myfun
(具有更多参数和更复杂的特征)解决,如下所示:
myfun = @(params)[tt - params(2) - ((2.* pi.* freqs).^2.*params(5).^2.*params(3))./(params(3).^2 + (2.* pi.* freqs).^2.*params(5).^2)...
-(params(4).*(1-(2.* pi.* freqs).^2.*params(1).*params(7).*params(6).*params(4))...
+ ((2.* pi.* freqs).*params(7).*params(6).*params(4)).*((2 * pi.* freqs).*params(7).*Rp+ (2 * pi.* freqs).*params(7).*params(6)+(2 * pi.* freqs).*params(1).*params(4)))...
./((1-(2.* pi.* freqs).^2.*params(1).*params(7).*params(6).*params(4)).^2 +((2.* pi.* freqs).*params(7).*params(4)+ (2.* pi.* freqs).*params(7).*params(6)+(2.* pi.* freqs).*params(1).*params(4)).^2),...
hh +((2.* pi.* freqs).*params(5).*params(3).^2)./(params(3).^2 + (2.* pi.* freqs).^2.*params(5).^2)...
-(params(4).*((2 * pi.* freqs).*params(7).*Rp+ (2 * pi.* freqs).*params(7).*params(6)+(2 * pi.* freqs).*params(1).*params(4)) - ((2.* pi.* freqs).*params(7).*params(6).*params(4))...
.*(1-(2.* pi.* freqs).^2.*params(1).*params(7).*params(6).*params(4)))...
./((1-(2.* pi.* freqs).^2.*params(1).*params(7).*params(6).*params(4)).^2 ...
+ ((2.* pi.* freqs).*params(7).*params(4)+ (2.* pi.* freqs).*params(7).*params(6)+(2.* pi.* freqs).*params(1).*params(4)).^2)];
但是新的错误是:
Local minimum possible.
lsqnonlin stopped because the final change in the sum of squares relative to
its initial value is less than the default value of the function tolerance.
<stopping criteria details>
我试图设置公差:
options = optimoptions(@lsqnonlin,'Algorithm','trust-region-reflective','OptimalityTolerance',1e-8);
但是它不起作用。有什么建议么? 附带测试数据。 预先感谢