14-2 ���ͿW�����ε{��

­º¥ý¡A§Ú­Ì¨Ó»¡©ú¦p¦ó¥HMATLAB½sĶ¾¹¨Ó±N¤@­ÓMATLAB¨ç¦¡½sĶ¦¨¿W¥ßÀ³¥Îµ{¦¡¡]Stand-alone Application¡^¡A¦¹µ{¦¡¥i¥H¦b¨S¦³¦w¸Ë MATLAB ªº¹q¸£°õ¦æ¡C©Ò¨Ï¥Îªº«ü¥O¬O mcc¡A®æ¦¡¦p¤U¡G

mcc ¡Vm userFunc.m

¨ä¤¤ userFunc.m ¬O¤@­Ó¥Ñ¨Ï¥ÎªÌ©Ò³]­pªºMATLAB¨ç¦¡¡A¸g¥ÑMATLAB½sĶ¾¹ªºÂà´««á¡A¥i¥H²£¥Í userFunc.exe¡]·L³nµøµ¡¥­¥x¡^©Î userFunc¡]Unix/Linux¥­¥x¡^ªº¥i°õ¦æÀÉ¡A§A¥i¥H¦b¨S¦³¦w¸Ë MATLAB ªº¨ä¥L¹q¸£°õ¦æ³o¨ÇÀɮסC

Åý§Ú­Ì¨Ó¬Ý¤@­Ó²³æªº½d¨Ò¡C­º¥ý¡A§Ú­Ì¥ý¼¶¼g¤@­Ó MATLAB ¨ç¦¡myEigValue.m¡A¦¹¨ç¦¡ªº¿é¤J¬O¤@­Ó¤è°}¡A¨Ã¨Ï¥Î MATLAB ªº¤º«Ø¨ç¼Æ eig ¨Ó­pºâ¦¹¤è°}ªº©T¦³­È¡AµM«á±N¦¹©T¦³­È¦C¦L¥X¨Ó¡A¦¹¨ç¦¡ªº­ì©l½X¦p¤U¡G

14-matlab½sĶ¾¹/myEigValue.mfunction eigValue = myEigValue(mat) %myEigValue: Generate the eigenvalues of the given matrix % Roger Jang, 20080210 if (isstr(mat)) % ­Y¿é¤J¬O¦r¦ê¡AÂন¼Æ­È mat=eval(mat); end [a, b] = eig(mat); eigValue=diag(b); disp(eigValue); % Åã¥Ü©T¦³­È eigenValue

±ý´ú¸Õ¦¹½d¨Ò¡A¥i¥H¦bMATLAB©R¥Oµøµ¡¿é¤J¡G

myEigValue(magic(5));

§Y¥i¦b¿Ã¹õÅã¥Ü¤@­Ó 5X5 ªºÅ]³N¤è°}©Ò¹ïÀ³ªº©T¦³­È¡C

