10-1 �u�ʰj�k�G���u���X

¤@¯ë¦Ó¨¥¡A¦±½uÀÀ¦X¡]Curve Fitting¡^©Ò«Ø¥ßªº¼Æ¾Ç¼Ò«¬¬O¡u³æ¿é¤J¡B³æ¿é¥X¡v¡]Single-input Single-output¡A²ºÙSISO¡^¡A©Ò¥H¨ä¯S©Ê¥i¥Î¤@±ø¦±½u¨Óªí¥Ü¡C­Y±ý«Ø¥ß¨ã¦³¨â­Ó¿é¤Jªº¼Æ¾Ç¼Ò«¬¡A«h¨ä¯S©Ê¥i¥Î¤@­Ó¦±­±¨Óªí¥Ü¡A¦¹Ãþ°ÝÃD¥iºÙ¬°¦±­±ÀÀ¦X¡]Surface Fitting¡^¡C¬Û¦Pªº·§©À¡A¥i¥H©µ¦ù¨ì¤@¯ëªº¡u¦h¿é¤J¡B³æ¿é¥X¡v¡]MISO¡^ ©Î¡u¦h¿é¤J¡B¦h¿é¥X¡v¡]MIMO¡^ªº¼Æ¾Ç¼Ò«¬¡A¨Ò¦pÃþ¯«¸gºô¸ô¡]Artificial Neural Networks¡^µ¥¡C

µL½×¬O¦±½uÀÀ¦X©Î¬O¦±­±ÀÀ¦X¡]©Î¬O¨ä¥¦¦h¿é¤J¼Ò«¬ªºÀÀ¦X°ÝÃD¡^¡A¦b¸ê®Æ¤ÀªR¤W³£ºÙ¬°°jÂk¤ÀªR¡]Regression Analysis¡^¡A©ÎºÙ¬°¸ê®ÆÀÀ¦X¡]Data Fitting¡^¡A¨ä²o¯A¨ìªº¼Æ¾Ç²z½×»P¤ÀªR§Þ¥©¬Û·í¼sªx¡C¦ý¦b¥»³¹¤¤¡A§Ú­Ì¥u¤¶²Ð´XºØ³Ì°ò¥»ªº¤èªk¡A¥H¤Î¦p¦ó¨Ï¥Î MATLAB ¨Ó¹ê²{³o¨Ç°ò¥»ªº¤èªk¡C

°jÂk¤ÀªR»P©Ò¨Ï¥Îªº¼Æ¾Ç¼Ò«¬¦³«Ü¤jªºÃö«Y¡A¦pªG©Ò¨Ï¥Îªº¼Ò«¬¬O½u©Ê¼Ò«¬¡A«h¦¹Ãþ°ÝÃDºÙ¬°½u©Ê°jÂk¡]Linear Regression¡^¡F¤Ï¤§¡A­Y¨Ï¥Î«D½u©Ê¼Ò«¬¡A«hºÙ¬°«D½u©Ê°jÂk¡]Nonlinear Regression¡^¡C¥»¸`±N¤¶²Ð½u©Ê°jÂk¡A¤U¸`«h¤¶²Ð«D½u©Ê°j½u¡C

½u©Ê°jÂk¬O¦b°jÂk¤ÀªR¤¤³Ì±`¥Îªº¤èªk¡A¨ä¼Ð·Ç¸Ñªk¤Î¬ÛÃö¼Æ¾Ç©Ê½è¥i¨£©ó¤@¯ë²Î­p©Î¸ê®Æ¤ÀªRªº±Ð¬ì®Ñ¡A¦]¦¹¥»³¹¤£°w¹ï²z½×¤Î¼Æ¾Ç±À¾É¸Ô­z¡AŪªÌ¥i¦Û¦æ°Ñ¦Ò¬ÛÃö®ÑÄy¡C¥H¤U±N¥H²³æ½d¨Ò¨Ó»¡©ú¦p¦ó¨Ï¥Î MATLAB ¨Ó¶i¦æ½u©Ê°jÂk¡C

°²³]§Ú­ÌªºÆ[¹î¸ê®Æ¬O¬ü°ê¦Û 1790 ¦Ü 1990 ¦~¡]¥H 10 ¦~¬°¤@³æ¦ì¡^ªºÁ`¤H¤f¡A¦¹¸ê®Æ¥i¥Ñ¸ü¤JÀÉ®× census.mat ±o¨ì¡A¦p¤U¡G

