1 / 10

数学模型实验课(二)

数学模型实验课(二). 最小二乘法与直线拟合. 康尔乃奶粉 32.4 元 400g; 67.1 元 900g. 4 k 1 + 4 2/3 k 2 = 32.4 9 k 1 + 9 2/3 k 2 = 67.1 解得 : k 1 = 5.3791, k 2 = 4.3192 模型 : C(W)=5.3791 W + 4.3192 W 2/3 . 预测 : W=1800, C(W) = 126.49. W=2500, C(W) = 154.36

tad-butler
Download Presentation

数学模型实验课(二)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 数学模型实验课(二) 最小二乘法与直线拟合

  2. 康尔乃奶粉 • 32.4元 400g; 67.1元 900g. • 4 k1 + 42/3 k2 = 32.4 • 9 k1 + 92/3 k2 = 67.1 • 解得: k1 = 5.3791, k2 = 4.3192 • 模型: C(W)=5.3791 W + 4.3192 W2/3. • 预测: W=1800, C(W) = 126.49. • W=2500, C(W) = 154.36 • 实际: W=1800, C(W)=115.9 • W=2500, C(W)=146.85

  3. >>x=[4,9,18,25];y=[32.4,67.1,115.9,146.85]; • >>x1=[x(1),x(2)]’,x2=x1.^(2/3); • >>y1=[y(1),y(2)]’;X=[x1,x2]; • >>k=X\y1 • >>x1=[x(1),x(2),x(3)];x2=x1.^(2/3); • >>y1=[y(1),y(2),y(3)];X=[x1,x2]; • >>k=X\y1

  4. 求解线性方程组:A x = y • 如果 . 设:Ax+ε= y,求 x 使得误差 ||ε|| 最小。

  5. A’A x = A’y x = (A’A)-1A’y 二. 直线拟合 1. 矩阵左除 数据(xi, yi),拟合直线 y = a + bx, 误差最小 模型:yi = a + bxi +ε X b = y

  6. >>y=[17,16,17,23,26,27,41,49]; • >>x=[1953,2015,2015,2821,3049,3049,5133,5592]; • >>X=[ones(8,1),x’];b=X\y’; • >>y1=b(1)+b(2).*x; • >>plot(x,y1,’r’,x,y,’*r’)

  7. 2. 直线拟合的效果(相关系数)

  8. >>X1=[x’,y’];m=size(X1);n=m(1);p=m(2); • >>X=[ones(n,1),x’];B=X\y’;a=B(1);b=B(2:p); • >>y1=a+b*x;plot(x,y1,’r’,x,y,’*r’); • >>Cov=X1’*(eye(n)-ones(n)./n)*X1; • >>Lyy=Cov(p,p);Lxx=Cov(1:(p-1),1:(p-1)); • >>R=(b’*Lxx*b)/Lyy;r=sqrt(R);

  9. 3. 多项式拟合 • b=polyfit(x,y,1); • 4.线性回归 • [b,r,j,k,l]=regress(y’,X);

More Related