9-3 �x�}���ƾǹB��

¯x°}ªº¥[´î»P¤@¯ë¯Â¶q¡]Scalar¡^ªº¥[´îÃþ¦ü¡A°ß¤@ªº­n¨D¬O¡G¬Û¥[©Î¬Û´îªº¯x°}¥²»Ý¨ã¦³¬Û¦Pªººû«×¡C­Yºû«×¤£¤@­P¡A«h MATLAB ·|²£¥Í¿ù»~°T®§¡A¨Ò¦p¡G

Example 1: 09-¯x°}ªº³B²z»P¹Bºâ/matrix12.mA = [12 34 56 20]; B = [1 3 2 4]; C = A + B C = 13 37 58 24

­Y­n¶i¦æ¯x°}»P¯Â¶qªº¥[´î­¼°£¡A¤@¯ëªº§@ªk¬Oª½±µ±N¯Â¶q®i¶}¨ÃÀ³¥Î¨ì¯x°}ªº¨C¤@­Ó¤¸¯À¡A½d¨Ò¦p¤U¡G

Example 2: 09-¯x°}ªº³B²z»P¹Bºâ/matrixAndScalarOperation.mA=[1 3 5]; fprintf('A = '); disp(A); fprintf('A+5 = '); disp(A+5); fprintf('A-3 = '); disp(A-3); fprintf('2*A = '); disp(2*A); fprintf('A/3 = '); disp(A/3); A = 1 3 5 A+5 = 6 8 10 A-3 = -2 0 2 2*A = 2 6 10 A/3 = 0.3333 1.0000 1.6667

Hint
¤W­z½d¨Òªº¨Ò¥~±¡ªp·|µo¥Í¦b¯Â¶q°£¥H¯x°}¡A¨Ò¦p 5/A¡A³o¤@Ãþ°£ªk±N¦b«áÄò³¹¸`°Q½×¡C

­Y±ý¶i¦æ¯x°}¬Û­¼¡A¥²»Ý½T»{²Ä¤@­Ó¯x°}ªºª½¦æ¼Æ¥Ø¡] Column Dimension¡^ ¥²»Ýµ¥©ó²Ä¤G­Ó¯x°}ªº¾î¦C¼Æ¥Ø¡]Row Dimension¡^¡A§_«hµLªk¶i¦æ¯x°}¬Û­¼¡AMATLAB ·|²£¥Í¿ù»~°T®§¡C¥H¤U¬O¤@­Ó¯x°}¬Û­¼ªºÂ²³æ½d¨Ò¡G

Example 3: 09-¯x°}ªº³B²z»P¹Bºâ/matrix13.mA = [1; 2]; B = [3, 4, 5]; C = A*B C = 3 4 5 6 8 10

¯x°}ªº°£ªk¡A±`ÂǥѤϯx°}©Î¸Ñ½u©Ê¤èµ{¦¡¨Ó¹F¦¨¡A¥i°Ñ¨£¥»®Ñ©n©f§@¡uMATLABµ{¦¡³]­p¡G¶i¶¥½g¡vªº²Ä¤»³¹¡u½u©Ê¥N¼Æ¡v²Ä¤@¸`¤Î²Ä¥|¸`¡C

¯x°}ªº¦¸¤è¹Bºâ¡A¥i¥Ñ¡u^¡v¨Ó¹F¦¨¡A¦ý¯x°}¥²»Ý¬O¤è°}¡A¨ä¦¸¤è¹Bºâ¤~¦³·N¸q¡A¨Ò¦p¡G

Example 4: 09-¯x°}ªº³B²z»P¹Bºâ/matrix14.mA = magic(3); B = A^2 B = 91 67 67 67 91 67 67 67 91

­Y¦b¡u*¡v¡A¡u/¡v¤Î¡u^¡v¤§«e¥[¤W¤@­Ó¥yÂI¡AMATLAB ±N·|°õ¦æ¯x°}¤º¡u¤¸¯À¹ï¤¸¯À¡v¡]Element-by-element¡^ ªº¹Bºâ¡A¨Ò¦p¡G

