<MakerFile 4.0K> Aa•ÿla ` ˜ d H H d ½ TableFootnote ] Ç _ Æ $ * à d 6 6 6 Footnote . * à 6 . ÌÌ / - Ð Ñ 2 TOC Heading logon ÌÌ ÌÌ :;,.É!? ff + @ e u l j " =Ò e ž =Ú k " EquationVariables =Ó f ¢ =Ô g ¤ @ =Õ h ! =× i ! =Ø u … w u ! þ v " ý ý <$lastpagenum> þ <$monthname> <$daynum>, <$year> ÿ "<$monthnum>/<$daynum>/<$shortyear> ;<$monthname> <$daynum>, <$year> <$hour>:<$minute00> <$ampm> "<$monthnum>/<$daynum>/<$shortyear> <$monthname> <$daynum>, <$year> "<$monthnum>/<$daynum>/<$shortyear> <$fullfilename>i <$filename>a <$paratext[Title]> <$paratext[Heading]> <$curpagenum> <$marker1> <$marker2> (Continued) Heading & Page Ò<$paratext>Ó on page <$pagenum> Page page <$pagenum> See Heading & Page %See Ò<$paratext>Ó on page <$pagenum>.! Table & Page 7Table <$paranumonly>, Ò<$paratext>,Ó on page <$pagenum> + (Sheet <$tblsheetnum> of <$tblsheetcount>) • • • l • | | Q Ž • • ‘ ’ “ } ~ • € • ƒ A } ~ • € • ™ Q P P P P Q l ari Ae @ u =Ô ¤ =Ø " w ! ý A l l l l l l ” ñ ‘ º ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ ¨ ¨ thn A> =Û = = G A B A = M = = = = < < = < < S n $ > e i n $ > e o m i =Ü =Ý =Þ =ß =à =á =â =ã =ä =å =æ =ç =è =é =ê =ë =ì =í S =î T = = = = = i u =ï =ð =ñ =ò =ó = =ô = r =õ = o =ö Q e =÷ = < =ø R p = Q = Q = = = = = = J = = = = - = N e r 7 o x p + e s | =ù =ú =û =ü =ý =þ =ÿ > > > > > > > > > > > = > ! = > " = # R i > > $ % & ' ( ) * + , . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B = N = = = O T T T = = L = = Q = = = N = = O : : : = N = O O : P € " ‘ n $ > e i n $ > e o m i > > > > > > > > > > > > > > > >> > >! >" ># >$ >% >& >' >( >) >* >+ >, >C = D E F G H = : a = = I J K L M N O P Q R S T U = = = = = R = = J J N = : >. T i u >/ >0 >1 >2 >3 r o e < p e r >4 >5 >6 >7 >8 >9 >: >; >< >= >> >? >@ V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ • € • ‚ : = N O : : N = = = O P P = = N = = = J E E = R = = = J J Q Q J J = R = = = = J Q Q Q J Q 7 o x p + e s | i P € " ‘ n $ > e i n $ > e o m i >A >B >C >D >E >F >G >H >I >J >K >L >M >N >O >P >Q >R >S >T >U >V >W >X >Y >Z >[ >\ >] >^ >_ >` >a >b >c >d >e >f >g >h >i >j >k >l >m ƒ Q „ … † ‡ ˆ Q Q N : : >n T i u >s >o >p >q >r ‰ Š ‹ Œ • Ž • • ‘ ’ “ ” • – — ˜ ™ š › œ • ž Ÿ ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ ¿ Ò Ó Ô Õ : = = = = = = = J Q Q Q Q J Q a a a J Q ^ ^ ^ ^ ^ J = R R Q R R R R R R R R R R R R R R R R R R R Q O Q = N r o e < p e r 7 o x p + e s | i P € " ‘ n $ > e i n $ > e o >t >u >v >w >x >y >z >{ >| >} >~ >• >€ >• >‚ >ƒ >„ >… >† >‡ >ˆ >‰ >Š >‹ >Œ >• >Ž >• >• >‘ >’ >“ >” >• >– >— >˜ >™ >š >› >œ >• >ž >Ÿ > >¡ >¢ >£ >¤ >¥ >¦ >§ >¨ >© Ö × Ø Ù J Q Q Q m i >ª >« >¬ >Ú Q Û Ü Ý Þ ß Q Q Q Q Q à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ Q ; ; ; ; ; O N Q Q Q K K K K K Q Q R = = < = J Q [ J Q [ J = R >® T i u >¯ >° >± >² >³ r o e < p e r 7 o x p + e s | i P € >´ >µ >¶ >· >¸ >¹ >º >» >¼ >½ >¾ >¿ >À >Á > >à >Ä >Å >Æ >Ç >È >É >Ê >Ë >Ì >Í >Î >Ï >Ð >Ñ >Ò >Ó = " >Ô = >Õ Q >Ö Q >× = >Ø = >Ù = >Ú Q ‘ >Û Q >Ü Q n >Ý Q $ >Þ J >ß Q > >à Q e >á J i >â Q >ã Q n >ä = $ >å = >æ J > >ç Q e >è Q o >é J m >ê R >ë = i >ì = >í = >î ! = T >ï " J >ð # Q i >ñ $ Q u >ò % Q >ó & Q >ô ' J r >õ ( C o >ö ) C e >÷ * C < >ø + C p >ù , C >ú - C e >û . C >ü / C >ý 0 C r >þ 1 = >ÿ 2 R ? 3 = 7 ? 4 = o ? 5 = x ? 8 = p ? 9 J + ? : Q e ? ; Q s ? < Q ? = Q ? > Q | ? ? Q ? @ Q ? A Q i ? B Q ? C Q ? D Q ? E Q P ? F Q ? G Q € ? H Q " ? I O ? J O ? K O ? L O ? M O ? N O ? O O ‘ ? P O ? Q O n ? R O $ ?- S N ? T O > ? U O e ?! V O i ?" W O ?# X O n ?$ Y O $ ?% Z O ?& [ O > ?' \ O e ?( ] O o ?) ^ O m ?* _ O ?+ ` O i ?, a O ?- b O ?. c O T ?/ d O ?0 e O i ?1 f O u ?2 g O ?3 h O ?4 i O r ?5 j O o ?6 k O e ?7 l Q < ?8 m Q p ?9 n Q ?: o N e ?; p = ?< q O ?= r O r ?> s O ?? t O ?@ u O 7 ?A v O o ?B w O x ?C x O p ?D y O + ?E z O e ?F { O s ?G | O ?H } O ?I ~ O | ?J • O ?K € O ?L • O i ?M ‚ O ?N ƒ O ?O „ O ?P … O P ?Q † O ?R ‡ N € ?S ˆ Q " ?T ‰ Q ?U Š Q ?V ‹ Q ?W Œ Q ?X • Q ?Y Ž Q ?Z • N ‘ ?[ • J ?\ ‘ Q n ?] ’ Q $ ?^ “ Q ?_ ” Q > ?` • Q e ?a – Q i ?b — N ?c ˜ J n ?d ™ Q $ ?e š Q ?f › Q > ?g œ Q e ?h • Q o ?i ž N m ?j Ÿ Q ?k Q i ?l ¡ Q ?m ¢ Q ?n £ Q T ?o ¤ Q ?p Ý = i ?q ß R u ?r à < ?s á = ?t â = r ?u ã = o ?v ä = e ?w å = < ?x æ = p ?y ç R ?z è J e ?{ é J ?| ê Q ?} ë J r ?~ ì Q ?• í Q ?€ î J 7 ?• ï J o ?‚ ð Q x ?ƒ ñ Q p ?„ ò J + ?… ó J e ?† ô Q s ?‡ õ Q ?ˆ ö J ?‰ ÷ J | ?Š ø Q ?‹ ù Q = ?Œ i ?• = ?Ž = ?• = = = = R = N N N = = = = = = = - < = = ! N " N # = $ N % N & N ' N ( N ) N * = + = P € " ‘ n $ > e i n $ > e o m i ?• ?‘ ?’ ?“ ?” ?• ?– ?— ?˜ ?™ ?š ?› ?œ ?• ?ž ?Ÿ ? ?¡ ?¢ ?£ ?¤ ?¥ ?¦ ?§ ?¨ ?© ?ª ?« ?¬ ?, = . / 0 1 = = = = < 3 4 5 7 8 = > ? @ A B C D E F R = = = D = H = = = H I I = = ?® T i u ?¯ ?° ?± ?² ?³ r o e < p e r 7 o ?´ ?µ ?¶ ?· ?¸ ?¹ ?º ?» ?¼ ?½ ?¾ ?¿ ?À ?Á ? M N O P Q R S T U V W X ` c d f g h o q r u w | } ~ • € ‚ ƒ „ … † ‰ N N N N N N N J Q Q Q Q = Q J ^ N : J Q Q Q Q Q Q Q C C N N Q Q Q J x p + e s | i P € " ‘ n $ > e i n ?à ?Ä ?Å ?Æ ?Ç ?È ?É ?Ê ?Ë ?Ì ?Í ?Î ?Ï ?Ð ?Ñ ?Ò ?Ó ?Ô ?Õ ?Ö ?× ?Ø ?Ù ?Ú ?Û ?Ü ?Ý ?Þ ?ß ?à ?á ?â ?ã m - š 9 d ?ä m Ñ § • | o d ?å n Ñ i ?- • } = d ?æ o Ñ ° p { u ^¨ ?ç p Ò r H “Ó 3Kº ^¨ H R H ^¨ ?è q Ò = H qùv ?ü^¨ H z·¸ H Single Line r H “Ó 3Kº q o R ¡ p r o z·¸ ¡ H ' Footnote < H ´ qùv ?ü- ?é r Ó q t o = s s • • ^¨ ?ë t Õ r u o H §ùv D£f ^¨ H °·¸ H °·¸ ¡ Double Line H º Footnote x ?ê s × r s Ô N ™ H §ùv D£f ?ì u Ó t x o P v w Double Line ?Ó Ô Q Ô • C n ?ï x Ó u z o ?Ò ?í v Ö Ô Ô H † w u ?î w Ö v Ô Ô u ?× Û Ô Q Single Line y y Ô ?ð y Ö x Ô § Ô H Z ´ ?ñ z Ó x { o TableFootnote= ^¨ ?ò { Ó ° E¸¾ GX- RŸb ^¨ E¸¾ P o E¸¾ TableFootnoteç E¸¾ GX- RŸb z o P o ¡ 6 6 ø ¬ ?ó | Ó € m 6 • ñ ™ = 6 6 ø ¬ ?è 6 ø ¬ ` ?ô } Ó ~ n n 6 Ž 6 ø ¬ = ò ™ 6 ` ø ?õ ~ Ó • } n 6 • ó ›^¨ 6 ø ªª Page j 11 k ø ?ö • Ó ~ n ªª UU h 6 • ô › w 6 ø x öUV ø ?÷ € Ó • | m ªª ªª UU ` 6 ‘ õ › 6 öUV ø ?× ø ?ø • Ó € m ªª ªª UU ` 6 ø ’ ö › z ªª d ªª ?ù ‚ Ñ UU ` n ƒ § ?ð 6 6 ø ¬ ?ú ƒ Ó œ ‚ § 6 “ ÷ ™ 6 ø ¬ … 0 { ` ` á ™ n $ ` â ™^¨ 2 ` ã ™ ° @ ™¸¾ o N ™eF n \ ™ j ™ x ™ † ™ è ” ™ = ª ø • 6 ¼ ù ™ Ê ú ™ ` ` ` ` ` ` ` ` Introduction to Matlab ` ` = Ø ü ™ ` æ û ™?õ Ó ô ` ` å ™ ` æ ™ ` ª # 1 * + , . ô ™ªª ™ , ™ : ™ H ™ V ™ d ™ r / ™ € 0 ™ Ž ` ` ` ` ` ` ` ` ` ™ œ ™ × ª ý ™ ¸ þ ™ Æ õ ™ U Ô ™ n â ™ ð ™ þ ™ ` h h July 18, 1995 i ` Thomas D. Citriniti ` Core Engineering ` !Rensselaer Polytechnic Institute ` Troy, New York 12180 ` ` ` ™ ` ™ ÷ ( ` ™ á 6 ` ™ â D ` ™ ã R ™ bThis tutorial was written to introduce MATLAB and provide examples to use in conjunction with the ` ™ kPreface program. It assumes the user has sufficient familiarity with the operating system to logon, create n @ ™ files, and change directories. û | ÿ ™ å Š ™ æ ˜ ` ` ` ™ ¦ ` ä ™ # d ?û „ Ñ … … , 6 6 ø ¬ ?ü … Ó „ 6 6 “ 5 ™ UT ø ¬ ƒ ‡ 0 UT ªª ` ` - 1.1 Accessing MATLAB %ÿþ ` ™Ju 3ÿþ ™ _Once a login session has been established and a UNIX windows has been opened, two commands are !Re Aÿþ @ ™ic required to start MATLAB: Oÿþ ` ™rk 1 ]ÿþ ` ™ % setup matlab-4.0a kÿþ ` ™ yÿþ ` ™ % matlab ‡ÿþ ` ™ á •ÿþ ™ â fThis begins execution. Note a change in prompt (from % to >>). On line help is available for most MAT £ÿþ @ ™e !LAB commands. To invoke it type: ±ÿþ ` ™pr a ¿ÿþ ` ™us ¨ >> help n Íÿþ ` ™ t o Ûÿþ ` ™ l 8which provides a list of help topics to choose from, or re éÿþ ` - ™ ÷ÿþ ` ¨ >> help topic ˜ ÿþ ` ™ ÿþ ` ! ™ # Jwhich invokes a help file for the topic specified. Try plot ™ . !ÿþ ` " ™?ü Ó 1UR UT ªª ` # 2.1 Entering Matrices ?ÿü ` ¨ help ™ Mÿü ™ gMatrices can be entered into matlab from the command line or thorough data files, we will be doing all ssi [ÿü @ ™is dour work from the command line. Here is how to create a 3x3 matrix and assign it to the variable A. TL iÿü ` $ ™ k wÿü ` % ¨ >> A = [ 1 2 3; 4 5 6; 7 8 9 ] …ÿü ` & ™ÿþ “ÿü ` ' ™at 2This produces the following response from MATLAB: ¡ÿü ` ( ™n. t ¯ÿü ` ) ¬pt A = ½ÿü ` * ¬el 1 2 3 lab Ëÿü ` + ¬ÿþ 4 5 6 @ Ùÿü ` , ¬. 7 8 9 it çÿü ` - ™ õÿü ` . ™ \Note that MATLAB is case sensitive. Thus, when using variables, ÒAÓ is not the same as ÒaÓ. h ÿü ` 0 ™se o ÿü 1 ™ ^Random numbers and matrices. RAND(N) is an N-by-N matrix with random entries. RAND(M,N) is an ÿü 1 ™he bM-by-N matrix with random entries. RAND(A) is the same size as A. RAND with no arguments is a sca -ÿü @ 1 ™ri 4lar whose value changes each time it is referenced. ic ;ÿü ` 5 ™in m Iÿü ` 6 ¨ma >> A = rand(3,2) Wÿü ` 7 ™l d eÿü ` 8 ™ ¬ A = s sÿü ` 9 ¬e m •ÿü ` : ¬ho 0.2342 0.3243 ma •ÿü ` ; ¬ t 0.1334 0.1212 TL •ÿü ` < ¬ 0.8656 0.4543 ¤ ¨ d ?ý † Ñ ‡ ‡ $ 6 7 ¬ ?þ ‡ Ó † $ “ > ¨ 6 7 ¬ … ‰ 0 ` >> A(3,2) ` * ` ? ™ÿü $ ` @ ¬ 6 ans = 2 ` A ¬ 7 9 @ ` B ¬ 0.4543 ÿü N ` C ™No t \ D ™ s wOnce a matrix has been assigned to variable A, it is stored for theduration of the MATLAB session, or until you assign num j @ D ™ R 7new values to A. To clear A of any value, use clear A: is x ` G ™ 1 e † ` H ™th >> clear A s. ” ` I ™me z ¢ ` J ™no &To empty all variables at once, type: ° ` K ™ch e ¾ ` L ™re >> clear Ì ` M ™in m ÛUT UT ªª ` N -ma 3.1 Matrix operations éÿþ ` O ™ d ü ÷ÿþ P ™ rWhile matrix operations act upon an entire matrix, MATLABÕs array operators act upon the individual elements of a ÿþ @ P ™ 0 /matrix. For example, using A and B defined as: ÿþ ` 3 ™ ‡ !ÿþ ` 4 ™ /ÿþ ` S ¨ Ó >> A = [ 1 2; 3 4 ] =ÿþ ` T ™ ‰ ¬ A = Kÿþ ` U ¬ 1 2 Yÿþ V ¬ gÿþ W ™ uÿþ X ¨ ƒÿþ Y ¬ 0 ü ‘ÿþ Z ¬No Ÿÿþ [ ¬On t -ÿþ \ ¨ne ` 3 4 ` ` >> B = [ 5 6; 7 8 ] ` B = ` 5 6 ` 7 8 ` >> C = A * B »ÿþ ` ] ™th r Éÿþ ` ^ ™B )produces the Matrix operation result of: ×ÿþ ` _ ™es åÿþ ` ` ¬ny C = óÿþ ` a ¬ F 19 22 or A(1,1)*B(1,1)+A(1,2)*B(2,1) A(1,1)*B(1,2)+A(1,2)*B(2,2) ÿþ ` b ¬ G 43 50 or A(2,1)*B(1,1)+A(2,2)*B(2,1) A(2,1)*B(1,2)+A(2,2)*B(2,2) ¾ ÿþ ` c ™ > where ÿþ ` d ™in m +ÿþ ` e ¨ma >> C = A .* B ati 9ÿþ ` f ™ O d Gÿþ ` g ™ P (produces the Array operation result of: en Uÿþ ` h ™BÕ r cÿþ ` i ©up ¬ C = v qÿþ ` j ¬a ' 5 12 or A(1,1)*B(1,1) A(1,2)*B(1,2) , u •ÿþ ` k ¬ed ( 21 32 or A(2,1)*B(2,1) A(2,2)*B(2,2) •ÿþ ` l ™ ›ÿþ ` ™[ ; d ?ÿ ˆ Ñ þ ‰ ‰ ÿþ 6 6 ø ¬ @ ‰ Ó ˆ 6 ‡ ‹ 0 UT UT ªª ` m - 0 ,4.1 Statements, expressions, and variables. ÿþ ` n ™ÿþ %ÿþ ` o ™C NThe semicolon (;) following a statement will suppress printing of the result. 3ÿþ ` p ™ÿþ Aÿþ ` q ©ÿþ >> A = [ 1 2; 3 4 ] Oÿþ ` r © 1 ]ÿþ ` ©(1 ¬ A = B kÿþ ` s ¬2) 1 2 * yÿþ ` t ¬ 3 4 ‡ÿþ ` ¤,1 ( •ÿþ ` u © >> A = [ 1 2; 3 4 ]; £ÿþ ` v © >> > ±ÿþ ` w ™ d ÁUR UT ªª ` x 5.1 Matrix Building Functions. Ïÿü ` y ™ÿþ Ýÿü ` z ™uc KAll zeros. ZEROS(N) is an N-by-N matrix of zeros. ZEROS(M,N) is an M-by-N ©up ëÿü ` { ™ ?matrix of zeros. ZEROS(A) is the same size as A and all zeros. ùÿü ` | ™r , ÿü ` } ©(2 >> A = zeros(2,3) ` l ÿü ` ~ ¬ A = #ÿü ` • ¬ 0 0 0 ˆ Ñ 1ÿü ` € ¬ 0 0 0 ?ÿü ` • © >> A = zeros(3) Ó Mÿü ` ‚ ¬ A= “ 6 ø ¬ [ÿü ` ƒ ¬ 0 0 0 iÿü ` „ ¬ m 0 0 0 St wÿü ` … ¬on 0 0 0 ria …ÿü ` † ¨ >> A = rand(3) “ÿü ` g ©se o ¡ÿü ` ‡ ¬a A= men ¯ÿü ` E ¬in 0.3245 0.6457 0.7324 ½ÿü ` ˆ ¬ÿþ 0.4734 0.2333 0.2168 [ Ëÿü ` ‰ ¬ 0.1205 0.3913 0.9573 Ùÿü ` h ¤ B þ çÿü ` Š ™ 1 * õÿü ` ‹ ™ PIf V is a row or column vector with N components, DIAG(V,K) is a square matrix ÿü ` Œ ™ > Mof order N+ABS(K) with the elements of V on the K-th diagonal. K = 0 is the ÿü ` • ™ÿþ Mmain diagonal, K > 0 is above the main diagonal and K < 0 is below the main O ÿü ` Ž ™N Odiagonal. DIAG(V) simply puts V on the main diagonal. (note: Your results will ze -ÿü ` • ™ Cdiffer since the rand function returns an array of randum results) ` ~ ;ÿü ` • ™ Iÿü ` ‘ © Ñ >> X = diag(A) Wÿü ` R © eÿü ` ’ ¬ze X = Ó sÿü ` “ ¬ 0.3245 ÿü •ÿü ` ” ¬ 0 0.2333 ÿü •ÿü ` • ¬ 0 0.9573 ÿü •ÿü c ¤ 0 0 ` d @ Š Ñ o ÿü 6 ‹ ‹ 6 ø ¬ @ ‹ Ó Š n 6 6 ø ¬ ‰ • “ 1ÿþ – ©0. >> X = diag(diag(A)) ` Q ©13 . $ ` — ¬ X = B 2 ` ˜ ¬ Š ` 0.3245 0 0 @ ™ ¬ i ` 0 0.2333 0 um N š ¬mp ` 0 0 0.9573 ,K \ ` F ¤ix j ` › © > - >> B = [ A, zeros(3,2);zeros(2,3), eye(2) ] h x ` d © = i † ` œ ¬ B = þ ” ` • ¬ > 0.3245 0.6457 0.7324 0 0 an ¢ ` ž ¬he 0.4734 0.2333 0.2168 0 0 Odi ° ` Ÿ ¬mp 0.1205 0.3913 0.9573 0 0 l. ¾ ` ¬s 0 0 0 1.0000 0 Ì ` ¡ ¬in 0 0 0 0 1.0000 n Ú ` f ¤of n è ` ¢ © ¬ >> © ö ` o © ‘ Ñ / ™ gTRIU(X) is the upper triangular part of X. TRIU(X,K) is the elements on and above the K-th diagonal of 0 @ / ™ fX. K = 0 is the main diagonal, K > 0 is above the main diagonal and K < 0 is below the main diagonal. ` Ô ™ . ` Õ ¨ >> a = rand(5),b = triu(a) < ` Ö © J ` × ¬ – a = > X ` Ø ¬) f ` Ù ¬ . $ 0.9103 0.3282 0.2470 0.0727 0.7665 t ` Ú ¬0 $ 0.7622 0.6326 0.9826 0.6316 0.4777 um ‚ ` Û ¬mp $ 0.2625 0.7564 0.7227 0.8847 0.2378 • ` Ü ¬ > $ 0.0475 0.9910 0.7534 0.2727 0.2749 ey ž ` Ý ¬ $ 0.7361 0.3653 0.6515 0.4364 0.3593 þ ¬ ` Þ ¬ > 0 º ` ß ¬4 b = n È ` à ¬he 0 Ö ` á ¬8 ( 0.9103 0.3282 0.2470 0.0727 0.7665 13 ä ` â ¬ # 0 0.6326 0.9826 0.6316 0.4777 Ì ò ` ã ¬ 0 - 0 0 0.7227 0.8847 0.2378 ` ä ¬ 0 0 0 0.2727 0.2749 ` å Ñ R æ n ç ¬ 0 0 0 ¬ t * ¨RI >> a == b el 8 è ¬e F é ¬ 0 ans = T ê ¬ i h b ë ¬ > 1 1 in p ì ¬0 0 1 di ~ í ¬ 0 0 Œ î ¬a 0 0 (a š ï ¬ Ö 0 0 0 ¨ ð ¬ ¤ d 0 ` 0.3593 ` ` ` ` ` 1 ` 1 ` 1 ` 0 ` 1 1 1 1 1 1 1 1 0 1 ` @ Œ Ñ . • • 66 6 6 ø ¬ @ • Ó Œ 6 6 ø ¬ ‹ • “ 00. UT UT ªª ` ò - 0 6.1 Scalar functions. ÿþ ` ó ™10 7 %ÿþ ` ô ™ey iScalar functions are math functions that operate on a single value at a time throughout the whole array. b 3ÿþ ` ö ™ à e Aÿþ ` ÷ © á " >> a = [ 2*pi 3*pi/2 pi pi/2 0 ] Oÿþ ` q ¬ ]ÿþ ` ø ¬32 a = 2 kÿþ ` ù ¬ 6.2832 4.7124 3.1416 1.5708 0 227 yÿþ ` r ¬ ‡ÿþ ` ú © >> sin(a) .27 •ÿþ ` u ¬ å Ñ £ÿþ ` û ¬35 ans = ±ÿþ ` ü ¬ ! -0.0000 -1.0000 0.0000 1.0000 0 ¿ÿþ ` w ¬ Íÿþ ` ý © a >> Ûÿþ ` þ ™ i h ëUR UT ªª ` ÿ - > 7.1 Vector functions. ùÿü ` 1 ™ ÿü ™ lVector functions are math functions that operate on a vector, a vector is a single row array. MAX(X) is the ÿü ™ dlargest element in X. For matrices, MAX(X) is a vector containing the maximum element from each col @ #ÿü ™ dumn. [Y,I] = MAX(X) stores the indices of the maximum values in vector I. MAX(X,Y) returns a matrix 1ÿü @ ™ Jthe same size as X and Y with the largest elements taken from X or Y. £ ?ÿü ` ‚ ¨ou u Mÿü ` ƒ ¨ b >> a = [ 1 2 3; 4 5 6; 7 8 9 ] [ÿü ` Ò ¬[ i iÿü ` ¬] a = wÿü ` ¬ÿþ ` ø …ÿü 1 2 3 ` ¬ ¬ 4 5 6 “ÿü ` ¬.1 7 8 9 8 0 ¡ÿü Ó ¬ r ¯ÿü ` ` š ú >> max(a) (a) ½ÿü ` ¬ u å Ëÿü ` ¬ û ans = s = Ùÿü ` ¬ ü 7 8 9 .00 çÿü ` ¬1. 0 õÿü ` š w >> max(max(a)) ÿü ` ¬ÿþ ÿü „ ¬UR ` ÿ ÿü ` ans = ` ¬un s. -ÿü … ¤ 1 ;ÿü 9 ` ™ gFor vectors, SUM(X) is the sum of the elements of X. For matrices, SUM(X) is a row vector with the sum th Iÿü @ ™ 2over each column. SUM(DIAG(X)) is the trace of X. Wÿü ` ™g eÿü ` ©om sÿü š >> sum(a) ` ¬ [ ] •ÿü ` † ¬he ans = of •ÿü ` ¬ i 12 15 18 •ÿü ` © m i d @ Ž Ñ X • • t em 6 6 ø ¬ @ • Ó Ž ‚ 6 “ 6 ø ¬ 0 4 UT • ‘ UT ªª ` -ÿü ÿþ 8.1 Matrix functions. ` ™ a %ÿþ ` ™ÿþ OMatrix functions are math functions that are specific to matrix manipulations. 3ÿþ ` ™ÿü bEigenvalues and eigenvectors. EIG(X) is a vector containing the eigenvalues of a square matrix X. Aÿþ ` ! ™00 ü Oÿþ ` " 0 š w | ü © >> y = eig(a) ]ÿþ ¬ kÿþ ` ` # ¬ y = yÿþ ` $ ¬ = ‡ÿþ 16.1168 ` % ¬. -1.1168 •ÿþ ` & ¬ £ÿþ } ¬(X s ±ÿþ -0.0000 ` ` ' ©em >> [U,D] = eig(a) es, ¿ÿþ ` ~ ¬ec Íÿþ ` ( ¬ÿü Ûÿþ U = ` ) ¬h éÿþ 0.2320 0 .7858 ` 0.4082 * ¬ ÷ÿþ 0.5253 0.0868 -0.8165 ` + ¬su [ ÿþ • ¬ † e ÿþ 0.8187 -0.6123 ` ` 0.4082 , ¬ !ÿþ D = ` - ¬ÿü 16.1168 i /ÿþ ` 0 0 . ¬ =ÿþ 0 -1.1168 ` 0 / ¬ 6 Kÿþ € ¬ Ó Yÿþ 0 0 -0.0000 ` ` 0 ¬ gÿþ >> ` 1 ™ uÿþ ` 5 ™ªª …UR UT ªª ` 2 -un $9.1 Submatrices and colon notation. “ÿü ` 3 ™ix n ¡ÿü 4 ™nc gMatrices can be referenced as whole matrices or submatrices within larger matrices by way of colon ref IG( ¯ÿü 4 ™ta ierences. Colon notation can be used as an implied for loop with the syntax from:step:to which define the w ½ÿü @ 4 ™ Iloop contraints. (the transposed) Ëÿü ` ¬ Õ ™ denotes the matrix should be 8 ™ þ Ùÿü ` 9 © X çÿü >> x = [ 0.0:0.1:2.0 ]Õ ` : ¬ ' õÿü ` ; ¬a) þ ÿü x = ` < ¬ þ ÿü ` = ¬ U Ûÿþ ÿü 0 ` > ¬ 0 78 -ÿü 0.1000 ` ? ¬ ;ÿü 0.2000 ` @ ¬-0 ÿþ Iÿü 0.3000 ` A ¬ 0 12 Wÿü 0.4000 ` B ¬ † eÿü 0.5000 ` C ¬ , 0.6000 sÿü ` D ¬ÿü •ÿü 0.7000 ` E ¬ •ÿü 0.8000 ` F ¬ÿþ 0.9000 / •ÿü ` G ¬00 1.0000 d @ • Ñ ÿþ 6 ‘ ‘ 6 ø ¬ @ ‘ Ó • . 6 “ 6 ø ¬ • “ 1 ` H ¬ nc 1.1000 ` I ¬re s $ 1.2000 ` J ¬su wi 2 1.3000 ` K ¬ 1.4000 c @ ` L ¬ ta N 1.5000 ` M ¬ot be \ 1.6000 ` N ¬d it j 1.7000 ` O ¬st h x 1.8000 ` P ¬ † 1.9000 ` Q ¬ ( ™ ” 2.0000 ` R ¬ix ¢ ` S ¨ >> y = sin(x) ™ ° ` T ¬ 9 ¾ ` U ¬1: X Ì y = ` V ¬ ' 0 õÿü Ú ` W ¬ x è 0.0998 ` X ¬ÿü 0.1987 = ö ` Y ¬ 0 0.2955 ` Z ¬ 0.3894 ` [ ¬ -0 0.4794 ` \ ¬ 0 . 0.5646 ` ] ¬ < 0.6442 ` ^ ¬ 0.7174 , J ` _ ¬ ÿü X 0.7833 ` ` ¬ f 0.8415 ` a ¬ ÿþ t 0.8912 ` b ¬ 00 ‚ 0.9320 ` c ¬ • 0.9636 ` d ¬ ž 0.9854 ` e ¬ÿþ ¬ 0.9975 ` f ¬ 0.9996 . º ` g ¬ È 0.9917 ` h ¬ 0.9738 H Ö ` i ¬ 0.9463 I ä ` j ¬ 0.9093 J ò ` k ¬ ` o ¨ >> [x y] ` p ™00 ¬ ans = ` q ¬be * 0 0 ` r ¬00 ` 0.1000 0.0998 O 8 ` s ¬ 1 F 0.2000 0.1987 ` t ¬ ™ T 0.3000 0.2955 ` u ¬ix ` 0.4000 0.3894 S b ` v ¬x) ` 0.5000 0.4794 T p ` w ¬ Ì ~ 0.6000 0.5646 ` x ¬ 0 ` 0.7000 0.6442 W Œ ` y ¬ 0 š 0.8000 0.7174 ` z ¬ 0 ¨ 0.9000 0.7833 ` { ¬ 1.0000 0.8415 d @ ’ Ñ “ “ ] 6 “ Ó 6 ø ’ ¬ @ 7 6 “ 6 ø ¬ ‘ • 1 ` | ¬ ¬ 1.1000 0.8912 ` } ¬ 932 $ 1.2000 0.9320 ` ~ ¬ c • 1.3000 0.9636 2 ` • ¬ 0 @ 1.4000 0.9854 ` € ¬ ¬ N 1.5000 0.9975 ` • ¬ 991 \ 1.6000 0.9996 ` ‚ ¬ h Ö 1.7000 0.9917 j ` ƒ ¬ 0 x 1.8000 0.9738 ` „ ¬ J ¬ 1.9000 0.9463 † ` … ¬ o 2.0000 0.9093 ” ` † ¬ ¢ ` ‡ ¨ >> a(1:3,2) ° ` ˆ ¬00 ¾ ` ‰ ¬ ` ans = s Ì ` Š ¬87 Ú ` ‹ ¬ 300 è 2 ` Œ ¬ ` 5 u ö ` • ¬94 b 8 ` Ž ¬ 0 ` • ¨ >> a(1:3,3) 0 ` • © . ` ‘ ¬00 ` ans = W < ` ’ ¬ J ` “ ¬ 3 X ` ” ¬0. 0 f 6 ` • ¬ 000 t 9 ` – ¬ ‚ ` — ¨ >> a(1:2,2) • ` ˜ © ž ` ™ ¬ ans = ¬ ` š ¬ º ` › ¬ 2 È ` œ ¬ ¬ Ö 5 ` • ¬ ä ` ž ¨ 1 >> a(2:3,2) 2 ò ` Ÿ ¬ c ` ¬ ` ans = • ` ¡ ¬54 @ 5 ` ¢ ¬ 1 0. * 8 ` £ ¬ 8 ` ¤ ¬96 F >> ` l ¤ 1 0 T ` m ¤ b ` n ¤0. 8 p 2 ¤ ` „ J ~ ¦ ¤ Œ ¿ ¤ 0 š ñ ¤ ¨ ‰ © ` ` ` ` d ” Ñ @ 0 • • a 6 6 ø ¬ @ • Ó ” 6 6 ø ¬ ž ž “ — “ " UT UT ªª ` ç - 8 10.1 Output Format. 0 ÿþ ` Ý ™ • %ÿþ ` è © >> a = 1 3ÿþ ` é © a Aÿþ ¬ a = ` ê ¬ 1 ¬ Oÿþ ` ë © “ >> a = 1.2 ]ÿþ ` ì ¬ 6 kÿþ a = ` í ¬ 9 yÿþ 1.2000 ` î © > ‡ÿþ >> format short ` ï © >> a = 1.2 •ÿþ ` ð ¬ = £ÿþ a = ` ñ ¬ š 1.2000 ±ÿþ ` ò © 2 >> format long œ ¿ÿþ ` ó © >> a = 1.2 Íÿþ ` ô ¬ 1 ( Ûÿþ a = ` õ ¬ éÿþ 1.20000000000000 ` ö © • >> format short e 5 ÷ÿþ ` ÷ © ¢ >> a = 1.2 ÿþ ` ø ¬ a = ÿþ ` ù ¬ !ÿþ 1.20000 ` ¤ /ÿþ ` ¤ ?UR UT ªª ` 11.1 Graphics. ~ Mÿü ` ™ [ÿü ` ™ ¨ >> x = -4:0.01:4; ¨ iÿü ` ¨ >> y = sin(x); wÿü ` ¨ , >> plot(x,y), title(ÔExample Sin curve.Õ); …ÿü ` ¨ >> “ÿü ` ™ ž ¡ÿü h ™ e T y • ` - ™10 Fig1: Section 13 example plot. ` Ý ‡ • ™ è • • ™ÿþ £ • = ™ a a – Ñ ` ` ` d @ ë — — ÿþ 6 6 ø ¬ @ — Ó – 6 6 ø ¬ ¢ ¢ • ™ “ > £ ™ ` ` ¨ >> x = -1.5:0.01:1.5; ð ! ¨ ` >> y = exp(-x.^2); $ ` " ¨ 2 >> plot(x,y,Õ--gÕ) ÿþ 2 ` $ ¨ > >> xx = -2:.1:2; @ ` % ¨ ( >> yy = xx; õ N ` & ¨00 >> [x,y] = meshdom(xx,yy); > \ ` ' ¨ 5 >> z = exp(-x.^2 - y.^2); 1. j ` ( ¨ ø ' >> mesh(z), title(ÔNeat mesh plot.Õ); 0 x h ) ¨ >> © f N(õ ` 1 ™UT Fig2: Section 13 example plot. Mÿü ]~I UT ªª ` 3 ü ¤ > ¥ ü § ¨ © , ª v « ¬ ® m~G }~E •~C - > •~A -~? -(x ½~= -n Í~; Ý~9 í~7 ý~5 - • UT ªª ` UT ªª ` UT ªª ` UT ªª ` UT ªª ` UT ªª ` UT ªª ` UT ªª ` UT ªª ` UT ªª ` ~3 UT ¯ -: t ~1 ° -t. Ý -~/ ± è =~² -ÿþ M~+ ³ - a a ]~) ´ - ªª ` m~' µ - ªª ` UT UT ªª ` UT ªª ` UT ªª ` UT ªª ` UT ªª ` ë }~% ¶ -ÿþ •~# · - UT ªª ` UT ªª ` •~! ¸ - UT ªª ` d @ ˜ Ñ > ™ ™ > 6 $ ø Ð @ ™ Ó ˜ 6 “ $ ø Ð ¤ ¤ — $ > UT UT ªª ` ¹ -ÿþ +An additional example of function plotting UR UT ªª ` ß ®yy x 'ÿü 4 ™ & mThe First Derivative test for Relative Extrema. This example will use the derivative of a function to locate > 5ÿü @ 4 ™Ne Yits relative maximum points. The theorem for testing for relative extrema is defined as: Cÿü ` 7 ™ÿü I Qÿü 8 ™ÿü ~ If ¦ f ™ has a relative minimum or relative maximum when x = c, then either (i) ¦ fÕ(c) ™ = 0 or (ii) ¦ fÕ(c) ™ is _ÿü 8 ™~; tundefined. That is, c is a critical number of ¦ f ™ . Based on this theorem, locate all relative extrema for the ~1 mÿü @ 8 ™ Ý function: {ÿü ` = ™UT ª ‰ÿü ` > ™UT 1 ¦ f(x) = 2x § 3 ¦ - 3x § 2 ¦ - 36x + 14 ª —ÿü ` ? ™UT ª ¥ÿü ` @ ™UT HSolution: By setting the derivative of ¦ f ™ equal to zero, we have ³ÿü ` A ™ ™ Áÿü ` B ™ & ¦ fÕ(x) = 6x ¯ 2 ¦ -6x - 36 = 0 Ïÿü ` C ¦ 6(x ¯ 2 ¦ - x - 6) = 0 UT Ýÿü ` D ¦dd 6(x - 3)(x + 2) = 0 ëÿü ` E ™UR T ùÿü F ™ÿü ~ Since ¦ f ™ Õ is defined for all real numbers, the only critical numbers of ¦ f ™ are -2 and 3. To test this proof we ÿü F ™Ne mcan create matrices to represent our function and an interval to operate on, the interval should include the ü ÿü F ™ 8 iabove stated critical numbers. To create the interval using arrays, use the colon notation: (remember to #ÿü @ F ™™ ;use the Array operator notation (.^) for the powers of x). nu 1ÿü ` ™ B d ?ÿü M ¨lo >> m Mÿü N ¨ 0 >> ÿü [ÿü O ¨ 5 >> iÿü P ¨ÿü >> grid; wÿü Q ¨ s >> f …ÿü R ¨we >> “ÿü S ¨ 0 ¡ÿü T © 2 ¯ÿü U ¬x 2) ½ÿü V ¬ E 4 >> in Ëÿü W ¬mb n Ùÿü X ¬ s çÿü ` ™ÿü Âûã ` X = -4.0:.1:5.0; ` FofX = 2.0*X.^3 - 3.0*X.^2 - 36.0*X + 14.0; ` plot(X,FofX),title(ÔTest for Relative ExtremaÕ); ` ` [Y,Max_I) = max(FofX); ` [Y,Min_I) = min(FofX); ` >> Relative_Maximum = [ X(Max_I) FofX(Max_I) ] ` ¬ Relative_Maximum = ` -2 58 ` ¨ Relative_Minimum = [ X(Min_I) FofX(Min_I) ] ` Relative_Minimum = ` 3.0000 -67.0000 h g ` à ™te 8Figure 3: Plot of results to Test for Relative Extrema. ra H ™ Ô @ œ Ø ƒ • ‚ ü H ™ Ô ™ÿü H ™ ™ Q « ¹ @ • Ù œ ¦ ‚ s Q « ota on Q « « ±-¸ Ûÿü • É “ @ ž Ó ” e ¹ r Ÿ Ÿ • e õ€ ½-¨ p er – õ€ ½-¨ . @ Ÿ Ó ž <c>Screen1.xwd d @ Ñ * O ¯m‘ ² ¨ ¨ $Ý È(õ @ ¢ Ó – t > £ £ — f ù-• ¼(Ø ù-• ¼(Ø – ü @ £ Ó ¢ <c>Screen2.xwd ´ ÿü ü Ìûç @ ¤ Ó ˜ S T ¥ ¥ ™ g ïÿè Àõ im = – ïÿè Àõ @ ¥ Ó ¤ <c>Screen3.xwd H [ X in H Q ¹ ` X Q 6 6 ø ¬ Ô @ Q ¹ @ ¨ Ó ¦ Ø • § ‚ @ § Ù ¦ e H ‚ Ô 6 6 ø ¬ ” r ` ™ra ) n o d m Right d Reference¦ Left d d ‚ No Footer« d „ “ d † r d ˆ d er d Ž Š <c d Ó d • Œ d € ’ * O d d Ó £ Footer ” – d d -• No 5 u M # ˜ æf ™ 5 ½ æf ¥ ™ Body . 6 ½ æf Ø ™ CellBody 7 . ½ CellHeading . æf ½ ™ e 8 Footnote . æf ™ 9 T ½ “ Heading Body . æf ™ : ¤ matout ½ . æf H ™ • ; ¤ ~ ´ ½ æf h æf 5 matout ™ H ~ . < ™ Ø ½ æf Body ™ . = ™ ½ æf Body ™ . > ™ ½ CellHeading . æf ™ ? ™ ½ æf ™ CellBody @ œ T . ½ TableTitle T:Table <n+>: . À @ ½ der ü A › ™ ü B › . . À @ ½ ø Footer . æf ™ C ¤ ø Hea matout ½ . æf H ™ æf ´ D ™ ™ ü ½ Body . æf ™ E ¤ Ø ½ matout æf H ~ . ™ F ¢ ½ H ~ À Ta ¢ ½ ter le @ ü matout G › ™ ø . æf ™ H ™ . Foo ½ . ot æf Z ™ Body I ª ½ Z Body . æf ™ J © ½ H ~ æf ¢ ™ matout K ¤ . ½ H ~ Ø h matout æf . ™ L ™ ½ ~ ¢ æf ½ æf matout ™ ™ . M • Body N © . ½ æf ™ Body O ¤ . ½ æf Body ™ . P ¤ matout ½ . æf 9™™ ™ l Q ¤ • matout ½ . æf H ™ ~ R ® ¢ ½ æf ™ Body S ™ . ½ æf Body ™ . T ¤ ½ Body H ~ . æf ™ [ ¤ æf ´ ½ z æf 6 matout ™ ¤ ~ . ^ ¤ Æ ê 2 ½ to æf 6 matout ™ ~ . a ¤ ™™ ´ to matout ½ . H ™ ¹ ° ~ Æ zÙVÓ ™ ½ ;cóo š zÙVÓ › ½ ½ ReadOut æf îãø œ Bo f Emphasis Subscript Superscript ½ € îãø • ž ½ ½ Ÿ ½ ½ f © - ¡ ½ æf ÷3 îãø ¢ ½ Titles zÙVÓ £ ½ TypeIn æ_ý‰ ¤ ½ ÷3 ;cóo ¥ ½ TypeIn h°„² ¦ ½ Emphasis h°„² § ½ Emphasis ;cóo ¨ ½ TypeIn ;cóo © ½ h°„² ª ½ ÷3 æ_ý‰ « ½ ReadOutÆ æ_ý‰ ¬ ½ ReadOut îãø - ½ Titles îãø ® ½ h°„² ¯ Superscriptœ bles Ñ á Ô Ó € ½ € ½ Ñ ½ × ÿÿØ; ½ ± ø Ò Õ ½ Ø EquationVaria ½ Ö ½ ½ Z € Ù ½ Z b d Å a ½ ½ Õ Å q Medium Thick‰ f € @ € c e a ½ ½ ½ Thin Double Very Thin Æ a a c @ ½ ½ ½ > ? > H a > ? > a a a a a a H H > ? > > ? > Format ATy H > ? > H Ç a a b @ ½ ½ ½ > ? > H ) 9 ) * ¿ > ? > Commentî H H > ? > a > ? > Format B b a H ! 1 # a > ? > =Ö ! a H u h i =Ù " v j k ½ Í Å ½ Black Su ¿Eq Redn d d Á Blue d Magenta d Times-Roman½ Times-Bold Courier d • À T! ¾ White Green ½ d  ½ Cyan Ä€ Yellow d d A d d à Courier-Bold Times-Italic Helvetica-Bold Courier Times Helveticae Regular½ Regular Bold RegularT Italic Îl%™ Ï dã G™ ™ ê}X:§ ãªv„S\ Âoœ(%[ÒŒ An“«r tŽ ]lGZ†' Ía8¦å½«k¢Æõˆ³_ ‰Ç 7÷¹ÐAq\·Ÿ`R(3ÝiEø L º ~H F-ñò©™‰ {Q¥HÍ¡õ—…ù Åbq+y ƒ ²ôökó ~¿}ñ 4 ViütÀãü-v hrÆ .Þ t5c]®âÊ5ÇéIÒñyüÅU‹