MATLAB回归分析求系数问题!!!! matlab回归拟合相关问题
MATLAB回归分析求系数问题!!!!
f=@(a,x)a(1) (a(2) a(3)*(1-m)/m a(4)*n/m^2).*(x(1,:) x(2,:))/2 (a(5) a(6)*(1-m)/m a(7)*n/m^2).*(x(1,:)-x(2,:))/2
x = [281.1 283.0 284.8 286.7288.7 290.7 292.7 282.5 285.4 288.3 291.3 294.3 297.4 300.6]
y = [280 285 290 295 300 305310]
m = 0.972n = -0.013
[a,e]=lsqcurvefit(f,ones(1,7),x,y)
disp( a0 a1 a2 a3 a4 a5 a6 )disp(a)
disp(cha_wu)disp(e)
matlab回归拟合相关问题
把三段数据拼接到一起,然后做拟合就可以了,假设自变量都是t,三组数据是x1,x2,x3:
t=1:10
x1=(1:10) randn([1,10])
x2=(1:10) randn([1,10])
x3=(1:10) randn([1,10])
t=[t,t,t]
x=[x1,x2,x3]
   
p=polyfit(t,x,2)
figurehold on
plot(t,x,k*)
t=1:10
f=polyval(p,t)
plot(t,f,r)
legend(原始数据,二阶拟合)
效果图:
用matlab做回归的问题
y1=[1 2 3 5 6]
y2=
y3=
y=[y1 y2 y3 ……]
x1=[1 2 3 5 6]
x2=
x3=
x=[x1 x2 x3……]
p=[]
for i=1:length(x(1,:))
p1=polyfit(x(:,i),y(:,i),n)%n次回归
p=[p p1]
end
这将最后的回归结果都在矩阵p中
祝你学习愉快!