24小时热门版块排行榜    

查看: 1724  |  回复: 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的回帖

dingd

铁杆木虫 (职业作家)

【答案】应助回帖

★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
o452794544: 金币+6, ★★★很有帮助 2016-03-21 16:39:36
换这个公式要好的多:
y=a*exp(-0.5*(((x1-b)/c)^2))+d*exp(-0.5*(((x2-f)/g)^2));

均方差(RMSE):0.401981621559676
残差平方和(SSE):3.55496292957842
相关系数(R): 0.996661569977283
相关系数之平方(R^2): 0.993334285069583
确定系数(DC): 0.993333686971469
卡方系数(Chi-Square): 0.838652138061828
F统计(F-Statistic): 480.02546329649

参数        最佳估算
----------        -------------
a        -5.90625065613002
b        1204.03546366578
c        -526.613682770912
d        14.0704287034134
f        1448.75058061013
g        -1080.76690762784
2楼2016-03-15 14:50:58
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dingd

铁杆木虫 (职业作家)

【答案】应助回帖

再加个拟合图
二元非线性拟合,请大神帮忙看下程序哪有问题,谢谢!
c1.jpg

3楼2016-03-15 14:51:47
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

o452794544

新虫 (初入文坛)

引用回帖:
2楼: Originally posted by dingd at 2016-03-15 14:50:58
换这个公式要好的多:
y=a*exp(-0.5*(((x1-b)/c)^2))+d*exp(-0.5*(((x2-f)/g)^2));

均方差(RMSE):0.401981621559676
残差平方和(SSE):3.55496292957842
相关系数(R): 0.996661569977283
相关系数之平方(R^2) ...

谢谢你的回答,这个是什么函数或模型?请问你为什么选用这个函数?有什么依据吗?
4楼2016-03-15 15:26:48
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

o452794544

新虫 (初入文坛)

引用回帖:
3楼: Originally posted by dingd at 2016-03-15 14:51:47
再加个拟合图

c1.jpg

还有可以把你的代码发上来吗?谢谢!
5楼2016-03-15 15:34:13
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dingd

铁杆木虫 (职业作家)

引用回帖:
4楼: Originally posted by o452794544 at 2016-03-15 15:26:48
谢谢你的回答,这个是什么函数或模型?请问你为什么选用这个函数?有什么依据吗?...

三维高斯函数,专门的峰值函数
6楼2016-03-15 17:09:23
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

o452794544

新虫 (初入文坛)

引用回帖:
6楼: Originally posted by dingd at 2016-03-15 17:09:23
三维高斯函数,专门的峰值函数...

好的,谢谢,如果要是二元以上的多元的,也可以用这类函数吗?只要在函数后面再添加项就可以吗?
7楼2016-03-21 16:38:05
已阅   回复此楼   关注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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 313求调剂 +3 肆叁贰壹22 2026-03-19 3/150 2026-03-21 08:01 by JourneyLucky
[考研] 南昌大学材料专硕311分求调剂 +6 77chaselx 2026-03-20 6/300 2026-03-21 07:24 by JourneyLucky
[考研] 316求调剂 +6 梁茜雯 2026-03-19 6/300 2026-03-21 06:32 by Ecowxq666!
[考研] 346求调剂[0856] +4 WayneLim327 2026-03-16 7/350 2026-03-21 04:02 by JourneyLucky
[考研] 307求调剂 +3 wyyyqx 2026-03-17 3/150 2026-03-21 03:20 by JourneyLucky
[考研] 301求调剂 +10 yy要上岸呀 2026-03-17 10/500 2026-03-21 03:14 by JourneyLucky
[考研] 初始318分求调剂(有工作经验) +3 1911236844 2026-03-17 3/150 2026-03-21 02:33 by JourneyLucky
[考研] 328求调剂,英语六级551,有科研经历 +4 生物工程调剂 2026-03-17 8/400 2026-03-21 02:12 by JourneyLucky
[考研] 085700资源与环境308求调剂 +12 墨墨漠 2026-03-18 13/650 2026-03-21 01:42 by JourneyLucky
[考研] 280求调剂 +7 咕噜晓晓 2026-03-18 8/400 2026-03-21 01:27 by JourneyLucky
[考研] 295求调剂 +4 一志愿京区211 2026-03-18 6/300 2026-03-20 23:41 by JourneyLucky
[考研] 321求调剂 +9 何润采123 2026-03-18 11/550 2026-03-20 23:19 by JourneyLucky
[考研] 材料学硕297已过四六级求调剂推荐 +11 adaie 2026-03-19 11/550 2026-03-20 21:30 by laoshidan
[考研] 一志愿西安交通大学 学硕 354求调剂 +3 我想要读研究生 2026-03-20 3/150 2026-03-20 20:13 by JourneyLucky
[考研] 求调剂 +3 @taotao 2026-03-20 3/150 2026-03-20 19:35 by JourneyLucky
[基金申请] 学校已经提交到NSFC,还能修改吗? 40+4 babangida 2026-03-19 8/400 2026-03-20 15:58 by babero
[考研] 0856调剂,是学校就去 +8 sllhht 2026-03-19 9/450 2026-03-20 14:25 by 无懈可击111
[考研] 293求调剂 +11 zjl的号 2026-03-16 16/800 2026-03-18 08:10 by zhukairuo
[考博] 26申博 +4 八6八68 2026-03-16 4/200 2026-03-17 13:00 by 轻松不少随
[考研] 070305求调剂 +3 mlpqaz03 2026-03-14 4/200 2026-03-15 11:04 by peike
信息提示
请填处理意见