Download
least square method n.
Skip this Video
Loading SlideShow in 5 Seconds..
Least Square Method PowerPoint Presentation
Download Presentation
Least Square Method

Least Square Method

602 Views Download Presentation
Download Presentation

Least Square Method

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Least Square Method Curve Fitting

  2. Linear Least Square Method

  3. ตัว ในกรณีที่มีค่าพารามิเตอร์ จำนวน

  4. Example 1 on page 362 % Linear1.m k =[141 138 119 115]'; T = [390 500 1000 1500]'; X = [T,[1 1 1 1]']; y = k; p =inv(X'*X)*X'*y

  5. Non Linear System of Equation

  6. = Jacobian Matrix

  7. Example

  8. clear; c1 = 1; c2 = 1; %First Guess NONLINEAR1.m for i=1:10 X = [c1;c2]; f1 = 2*(4/3-2/9*c1-8/27*c2)*(c1+c2)+(1-1/3*c1-2/3*c2)^2; f2 = 2*(5/3-2/9*c1-10/27*c2)*(c1+2*c2)+(1+1/3*c1+1/3*c2)^2; F = [f1;f2]; df1c1 = 2*(4/3-2/9*c1-8/27*c2)- 4/9*(c1+c2)- 2/3*(1-1/3*c1-2/3*c2); df1c2 = 2*(4/3-2/9*c1-8/27*c2)- 16/27*(c1+c2)- 4/3*(1-1/3*c1-2/3*c2); df2c1 = 2*(5/3-2/9*c1-10/27*c2)- 4/9*(c1+2*c2)+ 2/3*(1+1/3*c1+1/3*c2); df2c2 = 4*(5/3-2/9*c1-10/27*c2)- 20/27*(c1+2*c2)+ 2/3*(1+1/3*c1+1/3*c2); Z = [df1c1,df1c2;df2c1,df2c2]; W = -F+Z*X; Xnew = inv(Z)*W; c1 =Xnew(1);c2= Xnew(2); fprintf(' %g %g %g\n',i,c1,c2); end

  9. Non Linear Least Square Numerically

  10. Expand {y} by Taylor

  11. Example : Stress Relaxation Time Force .000001, 3.083900 .016670, 1.647600 .033330, 1.176900 .050000, .935450 .066670, .784570 .083330, .681970 .100000, .609550

  12. Example : Stress Relaxation

  13. Stess.m

  14. % Parameters Estimation % Using Stress Relaxation Data % Five parameters clear; clc; clf; Data= ... [ 1, .000001, 3.083900 2, .016670, 1.647600 3, .033330, 1.176900 4, .050000, .935450 5, .066670, .784570 6, .083330, .681970 7, .100000, .609550 8, .116670, .555230 9, .133330, .506950 10, .150000, .470740 20, .316670, .289690 30, .483330, .223300 40, .650000, .181050 50, .816670, .156910 60, .983330, .138810 70, 1.150000, .126740 80, 1.316700, .114670 90, 1.483300, .108630 100, 1.650000, .102600 110, 1.816700, .090530 120, 1.983300, .084490 130, 2.150000, .084490 140, 2.316700, .078460 150, 2.483300, .078460 160, 2.650000, .078460 170, 2.816700, .072420 180, 2.983300, .072420 190, 3.150000, .066390 200, 3.316700, .066390 220, 3.650000, .060350 240, 3.983300, .060350 260, 4.316700, .054320 280, 4.650000, .060350 300, 4.983300, .048280 350, 5.816700, .048280 400, 6.650000, .048280 500, 8.316700, .042250 600, 9.983300, .036210];

  15. t = Data(:,2); y = Data(:,3)*1000/224.8089; y = y/y(1); plot(t,y,'ro'); legend('Data','Fit'); xlabel('Time'); ylabel('Force'); title ('Non Linear Regression'); axis([min(t) round(max(t)) 01]); hold on; Plothandle = plot(t,y,'-','EraseMode','xor');

  16. a =[10;10;10;1;1]; % First Guess of three parameters da =1; i=0; while da>1e-20 ym = a(1)*exp(-a(2)*t)+a(3)*exp(-a(4)*t)+a(5); dyda1 = exp(-a(2)*t); dyda2 = -a(1)*t.*exp(-a(2)*t); dyda3 = exp(-a(4)*t); dyda4 = -a(3)*t.*exp(-a(4)*t); dyda5 = 1+zeros(size(t)); Jacob = [dyda1,dyda2,dyda3,dyda4,dyda5]; anew = a +0.1*inv(Jacob'*Jacob)*Jacob'*(y-ym); da = norm(anew-a); a = anew; i=i+1; fprintf( 'Iter = %g Par =%g %g %g %g %g\n',i,a(1),a(2),a(3),a(4),a(5)); set (Plothandle,'ydata',ym); drawnow; hold off; end

  17. ybar = mean(y); SSr = sum((ym-ybar).^2); Syy = sum((y-ybar).^2); R2 = SSr/Syy; fprintf( ' Parameter =%g %g %g %g %g\n',a(1),a(2),a(3),a(4),a(5)); fprintf( ' R_square =%g \n',R2);