Example 1: 10-¦±½uÀÀ¦X»P°jÂk¤ÀªR/censusPlot01.mload census.mat % ¸ü¤J¤H¤f¸ê®Æ plot(cdate, pop, 'o'); % cdate ¥Nªí¦~«×¡Apop ¥Nªí¤H¤fÁ`¼Æ xlabel('¦~«×'); ylabel('¬ü°ê¤H¤fÁ`¼Æ');

¨ä¤¤ cdate ¬°¦~«×¡Apop ¬°¤H¤fÁ`¼Æ¡A¨âªÌ³£¬Oªø«×¬° 21 ªº¦V¶q¡C°²³]§Ú­Ì­n¹w´ú¦b¦è¤¸ 2000 ¦~¤Î 2010 ¦~ªº¬ü°ê¤H¤fÁ`¼Æ¡A§Ú­Ì´N¥²¶·®Ú¾Ú¤W­z¸ê®Æ¨Ó«Ø¥ß¤@¼Æ¾Ç¼Ò«¬¡A¨Ã¨Ì¦¹¼Ò«¬¨Ó¶i¦æ¹w´ú¡C

Hint
³o­Ó¡u¬ü°ê¤H¤f¹ï¦~«×ªº¸ê®Æ¡vªº½d¨Ò¡A¬O¤@­Ó«Ü¦Ñªº½d¨Ò¡]¤ñ MATLAB Á٦ѡ^¡A³Ì¦­¥X²{¦b¥Ñ¤T¦ì¤j®v Forsythe¡BMalcolm¡BMoler ©Ò¼gªº®Ñ¡uComputer Methods for Mathematical Computations¡v¡A©ó 1977 ¦~¥Ñ Prentice-Hall ¥Xª©ªÀ©Ò¥Xª©¡C

¥Ñ¤W¹Ï¸ê®ÆÂI¨«¶Õ¡A§Ú­Ì¥i¥HÆ[¹î±oª¾¡A³q¹L³o¨ÇÂIªº¦±½u¥i¯à¬O¤@±ø¤G¦¸ªº©ßª«½u¡A©Ò¥H§Ú­Ì¥i¥H°²³]©Ò»Ýªº¼Æ¾Ç¼Ò«¬¬° $$ y = f(x; a_0, a_1, a_2) = a_0+a_1x+a_2x^2 $$

¨ä¤¤ $y$¡]¤H¤fÁ`¼Æ¡^¬°¦¹¼Ò«¬ªº¿é¥X¡A$x$¡]¦~«×¡^¬°¦¹¼Ò«¬ªº¿é¤J¡A$[a_0,a_1, a_2]$ «h¬°¦¹¼Ò«¬ªº°Ñ¼Æ¡]Parameters¡^¡C¥Ñ©ó³o¨Ç°Ñ¼Æ¬Û¹ï©ó¿é¥X y ¬O§e½u©ÊÃö«Y¡A©Ò¥H¦¹¼Ò«¬ºÙ¬°¡u¨ã¦³½u©Ê°Ñ¼Æ¡]Linear-in-the-parameters¡^¡vªº¼Ò«¬¡A§Ú­Ìªº¥ô°È«h¬O§ä¥X³Ì¦nªº°Ñ¼Æ­È¡A¨Ï±o¼Ò«¬¿é¥X»P¹ê»Ú¸ê®Æ¶V±µªñ¶V¦n¡A¦¹¹Lµ{§YºÙ¬°½u©Ê°jÂk¡]Linear Regression¡^¡C

°²³]§Ú­ÌªºÆ[¹î¸ê®Æ¥i¼g¦¨ $(x_i, y_i), i = 1 - 21$¡C·í¿é¤J¬° $x_i$ ®É¡A¹ê»Ú¿é¥X¬° $y_i$¡A¦ý¼Ò«¬ªº¹w´ú­È¬° $f(x_i; a_0, a_1, a_2) = a_0+a_1x_i+a_2x_i^2$¡A¦]¦¹¥­¤è»~®t¬° $[y_i-f(x_i)]^2$¡A¦ÓÁ`¥­¤è»~®t «h¥iªí¥Ü¦p¤U¡G $$ E(a_0, a_1, a_2) = \sum_{i=1}^{21}[y_i-f(x_i)]^2 = \sum_{i=1}^{21}[y_i-(a_0+a_1x_i+a_2x_i^2)]^2 $$

