24小时热门版块排行榜    

查看: 327  |  回复: 1

hanmei98232

木虫 (小有名气)

[求助] 求助 我自己仿照其他帖子写了个分段函数非线性拟合的程序一直出错 求高手! 已有1人参与

clear
tic
fun1=inline('-((beta(1)*x)/(beta(2)*x+1)).*8.314*298.15*(log(x)-0.784*(1.7321*x.^0.5/(1+2.0785*x.^0.5)+1.6667*log(1+2.0785*x.^0.5))+2.6667*x.*(beta(3)+beta(4)*(1+(-1-3.464*x.^0.5+6*x).*exp(-3.464*x.^0.5))/(12*x))+2.8289*x.^2*beta(5))+0.07214','beta','x');
fun2=inline('((beta(1)*x)/(beta(2)*x+1)).*8.314*298.15*(log(x)-0.784*(1.7321*x.^0.5/(1+2.0785*x.^0.5)+1.6667*log(1+2.0785*x.^0.5))+2.6667*x.*(beta(3)+beta(4)*(1+(-1-3.464*x.^0.5+6*x).*exp(-3.464*x.^0.5))/(12*x))+2.8289*x.^2*beta(5))+0.07214','beta','x');
fun=@(beta,x)((x<1).*fun1(beta,x)+(x>=1).*fun2(beta,x));
x=[0.19727        0.39798        0.60182        0.8034        0.98454        1.78733        2.05406        2.51801        3.16362        3.69954        4.5584 ];
y=[0.07282919        0.07366338        0.07454467        0.07522262        0.07593838        0.07919294        0.08033517        0.08203459        0.08494242        0.0867815        0.09083547];
beta=nlinfit(x,y,fun,[0.1,0.2,0.1,0.1,0]);
m=beta(1);
n=beta(2);
a=beta(3);
b=beta(4);
c=beta(5);
warning off all
y1=-((beta(1)*x)/(beta(2)*x+1)).*8.314*298.15*(log(x)-0.784*(1.7321*x.^0.5/(1+2.0785*x.^0.5)+1.6667*log(1+2.0785*x.^0.5))+2.6667*x.*(beta(3)+beta(4)*(1+(-1-3.464*x.^0.5+6*x).*exp(-3.464*x.^0.5))/(12*x))+2.8289*x.^2*beta(5))+0.07214;
y2=((beta(1)*x)/(beta(2)*x+1)).*8.314*298.15*(log(x)-0.784*(1.7321*x.^0.5/(1+2.0785*x.^0.5)+1.6667*log(1+2.0785*x.^0.5))+2.6667*x.*(beta(3)+beta(4)*(1+(-1-3.464*x.^0.5+6*x).*exp(-3.464*x.^0.5))/(12*x))+2.8289*x.^2*beta(5))+0.07214;
yfit(1:5)=y1;
yfit(6:11)=y2;
plot(x,y,'*')
hold on;
plot(x,yfit,'r-')
toc
求助 我自己仿照其他帖子写了个分段函数非线性拟合的程序一直出错 求高手!新手 刚刚接触 非常感谢
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

感谢参与,应助指数 +1
CODE:
fun1=inline('-((beta(1)*x)/(beta(2)*x+1)).*8.314*298.15*(log(x)-0.784*(1.7321*x.^0.5/(1+2.0785*x.^0.5)+1.6667*log(1+2.0785*x.^0.5))+2.6667*x.*(beta(3)+beta(4)*(1+(-1-3.464*x.^0.5+6*x).*exp(-3.464*x.^0.5))/(12*x))+2.8289*x.^2*beta(5))+0.07214','beta','x');
fun2=inline('((beta(1)*x)/(beta(2)*x+1)).*8.314*298.15*(log(x)-0.784*(1.7321*x.^0.5/(1+2.0785*x.^0.5)+1.6667*log(1+2.0785*x.^0.5))+2.6667*x.*(beta(3)+beta(4)*(1+(-1-3.464*x.^0.5+6*x).*exp(-3.464*x.^0.5))/(12*x))+2.8289*x.^2*beta(5))+0.07214','beta','x');
fun=@(beta,x)((x<1).*fun1(beta,x)+(x>=1).*fun2(beta,x));
x=[0.19727        0.39798        0.60182        0.8034        0.98454        1.78733        2.05406        2.51801        3.16362        3.69954        4.5584 ];
y=[0.07282919        0.07366338        0.07454467        0.07522262        0.07593838        0.07919294        0.08033517        0.08203459        0.08494242        0.0867815        0.09083547];
beta=nlinfit(x,y,fun,[0.1,0.2,0.1,0.1,0]);
plot(x,y,'ro',x,fun(beta,x),'k.')

The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
2楼2014-03-19 14:56:37
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 hanmei98232 的主题更新
信息提示
请填处理意见