matlab - MIT OpenCourseWare http://ocw.mit.edu 18.085...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: MIT OpenCourseWare http://ocw.mit.edu 18.085 Computational Science and Engineering I Fall 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms . MATLAB Tutorial Yoii ncctl n srrlall niimbcr of l~asic corrlmnrltls to st,art using II.ITL.IB. This short t,ut,orial dcscribcs those fimdnrncntal commands. Yo11 nccd t,o create vectors and mat,riccs. t,o claarage t,llcm, and t,o opemte ~vit,ll thcrn. Those arc all short high-lcvcl cornmnntls, bccn~lsc hI.ITL.4B constantly ~vorks nrit,h rnat,riccs. I bclicvc t,llat yon ~vill like t,llc pon7cr that this soft,\~~arc gives, t,o (lo linear algebra by a scrics of short inst,rnct,ions: creixte E creixte u, claarage E n),'i~,ltiplyE'II E = cyc(3) ,(I, = E (:. 1) E(3.1) = 5 v = E * u , The ~vord cyc st,ands for the idcntit,y mnt,rix. The s~lhrnatrix u, = E(:, 1)picks oiit colnrnn 1. The irlstr~lct,ion E(3, 1) = 5 rcscts t,llc (3, 1)entry to 5. Tllc corrlmnrltl E * ,ir rrliiltiplics the mnt,riccs E and 11,. .I11 t,hcsc corrlmnrltls arc rcpcnt,ctl in our list bclo~v. Hcrc is an cxnrnplc of inverting n rrlat,rix and solving a linear syst,cm: The rnatrix of all ones urns ntltlcd t,o cyc(3). and h is its t,llirtl colnrnn. Then inv(.4) prodiiccs t,llc invcrsc mnt,rix (normally in dccirnals; for fractions iisc fornrixt rat). Tllc syst,crn .4:1; = 11 is solrctl by rc; = inv(A) * h; ~vhich is t,hc slow \~~ay. Tllc bnckslash comrnand rc; = A\b uses Gaiissian clirnination if .4 is sqiiarc and rlcvcr cornpiit,cs the invcrsc rnat,rix. 1l:hcn the right side 11 cqiials the t,llirtl colnrnn of ,4; t,llc sol~lt,ion :I; rrlllst bc [0 11'. (Tlre tro,nspose symbol I nri~kes :I; 11 col?rrran 'i,ector.) Then A * :I; picks out t,hc third colnrnn of .4; and nrc have A?; = 11. Hcrc arc a fcxv comrncnt,~. The corrlmcrlt syrnl~ol is %': %' Tllc syrnl)ols rr and .4 arc iii,fererat: hI.ITL.4B is case-scnsit,ivc %' Type lrelp .slo,,sh for n dcscript,ion of ho\v t,o nsc the bnckslash syrnl)ol. Tllc word lrelp can i)c follo~vcd by a hI.ITLAIB syrnhol or cornrnand narnc or hl-file name. %' To tlisplay all 16 digit,s type fofol.rno,t lorag. Tllc norrnal fofol.rno,t slrort gives 4 digits aft,cr the dccirnal. %' .I scrrlicolon aft,cr a cornrnantl avoids tlisplay of t,llc rcs~llt,. .4 = oncs(3); ~vill not tlisplay t,hc 3 x 3 itlcnt,it,y matrix. %' Use t,hc up-arron7 cursor t,o rct,nrn t,o prcvio~~s cornmantls. How to input a row or column vector 11, = [2 4 51 has one row nrit,h t,llrcc corrlponcnts (a 1 x 3 rnat,rix) v = [2; 4; 51 has t,llrcc rows scparat,cd by scrrlicolons (a 3 x 1rnat,rix) How to input a matrix (a row at a time) A = [l 2 3; 4 5 61 has t,wo rows (al~vays a scrrlicolorl i)ctn~ccn ro~vs) A = [ 1 % 3 also produces the rrlat,rix A i~iit is harder to t,ypc...
View Full Document

Page1 / 8

matlab - MIT OpenCourseWare http://ocw.mit.edu 18.085...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online