找回密码
 注册
Simdroid-非首页
查看: 70|回复: 0

两种拟合方式,请问如何评价采纳

[复制链接]
发表于 2007-1-18 20:21:57 | 显示全部楼层 |阅读模式 来自 湖北武汉
以下是我编写的对非线性曲面的模型系数拟合的算法

                                1.模型函数 (这里的模型函数为一分数模型)
function f = my_fun(x0)
e1 = 1;
e2 = [20 10 5 3];
xd=[0.0975
0.19
0.36
0.51
0.64
0.75
0.84
0.91
0.96
0.99
];
yd = [2.0128        1.5021        1.2427        1.1341
3.0555        2.0178        1.4904        1.2696
5.22        3.0832        1.9965        1.5418
7.4938        4.1916        2.5128        1.8123
9.8673        5.3329        3.0309        2.0756
12.294        6.4802        3.5366        2.3241
14.662        7.5808        4.0075        2.5481
16.802        8.5596        4.4154        2.7369
18.515        9.3341        4.7317        2.8802
19.623        9.8311        4.9321        2.9698
];
f = [];
for ei = 1:4
    y1 = x0(1)*e1+x0(2)*e1.*xd+x0(3)*e2(ei)+x0(4)*e2(ei).*xd;
    y2 = e1+x0(5)*e1.*xd+x0(6)*e2(ei)+x0(7)*e2(ei).*xd;
    f_ei = y1./y2;  
    f_ei = f_ei-yd(:,ei);    %方式一:差
    %f_ei = (f_ei-yd(:,ei))*100./yd(:,ei); %方式二:相对误差*100
    f = [f;f_ei];%norm(f_ei,inf);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% f_ei = f_ei-yd(:,ei);    %方式一: 拟合点与样本点的差
% f_ei = (f_ei-yd(:,ei))*100./yd(:,ei); %方式二:拟合点与样本点的相对误差百分数*100


                  2.拟合代码,采用lsqnonlin非线性最小二乘法拟合
[x,resnorm,residual,exitflag,output] = lsqnonlin(@my_fun,x0);
%这里为防止出现 因为函数执行次数超出而中止迭代故加上了下面的代码
x0=x; n = [output.iterations, output.funcCount,output.cgiterations];
while exitflag == 0
    [x,resnorm,residual,exitflag,output,lambda,jacobian] = lsqnonlin(@my_fun,x0);
    x0 = x;n = n+[output.iterations, output.funcCount,output.cgiterations];
end

                         3 拟合的结果
两种拟合方式均收敛很好;收敛信息如下:
Optimization terminated: relative function value  changing by less than OPTIONS.TolFun.
方式一:
迭代次数 248;resnorm = 0.024478;
x0 =  [1.0344        -0.97322        0.010467        0.54327        -0.43418        0.0070479        -0.0074893];
拟合点与样本点的误差百分数:
1.205        -0.76067        -1.1011        -0.46761        0.057314        0.23588        0.17412        0.038748        -0.046306       
-0.067595        2.637        1.0945        0.32932        0.43015        0.55036        0.46866        0.23883        -0.0077892        -0.1867        -0.27564        2.2219        0.60567        -0.78953        -1.0636        -0.9242        -0.67229        -0.39616        -0.11345        0.14526        0.33363        2.0048        0.35708        -1.4226        -1.9542        -1.7774        -1.2079        -0.44661        0.35116        1.0504        1.5264
该百分数的二范数为: 0.063028

方式二:
迭代次数157;resnorm = 22.433;
x0 =  [1.017        -0.9126        0.0094001        0.56488        -0.3976        0.0082619        -0.0093351];
拟合点与样本点的误差百分数:
-0.59353        -1.3375        -0.82253        0.03549        0.55654        0.62384        0.4032        0.10114        -0.12777        -0.24621        1.1856        0.72815        0.82244        1.0894        1.0795        0.72531        0.16768        -0.40049        -0.84698        -1.1128        0.81806        0.072291        -0.42412        -0.40501        -0.29723        -0.25917        -0.28523        -0.32076        -0.33733        -0.33475        0.56063        -0.3892        -1.2726        -1.3565        -1.0264        -0.49822        0.10385        0.69148        1.1892        1.5219
该百分数的二范数为:0.047363


结论: 可不可以认为 采用相对误差百分数当作拟合点来进行拟合的效果是更好的?或者说这是一个一般性的结论?

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-4-26 10:36 , Processed in 0.037834 second(s), 17 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表