资源简介

结合一个题目演示了如何自编代码实现用多项式函数和指数函数作为基函数来实现最小二乘拟合,函数文件独立,便于移植,便于推广,题目附有解答,题目来自西工大数值计算方法作业。采用MATLAB实现。

资源截图

代码片段和文件信息

k=1:10;
t=(k-1)/10;
y=erf(t);

fun0=@(x)1;
fun1=@(x)x;
fun2=@(x)x*x;
fun3=@(x)power(x3);
fun4=@(x)power(x4);
fun5=@(x)power(x5);
fun6=@(x)power(x6);
fun7=@(x)power(x7);
fun8=@(x)power(x8);
fun9=@(x)power(x9);
fun10=@(x)power(x10);
fun11=@(x)exp(-x*x);
fun12=@(x)exp(-x*x)/(1+x);
fun13=@(x)exp(-x*x)/(1+x)/(1+x);
fun14=@(x)exp(-x*x)/(1+x)/(1+x)/(1+x);

phi1={fun0fun1};
phi2={fun0fun1fun2};
phi3={fun0fun1fun2fun3};
phi4={fun0fun1fun2fun3fun4};
phi5={fun0fun1fun2fun3fun4fun5};
phi6={fun0fun1fun2fun3fun4fun5fun6};
phi7={fun0fun1fun2fun3fun4fun5fun6fun7};
phi8={fun0fun1fun2fun3fun4fun5fun6fun7fun8};
phi9={fun0fun1fun2fun3fun4fun5fun6fun7fun8fun9};
phi10={fun0fun1fun2fun3fun4fun5fun6fun7fun8fun9fun10};

phi11={fun1fun3};
phi12={fun1fun3fun5};
phi13={fun1fun3fun5fun7};
phi14={fun1fun3fun5fun7fun9};

phi15={fun0fun11fun12fun13fun14};

err=zeros(151);
[~err(1)]=leastsquareEstimation(phi1yt);
[~err(2)]=leastsquareEstimation(phi2yt);
[~err(3)]=leastsquareEstimation(phi3yt);
[~err(4)]=leastsquareEstimation(phi4yt);
[~err(5)]=leastsquareEstimation(phi5yt);
[~err(6)]=leastsquareEstimation(phi6yt);
[~err(7)]=leastsquareEstimation(phi7yt);
[~err(8)]=leastsquareEstimation(phi8yt);
[~err(9)]=leastsquareEstimation(phi9yt);
[~err(10)]=leastsquareEstimation(phi10yt);
[~err(11)]=leastsquareEstimation(phi11yt);
[~err(12)]=leastsquareEstimation(phi12yt);
[~err(13)]=leastsquareEstimation(phi13yt);
[~err(14)]=leastsquareEstimation(phi14yt);
[~err(15)]=leastsquareEstimation(phi15yt);

format long
err

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        1677  2017-11-10 10:14  最小二乘函数拟合\Ex3_1.m
     文件         638  2017-11-10 09:52  最小二乘函数拟合\leastsquareEstimation.m
     文件       24561  2018-12-15 14:13  最小二乘函数拟合\示例题目.docx

评论

共有 条评论