qingqing5638 发表于 2011-1-23 11:29

1stopt里面的最小一乘法拟合曲线

有谁能用1stopt里面的最小一乘法帮我拟合一个曲线啊?我想看看效果然后建议老师买这个软件!谢谢

dingd 发表于 2011-1-23 22:37

4.0版有专门的最小一乘拟合命令。
拟合优化方面,1stOpt应该是当今最强最好用的。

re-us 发表于 2011-1-23 23:42

最小一乘?是不是要最小绝对值,不是最小平方?如果是的话,我有个matlab的例子

qingqing5638 发表于 2011-1-26 13:18

回复 3 # re-us 的帖子

呵呵能不能程序借我看一下,我的是多元的

re-us 发表于 2011-2-12 02:07

本帖最后由 re-us 于 2011-2-12 02:11 编辑

这个是有一次我的homework,应该是对的,irls.m 是老师给的,大概就是迭代的算法
%homework for Bob's 2.1
clear;
clc

%precomputed data
x=1:10;
x=x';

y=10:10:100;
resi=;
y=y+resi;
y=y';
%outlier
y(4)=y(4)-50;
N=length(y);

%build the parabolic system matrix
G = [ ones(N,1) , x];
%least-squares solution
disp('Least-squares solution')
m2 = G\y

%1-norm solution
disp('1-norm solution')
m1=irls(G,y,1.0e-5,1.0e-5,1,25)
%Plot from the two models
mm1=G*m1;mm2=G*m2;
figure(1)
bookfonts;
plot(x,mm1,x,mm2,'k');
hold on
plot(x,y,'ok');
legend('L_1 Fit','L_2 Fit','Location','SouthEast');

function x=irls(A,b,tolr,tolx,p,maxiter)
% x=irls(A,b,tolr,tolx,p,maxiter)
%
% Uses the iteratively reweight least squares strategy to find an
% approximate L_p solution to Ax=b.

=size(A);

R=eye(m);
x=A\b;

iter=1;
while (iter <= maxiter)
iter=iter+1;
r=A*x-b;
for i=1:m
if (abs(r(i)) < tolr)
r(i)=abs(tolr)^(p-2);
else
r(i)=abs(r(i))^(p-2);
end
end
R=diag(r);
newx=(A'*R*A)\(A'*R*b);
if (norm(newx-x)/(1+norm(x)) < tolx)
return;
else
x=newx;
end
end




re-us 发表于 2011-2-12 02:12

大概的意思就是:如果有outliers的话,用最小1乘比较好,希望有帮助
页: [1]
查看完整版本: 1stopt里面的最小一乘法拟合曲线