function [f] = NSmodel(x)
%UNTITLED4 此处显示有关此函数的摘要
% 此处显示详细说明
global coupon dur fre price yrdif
inv_dur=1./dur;
w=inv_dur/sum(inv_dur);
n=length(price);
price_1=zeros(size(price));
for i=1:n
t=(yrdif(i)-floor(yrdif(i))):1.0/fre(i):yrdif(i);
c=ones(size(t)).*coupon(i)/fre(i);
c(end)=c(end)+100;
coef=t/x(4);
r=x(1)+x(2)*(1-exp(-coef))/coef+x(3)*((1-exp(-coef))/coef-exp(-coef));
price_1(i)=sum(c.*exp(-r.*t));
end
f=w.*(price_1-price);
end
x0=[0 0 0 0.5]
lb=[-0.1 -0.1 -0.1 0]
ub=[0.1 0.1 0.1 0.75]
options=optimset('Algorithm','Levenberg-Marquardt',...
'Display','iter');
x=lsqnonlin(@NSmodel,x0,lb,ub);
以下是错误描述:
错误使用 lsqncommon (line 66)
The Levenberg-Marquardt algorithm does not handle bound constraints and the trust-region-reflective algorithm requires at least as many
equations as variables; aborting.
出错 lsqnonlin (line 236)
[xCurrent,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
出错 Untitled6 (line 7)
x=lsqnonlin(@NSmodel,x0,lb,ub);
2017-12-2 08:34 上传
点击文件名下载附件
61.25 KB, 下载次数: 3
数据就这些