¤W­z¥­¤è»~®t $E$ ¬O°Ñ¼Æ $a_0$¡B$a_1$¡B$a_2$ ªº¨ç¼Æ¡A¦]¦¹¥Ñ°ò¥»·L¿n¤À±oª¾¡A­Y­n¨D±o $E$ ªº³Ì¤p­È¡A§Ú­Ì¥i¥H¨D¥X $E$ ¹ï $a_0$¡B$a_1$¡B$a_2$ ªº¾É¦¡¡A¥O¨ä¬°¹s¡A§Y¥i¸Ñ¥X $a_0$¡B$a_1$¡B$a_2$ ªº³Ì¨Î­È¡C§ó¶i¤@¨BÆ[¹î¡A§Ú­Ìª¾¹D¦¹¼Ò«¬¨ã½u©Ê°Ñ¼Æ¡A©Ò¥H¥­¤è»~®t $E$ ¬° $a_0$¡B$a_1$¡B$a_2$ ªº¤G¦¸¦¡¡A¦Ó¾É¦¡ $\frac{\partial E}{\partial a_0}$¡B$\frac{\partial E}{\partial a_1}$ ¤Î $\frac{\partial E}{\partial a_2}$ ¬° $a_0$¡B$a_1$¡B$a_2$ªº¤@¦¸¦¡¡A¦]¦¹¦b¥O¾É¦¡¬°¹s¤§«á¡A§Ú­Ì¥i¥H±o¨ì¤@²Õ¤T¤¸¤@¦¸½u©ÊÁp¥ß¤èµ{¦¡¡A´N¥i¥H¸Ñ¥X°Ñ¼Æ $a_0$¡B$a_1$¡B$a_2$ ªº³Ì¨Î­È¡C

±q¥t¤@¤è­±¨Ó¬Ý¡A°²³] 21 ­ÓÆ[¹îÂI§¡³q¹L¦¹©ßª«½u¡A«h§Ú­Ì¥i¥H±N³o 21 ­ÓÂI±a¤J¦¹©ßª«½u¤èµ{¦¡¡A±o¨ì¤U¦C 21 ­Óµ¥¦¡¡G

$$ \left\{ \begin{matrix} a_0 + a_1 x_1 + a_2 x_1^2 & = & y_1\\ a_0 + a_1 x_2 + a_2 x_2^2 & = & y_1\\ \vdots & = & \vdots \\ a_0 + a_1 x_{21} + a_2 x_{21}^2 & = & y_{21}\\ \end{matrix} \right. $$

¥ç¥i¼g¦¨

$$ \underbrace{ \left[ \begin{matrix} 1 & x_1 & x_1^2\\ 1 & x_2 & x_2^2\\ \vdots & \vdots & \vdots\\ 1 & x_{21} & x_{21}^2\\ \end{matrix} \right] }_A \underbrace{ \left[ \begin{matrix} a_1\\ a_2\\ a_3\\ \end{matrix} \right] }_\theta = \underbrace{ \left[ \begin{matrix} y_1\\ y_2\\ \vdots\\ y_{21}\\ \end{matrix} \right] }_y $$

¨ä¤¤ $A$¡B$y$ ¬°¤wª¾¡A$\theta$ ¬°¥¼ª¾¦V¶q¡C«Ü©úÅ㪺¡A¤W­z¤èµ{²Õ§t 21 ­Ó¤èµ{¦¡¡A¦ý«o¥u¦³ 3 ­Ó¥¼ª¾¼Æ $\theta=\left[\theta_1, \theta_2, \theta_3 \right]^T$¡A©Ò¥H³q±`¤£¦s¦b¤@²Õ¸Ñ¨Óº¡¨¬³o 21 ­Ó¤èµ{¦¡¡C¦b¤@¯ë±¡ªp¤U¡A§Ú­Ì¥u¯à§ä¨ì¤@²Õ $\theta$¡A¨Ï±oµ¥¸¹¨âÃ䪺®t²§¬°³Ì¤p¡A¦¹®t²§¥i¼g¦¨

$$ \left\| y-A\theta \right\|^2 = (y-A\theta)^T(y-A\theta) $$

¦¹§Y¬°«e­zªºÁ`¥­¤è»~®t $E$¡C

¥Ñ©ó¦¹Ãþ°ÝÃD¦b½u©Ê°jÂk¸g±`¸I¨ì¡A©Ò¥H MATLAB ´£¨Ñ¤@­Ó²³æ¤è«Kªº¡u¥ª°£¡v¡]\¡^«ü¥O¡A¨Ó¸Ñ¥X³Ì¨Îªº $\theta$¡C¡]§Ú­Ì¦b¥»³¹³Ì«á¤@¤p¸`·|»¡©ú¦p¦ó¥H¯x°}ªº¾Þ§@¨Óºâ¥X $\theta$ ªº³Ì¨Î­È¡C¡^¦b¥H¤U½d¨Ò¤¤¡A§Ú­Ì§Q¥Î¡u¥ª°£¡v¨Óºâ¥X³Ì¨Îªº $\theta$ ­È¡A¨Ã¦P®Éµe¥X¨ã¦³³Ì¤p¥­¤è»~®tªº¤G¦¸¦±½u¡A¦p¤U¡G

Example 2: 10-¦±½uÀÀ¦X»P°jÂk¤ÀªR/census01.mload census.mat % ¸ü¤J¤H¤f¸ê®Æ plot(cdate, pop, 'o'); % cdate ¥Nªí¦~«×¡Apop ¥Nªí¤H¤fÁ`¼Æ A = [ones(size(cdate)), cdate, cdate.^2]; y = pop; theta = A\y; % §Q¥Î¡u¥ª°£¡v¡A§ä¥X³Ì¨Îªº theta ­È plot(cdate, pop, 'o', cdate, A*theta, '-'); legend('¹ê»Ú¤H¤f¼Æ', '¹w´ú¤H¤f¼Æ'); xlabel('¦~«×'); ylabel('¬ü°ê¤H¤fÁ`¼Æ');

Hint
  • ¥ª°£ªº·§©À¡A¥i°O¾Ð¦p¤U¡G­ì¥ýªº¤èµ{¦¡¬O A*theta = y¡A§Ú­Ì¥i±N A²¾¶µ¦Üµ¥¸¹¥kÃä¡A¦Ó±o¨ì theta = A\y¡C¥²¶·¤p¤ßªº¬O¡G­ì¥ý A ¦b­¼¦¡ªº²Ä¤@¶µ¡A©Ò¥H²¾¨ìµ¥¸¹¥kÃä«á¡AA ¤´µM¥²¶·¬O°£¦¡ªº²Ä¤@¶µ¡C
  • ­Y§Ú­Ì­n¸Ñªº¤èµ{¦¡¬O theta*A = y¡A«h¦P¼Ëªº·§©À¥i±o¨ì³Ì¤p¥­¤è¸Ñ theta = A/y¡C
  • ¦³Ãö¡u¥ª°£¡vªº¸Ô²Ó»¡©ú¡A¥i¨£¥»®Ñ¡u½u©Ê¥N¼Æ¡vªº²Ä¥|¸`¡uÁp¥ß½u©Ê¤èµ{¦¡¡v¡C

¥Ñ¤W­z½d¨Ò¡A§Ú­Ì¥i¥H§ä¥X³Ì¨Îªº $\theta=[a_0, a_1, a_2]=[21130, 23.51, 0.00654]$¡A¦]¦¹¨ã¦³³Ì¤p¥­¤è»~®tªº©ßª«½u¥i¥H¼g¦¨¡G $$ y = f(x) = a_0 + a_1 x + a_2 x^2 = 21130 + 23.51 x + 0.00654 x^2 $$

®Ú¾Ú¹Ï§Î¡A¦¹¤èµ{¦¡¤w¸g¯à°÷¬Û·í¹Gªñ©Òµ¹ªº 21 ­ÓÆ[¹îÂI¡C®Ú¾Ú¦¹©ßª«½u¼Æ¾Ç¼Ò«¬¡A§Ú­Ì¥i¥H¹w´ú¬ü°ê¦b 2000 ©M 2010 ¦~ªº¤H¤fÁ`¼Æ¬°¡G

Example 3: 10-¦±½uÀÀ¦X»P°jÂk¤ÀªR/census02.mload census.mat % ¸ü¤J¤H¤f¸ê®Æ A = [ones(size(cdate)), cdate, cdate.^2]; theta = A\pop; % §Q¥Î¡u¥ª°£¡v¡A§ä¥X³Ì¨Îªº theta ­È t=2000; pop2000 = [1, t, t^2]*theta; % ¦b 2000 ¦~¬ü°ê¤H¤f½u¼Æ¹w´ú­È t=2010; pop2010 = [1, t, t^2]*theta; % ¦b 2010 ¦~¬ü°ê¤H¤f½u¼Æ¹w´ú­È fprintf('¬ü°ê¤H¤f¦b2000¦~ªº¹w´ú­È = %g ¡]¦Ê¸U¤H¡^\n', pop2000); fprintf('¬ü°ê¤H¤f¦b2010¦~ªº¹w´ú­È = %g ¡]¦Ê¸U¤H¡^\n', pop2010);¬ü°ê¤H¤f¦b2000¦~ªº¹w´ú­È = 274.622 ¡]¦Ê¸U¤H¡^ ¬ü°ê¤H¤f¦b2010¦~ªº¹w´ú­È = 301.824 ¡]¦Ê¸U¤H¡^

Hint
½Ð¹ê»Ú°Ý¬Ý¬Ý Google ¤j¯«¡A¬Ý¬Ý¬ü°ê¦b 2000 ©M 2010 ¦~ªº¤H¤f¦U¬O¦h¤Ö¡H§Ú­Ì³o­Ó¹w´ú¼Ò«¬·Ç¶Ü¡H

¦b¤W­z¨Ò¤l¤¤¡A§Ú­Ìªº¼Æ¾Ç¼Ò«¬¬O¤@­Ó¤G¦¸©ßª«½u¡A§Ú­Ì¥i±N¤§±À¼s¡A±o¨ì¤@­Ó n ¦¸¦h¶µ¦¡¡G

$$y = f(x) = a_0 + a_1 x + a_2 x^2 + \cdots + a_n x^n$$

§Q¥Î¦h¶µ¦¡ªº¼Æ¾Ç¼Ò«¬¨Ó¶i¦æ¦±½uÀÀ¦X¡A³qºÙ¬°¡u¦h¶µ¦¡ÀÀ¦X¡]Polynomial Fitting¡^¡v¡A¤]¬O¦b¸ê®Æ¤ÀªR±`¥Î¨ìªº§Þ¥©¡C°w¹ï¦h¶µ¦¡ÀÀ¦X¡AMATLAB ´£¨Ñ¤F polyfit «ü¥O¨Ó§ä¥X³Ì¨Î°Ñ¼Æ¡A¨ä®ÄªG©M¡u¥ª°£¡v¡]\¡^¬O¤@­Pªº¡C¤@¥¹§ä¥X³Ì¨Î°Ñ¼Æ«á¡A§Ú­Ì¥i¥H¨Ï¥Î polyval «ü¥O¨Ó­pºâ¦h¶µ¦¡ªº­È¡Aµ{¦¡½X§ó¥[²¼ä¡A½Ð¨£¤U¦C½d¨Ò¡G

Example 4: 10-¦±½uÀÀ¦X»P°jÂk¤ÀªR/census03.mload census.mat % ¸ü¤J¤H¤f¸ê®Æ theta = polyfit(cdate, pop, 2); % ¶i¦æ¤G¦¸¦h¶µ¦¡ÀÀ¦X¡A§ä¥X theta ­È fprintf('¦b2000¦~ªº¹w´ú­È = %g ¡]¦Ê¸U¤H¡^\n', polyval(theta, 2000)); fprintf('¦b2010¦~ªº¹w´ú­È = %g ¡]¦Ê¸U¤H¡^\n', polyval(theta, 2010));¦b2000¦~ªº¹w´ú­È = 274.622 ¡]¦Ê¸U¤H¡^ ¦b2010¦~ªº¹w´ú­È = 301.824 ¡]¦Ê¸U¤H¡^

¦b¤W­z½d¨Ò¤¤¡A¡upolyfit(cdate, pop, 2)¡v¤¤ªº 2 ¥Nªí§Ú­Ì¥Î¨ìªº¼Ò«¬¬O 2 ¦¸¦h¶µ¦¡¡C¨Ï¥Î polyfit ©M polyval¡A¬O¤£¬OÅýµ{¦¡½X²µu«Ü¦h©O¡H¦³Ãö polyfit¡Bpolyval ¤Î¨ä¥¦¬ÛÃöªº¦h¶µ¦¡«ü¥O¡A¥i¨£¥»®Ñ¡u¦h¶µ¦¡ªº³B²z¤Î¤ÀªR¡v³¹¸`¡C

½u©Ê°jÂkªº¦¨¥\»P§_¡A»P©Ò¿ï¨úªº¼Ò«¬¦³«Ü¤jªºÃö«Y¡C¼Ò«¬©Ò§tªº°Ñ¼Æ¶V¦h¡A¥­¤è»~®t·|¶V¤p¡A­Y°Ñ¼Æ­Ó¼Æµ¥©ó¸ê®ÆÂI­Ó¼Æ¡A«h¦b¤@¯ë±¡ªp¤U¡A¥­¤è»~®t·|µ¥©ó¹s¡A¦ý³o¨Ã¤£ªí¥Ü¹w´ú·|³Ì·Ç¡A¦]¬°¸ê®ÆÂI§t¦³Âø°T¡A§¹¥þ§k¦X¸ê®Æªº¼Ò«¬¥ç¥Nªí¦¹¼Ò«¬¨üÂø°Tªº¼vÅT³Ì¤j¡A¹w´ú¤§·Ç½T«×¤]·|¸û®t¡C¦]¦¹¡A¡u¼Ò«¬½ÆÂø«×¡v¡]§Y¥iÅܰѼƪº­Ó¼Æ¡^©M¡u¹w´ú·Ç½T«×¡v¬O¬Û¤¬§Ü¿Åªº¨â­Ó¦]¯À¡AµLªk¨âªÌ­Ý±o¡A¦]¦¹§Ú­Ì¥²¶·¸g¥Ñ¹ï°ÝÃD¥»¨­ªºÁA¸Ñ¡A¨Ó§ä¨ì¤@­Ó¥­¿ÅÂI¡C