Example 5: 09-¯x°}ªº³B²z»P¹Bºâ/elByEl01.mA = [12; 45]; B = [2; 3]; C = A.*B % ª`·N¡u*¡v«e­±ªº¥yÂI D = A./B % ª`·N¡u/¡v«e­±ªº¥yÂI E = A.^2 % ª`·N¡u^¡v«e­±ªº¥yÂI C = 24 135 D = 6 15 E = 144 2025

¹ï©ó¤@­Ó½Æ¼Æ¯x°} z¡A¨ä¡u¦@³mÂà¸m¡v¯x°}¡]Conjugate Transpose¡^ ¥iªí¥Ü¦¨¯x°} z'¡A¨Ò¦p¡G

Example 6: 09-¯x°}ªº³B²z»P¹Bºâ/conjTranspose01.mi = sqrt(-1); % ³æ¦ìµê¼Æ z = [1+i, 2; 3, 1+2i]; w = z' % ¦@³mÂà¸m¡]ª`·N z «á­±ªº³æ¤Þ¸¹¡^ w = 1.0000 - 1.0000i 3.0000 + 0.0000i 2.0000 + 0.0000i 1.0000 - 2.0000i

­Y¥u·Q±o¨ì¥ô¦ó¯x°} z ªºÂà¸m¡]Transpose¡^¡A«h¥iªí¥Ü¦¨¯x°} z.'¡A¨Ò¦p¡G

Example 7: 09-¯x°}ªº³B²z»P¹Bºâ/transpose01.mi = sqrt(-1); % ³æ¦ìµê¼Æ z = [1+i, 2; 3, 1+2i]; w = z.' % ³æ¯ÂÂà¸m¡]ª`·N z «á­±ªº¥yÂI¤Î³æ¤Þ¸¹¡^ w = 1.0000 + 1.0000i 3.0000 + 0.0000i 2.0000 + 0.0000i 1.0000 + 2.0000i

­Y z ¬°¹ê¼Æ¡A«h z' ©M z.' ªºµ²ªG¬O¤@¼Ëªº¡C¡]¤@¯ë±`¥Çªº¿ù»~¡A·|§Ñ¤F¯x°} z ¥i¯à¬O½Æ¼Æ¡A¦]¦¹±N z¡¦ »~»{¬°¬O³æ¯Âªº¯x°}Âà¸m¡C¡^

¤@­Ó¦V¶q a ªº Lp-norm ¥i¥H©w¸q¬° $$ \|a\|_p = \left(\sum_i |a_i|^p \right)^{1/p} $$

·í p=2 ®É¡A¦¹§Y¬°¦V¶q a ªºªø«×¡A©ÎºÙ¼Ú¤óªø«×¡]Euclidean Length¡^¡C±ý¨D¤@¦V¶qªº Lp-norm¡A¥i¨Ï¥Î norm «ü¥O¡A¨ä¨Ï¥Î»yªk¦p¤U¡G

norm(x, p)

½d¨Ò¦p¤U

Example 8: 09-¯x°}ªº³B²z»P¹Bºâ/normVector01.ma = [3 4]; x = norm(a, 1) y = norm(a, 2) z = norm(a, inf) x = 7 y = 5 z = 4

Hint
§A¬O§_¥i¥HÃÒ©ú¤U¦C«íµ¥¦¡¡H
  • norm(a, 1)=$\sum_i |a_i|$
  • norm(a, inf)=$max_i |a_i|$

¤@­Ó¯x°} A ªº p-norm ¥i¥H©w¸q¦p¤U¡G $$ \|A\|_p = max_x \frac{\|Ax\|_p}{\|x\|_p} $$

MATLAB ªº norm «ü¥O¥ç¥i¥Î©ó­pºâ¯x°}ªº p-norm¡A¨Ò¦p¡G

Example 9: 09-¯x°}ªº³B²z»P¹Bºâ/normMatrix01.mA = [1 2 3; 4 5 6; 7 8 9]; norm(A, 2) ans = 16.8481

MATLAB ÁÙ¦³¬Û·í§¹¾ãªº¼Æ¾Ç¨ç¼Æ¤Î¤T¨¤¨ç¼Æ¡A³£¥i¥HÀ³¥Î©ó¦V¶q¤Î¯x°}¡C¥H¤U±N¼Æ¾Ç¨ç¼Æ¦Cªí¾ã²z¦p¤U¡G

¨ç¼Æ»¡©ú
abs(x) ¯Â¶qªºµ´¹ï­È©Î¦V¶qªºªø«×
angle(z) ½Æ¼Æ z ªº¬Û¨¤¡]Phase Angle¡^
sqrt(x) ¶}¥­¤è
real(z) ½Æ¼Æ z ªº¹ê³¡
imag(z) ½Æ¼Æ z ªºµê³¡
conj(z) ½Æ¼Æ z ªº¦@³m½Æ¼Æ
round(x) ¥|±Ë¤­¤J¦Ü³Ìªñ¾ã¼Æ
fix(x) µL½×¥¿­t¡A±Ë¥h¤p¼Æ¦Ü³Ìªñ¾ã¼Æ
floor(x) ¦aªO¨ç¼Æ¡A§Y±Ë¥h¥¿¤p¼Æ¦Ü³Ìªñ¾ã¼Æ
ceil(x) ¤ÑªáªO¨ç¼Æ¡A§Y¥[¤J¥¿¤p¼Æ¦Ü³Ìªñ¾ã¼Æ
rat(x) ±N¹ê¼Æ x ¤Æ¬°¤À¼Æªí¥Ü
rats(x) ±N¹ê¼Æ x ¤Æ¬°¦h¶µ¤À¼Æ®i¶}
sign(x) ²Å¸¹¨ç¼Æ¡]Signum function¡^¡G$sign(x)=\left\{\begin{matrix}-1, x<0\\0, x=0\\1, x>0\end{matrix}\right.$
rem(x,y) ¨D x °£¥Hyªº¾l¼Æ
gcd(x,y) ¾ã¼Æ x ©M y ªº³Ì¤j¤½¦]¼Æ
lcm(x,y) ¾ã¼Æ x ©M y ªº³Ì¤p¤½­¿¼Æ
exp(x) ¦ÛµM«ü¼Æ
pow2(x) 2 ªº«ü¼Æ
log(x) ¥H e ¬°©³ªº¹ï¼Æ¡A§Y¦ÛµM¹ï¼Æ
log2(x) ¥H 2 ¬°©³ªº¹ï¼Æ
log10(x) ¥H 10 ¬°©³ªº¹ï¼Æ

±`¥Îªº¤T¨¤¨ç¼Æ¤]¦Cªí¾ã²z¦p¤U¡G

