MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB数学相关] 非线性拟合 (https://www.labfans.com/bbs/showthread.php?t=8727)

alee817 2009-05-30 21:05

非线性拟合
 
clc;clear;
x=[-500 -480 -450 -400 -350 -300 -200 -180 -150 -100 -75 -50 -25 0 50 100 125 150 200 220 230 300 350 400 500 600];

y=[0 4 6 10 50 120 150 180 200 400 600 800 1200 1400 1600 1500 1000 800 400 390 300 180 150 50 25 0];

myfunc=inline('0.5*beta(1)*sqrt(3)*erf(sqrt(pi)*beta(2)*x/200)-beta(1)*sqrt(3)*0.5*erf(sqrt(pi)*beta(2)/200*(100-beta(3)-beta(4))','beta','x');
beta=nlinfit(x,y,myfunc,[0.5 1 20 20]);
q=beta(1),tanβ=beta(2),s3=beta(3),s4=beta(4)
%test the model
xx=min(x):max(x);
yy=q*sqrt(3)*0.5*erf(sqrt(pi)*tanβ*x/200)-q*sqrt(3)*0.5*erf(sqrt(pi)*tanβ/200*(100-beta(3)-beta(4));
plot(x,y,'o',x,yy,'r')

帮忙怎样修改呢?初学者
baidu的用户可进[url]http://zhidao.baidu.com/question/99432374.html[/url] 有加分

TTT_IOU 2009-05-30 22:48

回复: 非线性拟合
 
1 个附件
程序里面的β最好换掉,还有erf函数的括号问题!!
clear;clc;
x=[-500 -480 -450 -400 -350 -300 -200 -180 -150 -100 -75 -50 -25 0 50 100 125 150 200 220 230 300 350 400 500 600];
y=[0 4 6 10 50 120 150 180 200 400 600 800 1200 1400 1600 1500 1000 800 400 390 300 180 150 50 25 0];
myfunc=inline('0.5*beta(1)*sqrt(3)*erf(sqrt(pi)*beta(2)*x/200)-beta(1)*sqrt(3)*0.5*erf(sqrt(pi)*beta(2)/200*(100-beta(3)-beta(4)))','beta','x');
beta=nlinfit(x,y,myfunc,[0.5 1 20 20]);
q=beta(1),tan=beta(2),s3=beta(3),s4=beta(4)
%test the model
xx=min(x):max(x);
yy=q*sqrt(3)*0.5*erf(sqrt(pi)*tan*x/200)-q*sqrt(3)*0.5*erf(sqrt(pi)*tan/200*(100-beta(3)-beta(4)));
plot(x,y,'o',x,yy,'r')
希望有帮助!!!

alee817 2009-05-30 23:05

回复: 非线性拟合
 
先感谢2楼,虽然代码可以运行了,可是几乎得出的结果是错误的,偏差太大了,是什么原因呢?

slgu 2009-05-31 11:20

回复: 非线性拟合
 
该组数若用模型:
fx=@(b,x)=b(1)./(1+b(2)*(x-b(3)).^2).^b(4);
则:
b=[1690.996, 0.000050379149, 49.067055, 1.7555723]
RSS =65750.9048
MSe = 3131
R^2 = 0.98986


所有时间均为北京时间。现在的时间是 03:14

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.