## 1-1 ?´æ®µç¨‹å?ç¢¼ç?è¨ˆæ??¹æ?ï¼šé¦¬?¶è???

Example 1: 01-µ{¦¡­p®É/tictoc01.mtic % ¶}©l­p®É z=inv(rand(1000)); % inv «ü¥O¬O¥Î¨Ó­pºâ¤Ï¯x°} toc % µ²§ô­p®ÉElapsed time is 0.190357 seconds.

¥Ñ¤W­z½d¨Ò¡A¥i¥H±oª¾MATLAB ªá¶O¦b°õ¦æ inv(rand(1000)) ­pºâªº®É¶¡¡C

Hint

­Y­n¨Ï¥Î¦h­Ó°¨¿ö¨Ó­p®É¡A«h¥u»Ý­n±N tic «ü©w¨ì¤@­ÓÅÜ¼Æ§Y¥i¡A¹ïÀ³ªº toc «ü¥O¤]¥²¶·¥Î¨ì¦¹ÅÜ¼Æ¡A¤~¯à°O¿ý¦¹°¨¿ö©Òªáªº®É¶¡¡C¦b¤U¦C½d¨Ò¤¤¡A§Ú­Ì­pºâ inv «ü¥O¹ï¤£¦Pºû«×ªº¯x°}©Òªáªº®É¶¡¡A¨ä¤¤¥Î¤F¨â­Ó°¨¿ö¡A¤À§O­pºâÁ®É¶¡¥H¤Î¨C­Ó¯x°}©Òªáªº®É¶¡¡G

Example 2: 01-µ{¦¡­p®É/tictoc02.mtimer1=tic; % °¨ªí¤@¶}©l­p®É n=100*(1:10); for i=1:length(n) timer2=tic; % °¨ªí¤G¶}©l­p®É z=inv(rand(n(i))); % inv «ü¥O¬O¥Î¨Ó­pºâ¤Ï¯x°} time(i)=toc(timer2); % °¨ªí¤G°±¤î­p®É end fprintf('Overall time = %f sec\n', toc(timer1)); % °¨ªí¤@°±¤î­p®É plot(n, time, '.-'); xlabel('Matrix dimensions'); ylabel('Elapsed time (in sec)');Overall time = 0.562098 sec

­Y­n¨ú±oµ´¹ï®É¶¡¡A¥i¥H¨Ï¥Î clock «ü¥O¨Ó¶Ç¦^²{¦bªº®É¶¡©Ò§Î¦¨ªº¦V¶q¡A¥]§t 6 ­Ó¤¸¯À¡A¤À§O¬O¦~¡B¤ë¡B¤é¡B®É¡B¤À¡B¬í¡A¨Ò¦p§Ú­Ì¥i¥Hª½±µ¦b MATLAB µøµ¡¿é¤J¦p¤U¡G

>> round(clock) ans = 2012 2 6 10 58 12

¦b¤W¨Ò¤¤¡A¶Ç¦^ªº¾ã¼Æ¦V¶q¡A¥Nªí²{¦b®É¶¡¬O 2012 ¦~ 2 ¤ë 6 ¤é 10 ®É 58 ¤À 12 ¬í¡Around «ü¥Oªº§@¥Î¬O±N©Ò¦³¶Ç¦^¼Æ­È¡A¥[¥H¥|±Ë¤­¤J¦¨¾ã¼Æ¡A«K©ó¾\Åª¡C

Example 3: 01-µ{¦¡­p®É/etime01.mt0 = clock; % °O¿ý²{¦bªº®É¶¡ a = inv(rand(1000)); % °õ¦æ¤Ï¯x°}¹Bºâ elapsedTime = etime(clock, t0) % ­pºâ©Ò¯Ó¶OªºÁ®É¶¡ elapsedTime = 0.1490

Hint
etime ´N¬O elapsed time ¡]¸g¹L®É¶¡¡^ªºÂ²ºÙ¡C