24小时热门版块排行榜    

查看: 1667  |  回复: 7
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

o452794544

新虫 (初入文坛)

[求助] 二元非线性拟合,请大神帮忙看下程序哪有问题,谢谢!已有1人参与

两个自变量x1、x2,一个因变量y。通过绘图可以看出各个自变量和因变量的关系分布类似于正态分布,因此选用二维正太分布模型拟合。

下面是二维正态分布模型:

http://baike.baidu.com/view/9306579.htm  
可详见 http://baike.baidu.com/view/9306579.htm 百度百科

下面是数据:

y        x1                 x2
0        1000                2
0        1200                5
1        1400                15
1        1570                20
2        1720                30
2        1790                40
3        1860                60
4        1880                90
6        1980                172
7        2250                200
7        2530                250
8        2850                350
9        3100                450
10        3300                550
11        3500                650
12        3600                800
13        3800                1100
14        4000                1440
14        4200                1501
14        4500                1563
14        4800                1637
6        6800                2863

下面是函数代码:
function yy=fun(beta,x)
b1 = beta(1);
b2 = beta(2);
b3 = beta(3);
b4 = beta(4);
b5 = beta(5);
yy=(2*pi*b3*b4*(1-b5^2)^(1/2))^(-1)*exp(-1/2*(1-b5^2)^(-1)*((x(:,1)-b1)^2*b3^(-2)-2*b5*(x(:,1)-b1)*(x(:,2)-b2)*(b3*b4)^(-1)+(x(:,2)-b2)^2*b4^(-2)));

下面是程序运行代码:
clc
clear
data=load('data.txt');
y=data(:,1);
x=data(:,2:3);
beta=[1,0.1,3,1,0.5];         
[beta_out,r,J,COVB,mse]=nlinfit(x,y,@fun,beta);   
beta_out;
mse;
betaci=nlparci(beta_out,r,'Jacobian',J);   
betaa=[beta_out',betaci];        
[yy,delta]=nlpredci(@fun,x,beta_out,r,'Jacobian',J);
alpha=0.05;
nlintool(x,y,'fun',beta,alpha)  
r=corrcoef(y,yy);      
plotregression(y,yy)  
regstats(y,yy)

运行结果:
Warning: Rank deficient, rank = 0, tol =  0.000000e+00.
> In nlinfit>LMfit at 351
  In nlinfit at 184
  In nihe at 7
Warning: Some columns of the Jacobian are effectively zero at the solution, indicating that the
model is insensitive to some of its parameters.  That may be because those parameters are not
present in the model, or otherwise do not affect the predicted values.  It may also be due to
numerical underflow in the model function, which can sometimes be avoided by choosing better
initial parameter values, or by rescaling or recentering.  Parameter estimates may be unreliable.
> In nlinfit at 253
  In nihe at 7
Warning: Matrix is singular to working precision.
> In nlinfit at 274
  In nihe at 7
Warning: Matrix is singular to working precision.
> In nlparci at 104
  In nihe at 10
Warning: Matrix is singular to working precision.
> In nlpredci at 181
  In nihe at 12
Warning: Matrix is singular to working precision.
> In nlintool>PredictionsPlusError at 409
  In nlintool at 257
  In nihe at 14
Warning: Matrix is singular to working precision.
> In nlintool>PredictionsPlusError at 409
  In nlintool at 257
  In nihe at 14
Warning: Matrix is singular to working precision.
> In nlintool>PredictionsPlusError at 409
  In nlintool at 271
  In nihe at 14
Warning: Matrix is singular to working precision.
> In regstats at 193
  In regstats at 155
  In nihe at 17
Warning: Matrix is singular to working precision.
> In regstats at 208
  In regstats at 155
  In nihe at 17

出现很多错误,拟合度很低或者出现NaN。
求大神看是什么问题。
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

科院内马尔

银虫 (初入文坛)

引用回帖:
7楼: Originally posted by o452794544 at 2016-03-21 16:38:05
好的,谢谢,如果要是二元以上的多元的,也可以用这类函数吗?只要在函数后面再添加项就可以吗?...

楼主,请问你这个是用1stOpt实现的曲线拟合吗?
8楼2016-08-31 21:35:23
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 o452794544 的主题更新
信息提示
请填处理意见