¨ç¼Æ»¡©ú
sin(x) ¥¿©¶¨ç¼Æ
cos(x) ¾l©¶¨ç¼Æ
tan(x) ¥¿¤Á¨ç¼Æ
asin(x) ¤Ï¥¿©¶¨ç¼Æ
acos(x) ¤Ï¾l©¶¨ç¼Æ
atan(x) ¤Ï¥¿¤Á¨ç¼Æ
atan2(x,y) ¥|¶H­­ªº¤Ï¥¿¤Á¨ç¼Æ
sinh(x) ¶W¶V¥¿©¶¨ç¼Æ
cosh(x) ¶W¶V¾l©¶¨ç¼Æ
tanh(x) ¶W¶V¥¿¤Á¨ç¼Æ
asinh(x) ¤Ï¶W¶V¥¿©¶¨ç¼Æ
acosh(x) ¤Ï¶W¶V¾l©¶¨ç¼Æ
atanh(x) ¤Ï¶W¶V¥¿¤Á¨ç¼Æ

¦¹¥~¡AMATLAB ÁÙ¦³¤@¨Ç¨ç¼Æ¬O°w¹ï¦V¶q¤¸¯Àªº²Î­p¶q¦Ó³]­p¡A¨Ò¦p min¡]¨D¦V¶qªº·¥¤p­È¡^¡Bmean¡]¨D¦V¶qªº¥­§¡­È¡^µ¥¡A¦Cªí¾ã²z¦p¤U¡G

