登录论坛

查看完整版本 : [MATLAB数学相关] 非线性拟合


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的用户可进http://zhidao.baidu.com/question/99432374.html 有加分

TTT_IOU
2009-05-30, 22:48
程序里面的β最好换掉,还有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