Hint
¦b±N¦¹MATLAB¨ç¦¡½sĶ¦¨¬°¥i°õ¦æÀɪº¹Lµ{¤¤¡A·|²£¥Í¤@¨ÇÃB¥~ÀɮסA©Ò¥H§A¥²¶·±N¥»½d¨Ò¥Ñ¥úºÐ«þ¨©¦ÜµwºÐ¡A¤~¯à¶i¦æ¥H¤Uªº¾Þ§@¡C

¥Ñ©ó§Ú­Ì­n±N myEigValue.m Âà´«¦¨ myEigValue.exe¡A©Ò¥H¦³¤@¨Ç²Ó¸`­n¯S§O¤p¤ß¡G

  1. ¦]¬°MATLAB¨ç¦¡Âন°õ¦æÀÉ«á¡A©óDOSÀô¹Ò¤U¿é¤Jªº¸ê®Æ¬O¥H¦r¦ê¤è¦¡¶Ç¤J¡]©R¥O¦C°Ñ¼Æ¡^¡A©Ò¥H myEigValue.m ¥²¶·¥ý¨Ï¥Î eval ±N¿é¤J¦r¦êÂର¤è°}¡C
  2. myEigValue.m ¥²¶·¨Ï¥Î disp µ²ªG¦L¦b¿Ã¹õ¤W¡A¥H¤è«K myEigValue.exe ¨Ó¦L¥X¦P¼Ëªºµ²ªG¡C

±µµÛ¡A§Ú­Ì¦bMATLAB©R¥Oµøµ¡¤U¡A¥ý±N¤u§@¥Ø¿ý§ïÅÜ¦Ü myEigValue.m ©Ò¦bªº¥Ø¿ý¡AµM«á¨Ï¥Î¤U¦C©R¥O¨Ó±N myEigValue.m ½sĶ¦¨ myEigValue.exe¡A¦p¤U¡G

mcc ¡Vm myEigValue.m

Hint
¡u-m¡v¥Nªí¨Ï¥Î¥¨¶°¡]Macro¡^¨Ó²£¥Í¿W¥ßÀ³¥Îµ{¦¡¡A³o¬O¤@¯ë¹w³]ªº¿ï¶µ¡C

¤j¬ù¸g¹L¥b¤ÀÄÁªº®É¶¡¡A´N·|§¹¦¨½sĶ¡A¨Ã²£¥Í¼Æ­ÓÀɮסA¥]§t ¤@­Ó¥i°õ¦æÀÉ myEigValue.exe¡C­Y­n´ú¸Õ¦¹¥i°õ¦æÀÉ¡A¥i¥Hª½±µ¦b DOS ©R¥Oµøµ¡¤U¿é¤J¡G

myEigValue.exe magic(5)

§Y¥i¦b¿Ã¹õÅã¥Ü¤@­Ó 5X5 ªºÅ]³N¤è°}©Ò¹ïÀ³ªº©T¦³­È¡C­Y­n¿é¤J¤@­Ó¯S©wªº¤è°}¡A¥i¥H¨Ï¥ÎÃþÂù¤Þ¸¹¨Ó¥]¦í¥Nªí¤è°}ªº¦r¦ê¡A½d¨Ò¦p¤U¡G

myEigValue.exe "[1 2 3; 3 2 1; 1 1 1]" §Ú­Ì¥i¥H±N¤W­z¬yµ{¾ã²z¦¨¤@­Ó³æ¤@ªº½d¨Ò¡G

Example 1: 14-matlab½sĶ¾¹/mcc01.mfprintf('MATLAB version=%s\n', version); if ~exist('myEigValue'), mkdir('myEigValue'); end fprintf('Compiling myEigValue.m...\n'); tic; mcc -m myEigValue.m -d myEigValue; fprintf('Time for compiling = %g sec\n', toc); fprintf('Running DOS command: myEigValue\\myEigValue.exe magic(5)\n'); !myEigValue\myEigValue.exe magic(5) fprintf('Running DOS command: myEigValue\\myEigValue.exe "[1 2 3; 3 2 1; 1 1 1]"\n'); !myEigValue\myEigValue.exe "[1 2 3; 3 2 1; 1 1 1]" MATLAB version=7.14.0.739 (R2012a) Compiling myEigValue.m... DEMO Compiler license. The generated application will expire 30 days from today, on Sat Sep 15 20:06:02 2012. Time for compiling = 45.2777 sec Running DOS command: myEigValue\myEigValue.exe magic(5) 65.0000 -21.2768 -13.1263 21.2768 13.1263 Running DOS command: myEigValue\myEigValue.exe "[1 2 3; 3 2 1; 1 1 1]" 5.0000 -1.0000 0.0000

¦b¤W­z½d¨Ò¤¤¡A§Ú­Ì¦h°µ¤F´X¥ó¨Æ¡A¨ÓÅý¾ã­ÓÀɮץؿýµ²ºc°®²b¤@¨Ç¡G
  1. ¦pªG¿é¥X¥Ø¿ý myEigValue ¤£¦s¦b¡A§Ú­Ì¥ý«Ø¥ß³o­Ó¥Ø¿ý¡C
  2. ¦b mcc «ü¥O¤¤¨Ï¥Î¡u-d myEigValue¡v¥H«ü©w¿é¥X¥Ø¿ý¡A©Ò¦³ªº¿é¥XÀɮס]¥]§t³Ì«áªº¥i°õ¦æÀɮס^³£·|³Q¦s©ñ¦b¦¹¥Ø¿ý¤¤¡C

¦b¨Ï¥Î mcc ®É¡AÁÙ¦³´XÂI­nª`·N¡G

¥Ñ¦¹¤è¦¡©Ò½sĶ¥X¨Óªº¥i°õ¦æÀÉ¡A­Y­n¦b¨S¦³¦w¸Ë MATLAB ªº¾÷¾¹°õ¦æ¡AÁÙ¥²¶·¦h¤@¹D¤âÄò¨Ó¦w¸Ë MATLAB ¬ÛÃöªº¨ç¦¡®w¡A¦w¸ËÀɪº¦ì¸m¦p¤U¡]¥H 64-bit Windows ¥­¥x¬°¨Ò¡^¡G

{matlabroot}\toolbox\compiler\deploy\win64\MCRInstaller.exe
¦¹¦w¸ËÀÉ¥u»Ý°õ¦æ¤@¦¸§Y¥i¡A¬ÛÃö¸Ô²Ó»¡©ú¡A¥i°Ñ¨£½sĶ¹Lµ{¤¤©Ò²£¥Íªº readme.txt¡A©Î¬Oª½±µ¦bMATLAB¿é¤J¡umcrinstaller¡v¡]mcr¥NªíMATLAB Compiler Runtime¡A¥Î¨Ó¦s©ñ·|³Q¥Î¨ìªºMATLABµ{¦¡®w¡^¡A´N¥i¥H±o¨ì¬ÛÃö¸ê°T¡C
MATLABµ{¦¡³]­p¡G¶i¶¥½g