¨ç¼Æ»¡©ú
min(x) ¦V¶q x ªº¤¸¯Àªº³Ì¤p­È
max(x) ¦V¶q x ªº¤¸¯Àªº³Ì¤j­È
mean(x) ¦V¶q x ªº¤¸¯Àªº¥­§¡­È
median(x) ¦V¶q x ªº¤¸¯Àªº¤¤¦ì¼Æ
std(x) ¦V¶q x ªº¤¸¯Àªº¼Ð·Ç®t
diff(x) ¦V¶q x ªº¬Û¾F¤¸¯Àªº®t
sort(x) ¹ï¦V¶q x ªº¤¸¯À¶i¦æ±Æ§Ç¡]Sorting¡^
length(x) ¦V¶q x ªº¤¸¯À­Ó¼Æ
norm(x) ¦V¶q x ªº¼Ú¤ó¡]Euclidean¡^ªø«×
sum(x) ¦V¶q x ªº¤¸¯ÀÁ`©M
prod(x) ¦V¶q x ªº¤¸¯ÀÁ`­¼¿n
cumsum(x) ¦V¶q x ªº²Ö­p¤¸¯ÀÁ`©M
cumprod(x) ¦V¶q x ªº²Ö­p¤¸¯ÀÁ`­¼¿n
dot(x, y) ¦V¶q x ©M y ªº¤º¿n
cross(x, y) ¦V¶q x ©M y ªº¥~¿n

¨Ò¦p¡Asort «ü¥O¥i¹ï¦V¶q¤¸¯À¶i¦æ±Æ§Ç¡]Sorting¡^¡G

Example 10: 09-¯x°}ªº³B²z»P¹Bºâ/sort01.mx = [3 5 8 1 4]; [sorted, index] = sort(x) % ¹ï¯x°} x ªº¤¸¯À¶i¦æ±Æ§Ç sorted = 1 3 4 5 8 index = 4 1 5 2 3

¨ä¤¤ sorted ¬O±Æ§Ç«áªº¦V¶q¡Aindex «h¬O¨C­Ó±Æ§Ç«áªº¤¸¯À¦b­ì¦V¶q x ªº¦ì¸m¡A´«¥y¸Ü»¡¡Ax(index) §Yµ¥©ó sorted ¦V¶q¡C¥t¤@­Ó¦³½ìªº°ÝÃD¡G¦p¦ó¨Ï¥Î sort «ü¥O¥[¤W«e¨Ò¤¤ªº sorted ¤Î index ¨Ó¨D±o­ì¥ýªº¦V¶q x¡H¡]¦¹ÃD´N¯dµ¹¦U¦ìŪªÌ¥h½m¥\§a¡I¡^

¤W­z¦Cªíªº¨ç¼Æ¤j³¡¥÷¤]¾A¥Î©ó¯x°}¡A¥L­Ì¥u¬O±N¯x°}µø¬°¦æ¦V¶qªº¶°¦X¡A¨Ó³v¤@¹ï¦æ¦V¶q¶i¦æ¹Bºâ¡C¨Ò¦p¡G±ý§ä¥X¤@¯x°}³Ì¤j¤¸¯Àªº¦ì¸m¡A¥i¿é¤J¦p¤U¡G

Example 11: 09-¯x°}ªº³B²z»P¹Bºâ/max01.mx = magic(5); [colMax, colMaxIndex] = max(x) colMax = 23 24 25 21 22 colMaxIndex = 2 1 5 4 3

¨ä¤¤ colMax ¥Nªí¨C¤@ª½¦æªº³Ì¤j­È¡AcolMaxIndex «h¬O¨C¤@ª½¦æ¥X²{³Ì¤j­Èªº¦ì¸m¡C­Y­n¨D±o x ªº³Ì¤j¤¸¯Àªº¦ì¸m¡A¥i¿é¤J¦p¤U¡G

Example 12: 09-¯x°}ªº³B²z»P¹Bºâ/max02.mx = magic(5); [colMax, colMaxIndex] = max(x); [maxValue, maxIndex] = max(colMax); fprintf('Max value = x(%d, %d) = %d\n', ... colMaxIndex(maxIndex), maxIndex, maxValue);Max value = x(5, 3) = 25

¥Ñ¦¹¥i¥H¬Ý¥X¡A¯x°} x ªº³Ì¤j¤¸¯À§Y¬O maxValue¡A¦Ó¨äµo¥Í¦ì¸m¬° [colMaxIndex(maxIndex), maxIndex] = [5 , 3]¡C

Hint
­Y¥u­n§ä¥X¤@¯x°} x ªº³Ì¤j­È¡A¥i¿é¤J max(max)©Î¬O max(x(¡G))¡C


MATLABµ{¦¡³]­p¡G¤Jªù½g