nlinfit函数 matlab,Matlab中拟合函数nlinfit和lsqcurvefit的问题
我有98個(gè)數(shù)據(jù),存放在data1.txt中,這是縱軸值。橫軸表示時(shí)間。我想用這些數(shù)據(jù)擬合出Logistic曲線并進(jìn)行預(yù)測(cè),我是這樣想的,先用三點(diǎn)法計(jì)算出擬合參數(shù)的估值,然后把這估值作初值用nlinfit或lsqcurvefit擬合。
logistic曲線的模型:y=L/(1+a*exp(-1*b*x))
下面是我的代碼,很簡(jiǎn)單:
% Logstic預(yù)測(cè)沉降模型
clear;
clc;
y0=load('data1.txt');% 載入原始數(shù)據(jù)
n=length(y0);
y1=1./y0;
m=54;
r=m/3;
S1=sum(y1(1:r));
S2=sum(y1(r+1:2*r));
S3=sum(y1(2*r+1:3*r));
b=log((S1-S2)/(S2-S3))/r;
L=r/(S1-(S1-S2)^2/(S1-2*S2+S3));
a=(S1-S2)^2*(1-exp(-1*b))*L/((S1-2*S2+S3)*exp(-1*b)*(1-exp(-1*r*b)));
for i=1:m
t(i)=i;
end
fun=inline('c(1)/(1+c(2)*exp((-1)*c(3)*x))','c','x');
c0=[L,a,b];
y2=y0(1:m)';
%[c renmon]=lsqcurvefit(fun,c0,t,y2);
[c renmon]=nlinfit(t,y2,fun,c0);
for i=1:n
y3(i)=c(1)/(1+c(2)*exp(-1*c(3)*i);
end
plot(t,y0(1:l),t,y2');
但是不對(duì),總是報(bào)錯(cuò),具體如下
1.用nlinfit錯(cuò)誤如下:
??? Error using ==> nlinfit
The inline model function generated the following error:
Error using ==> inlineeval
Error in inline expression ==> c(1)/(1+c(2)*exp((-1)*c(3)*x))
??? Error using ==> mrdivide
Matrix dimensions must agree.
Error in ==> Logistic2 at 26
[c renmon]=nlinfit(t,y2,fun,c0);
說是矩陣維數(shù)不匹配!
2.用lsqcurvefit錯(cuò)誤如下:
??? Error using ==> optim\private\lsqncommon
User supplied expression or inline function ==> c(1)/(1+c(2)*exp((-1)*c(3)*x))
failed with the following error:
Error using ==> inlineeval
Error in inline expression ==> c(1)/(1+c(2)*exp((-1)*c(3)*x))
??? Error using ==> mrdivide
Matrix dimensions must agree.
Error in ==> lsqcurvefit at 149
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
Error in ==> Logistic2 at 25
[c renmon]=lsqcurvefit(fun,c0,t,y2);
好像除了維數(shù)不對(duì),lsqcurvefit函數(shù)輸出參數(shù)數(shù)也不對(duì),⊙﹏⊙汗。可是我是參照別人的代碼寫的啊。我把模型函數(shù)重新建了個(gè)m文件也不行。我是用的7.0的版本
這是什么問題?誰能幫我解決呢?不勝感激!我是新手,還沒有m幣,所以大家見諒啊
總結(jié)
以上是生活随笔為你收集整理的nlinfit函数 matlab,Matlab中拟合函数nlinfit和lsqcurvefit的问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苹果4s怎么绕过id激活_急急急,iPh
- 下一篇: matlab 左上角,matlab –