­Y¦b MATLAB ¤U¿é¤J¡ucensus¡v¡A´N¥i¥H¬Ý¨ì¨Ï¥Î¤£¦P¦¸¼Æªº¦h¶µ¦¡¡A¨Ó¹ï census ¸ê®Æ¶i¦æ¦±½uÀÀ¦Xªºµ²ªG¡A¦p¤U¡G

¥Ñ¤W­z¹Ï§Î¥i¥H¬Ý¥X¡A·í¦h¶µ¦¡ªº¦¸¼Æ¶V¨Ó¶V°ª®É¡A¡u¥~´¡¡v±`·|¥X²{¤£¥i«Hªºµ²ªG¡C¨Ò¦p¦b¤W¹Ï¤¤¡A¨Ï¥Î degree=8 ªº¦±½u¨Ó¹w´ú 2020 ¦~ªº¤H¤f¡A¤Ï¦Ó¥X²{¤£¤É¤Ï­°ªº±¡ªp¡]Ãø¹D¬Oµo¥Í¤F¥@¬É¤j¾Ô¡H¡^¡A³oºØ¤Ï±`ªºµ²ªG¡Aªí¥Ü§Ú­Ì¿ï¥Îªº¼Ò«¬°Ñ¼Æ¤Ó°ª¡AÁöµM»~®tªº¥­¤è©MÅܤp¤F¡A¦ý¬O¹w´úªº¥i¾a«×¤]¤U­°¤F¡C


MATLABµ{¦¡³]­p¡G¶i¶¥½g