0% found this document useful (0 votes)
5 views29 pages

Technion Hebrew MATLAB Tutorial

The document appears to be a fragmented and disorganized text related to MATLAB programming, including various commands, syntax errors, and outputs. It contains snippets of code, variable definitions, and examples of MATLAB functions, but lacks coherent structure or context. Overall, it seems to serve as a rough guide or notes on MATLAB usage rather than a formal document.

Uploaded by

idomarzel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
5 views29 pages

Technion Hebrew MATLAB Tutorial

The document appears to be a fragmented and disorganized text related to MATLAB programming, including various commands, syntax errors, and outputs. It contains snippets of code, variable definitions, and examples of MATLAB functions, but lacks coherent structure or context. Overall, it seems to serve as a rough guide or notes on MATLAB usage rather than a formal document.

Uploaded by

idomarzel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
MATLAB ™ ATL pe zap ee) Fe ee eure AV oRCOIN MSN AsO AD?M MATLAB MATLAB wrong) OVO MMA y FV Mow MM) wn .A~PIEM 0102 7omnD “Yanna eanen) T1992 Top AS’ NON yom Let tora, 7978 MATLAB Uo vies DOS Toyan now MATLAB oY Tiay> 7. MATLAB Ye (prompt) 10071 re Peon MATLABS9 JHO*33 » 27m meee 07 .NYTIDA WFD yarn MATLABS3 pan pod TN RO TVD squit AMDaN AA won DES? Min MATLAB d>qust v2) Joo mani3n help-n wryeaa warere ney MATLAB-3 Foym yay 7S Sy TOT vas OTD Maen SEM HAIEA Axon ROW Pam OMA C ATIBAN GU ne VOI w oP rtoo TEA Ww APBD ¥g2077 FO) .belp ro>on >>belp C fee mms t misma on MATLAB 2 nrTipa >>mareme? 1092: Ye ox vanw an Ora OS Fe ATEN IN Ty DD 913° TOAD seu ay ,o Ineo sim pan xo 7 Tig mien aio (;) DPosATIOIN a MnEON TA? 1766 Twn PR wena 1 tO ON .ToEN ya Fe TIN Fe OSTD xo MATLAB-> ersamm 12>?n (5) premrmps >>ael.793 LTO » Tp 1 (,) pa Oy AYTOID Mw MG ATS 7 wD In? me joan by Tn yeaa? (,) pron yoain rma eae ce. (5) POs OAR Gx TOON Sy Thyn yea1> xO (5) pPoaeMTIDs mera Apa oan year? (3) peosertips nor (,) DONO IDNR ITN Mpa >a=3;b98;c1=170.c2-0.1 “ei170 29.1000 » s Rox amin raw yee 29> 90s IX Ty on ya ATA. ot sang fumwn Tiny >ywan Fo Twn ax? (;) Desa A|?>nea :NOAYT 25h ans=9 >» ran rmpan NAS wan eM mM raw eo 1.3 a AM 29>n Tne BW .nyeMN 19 Ty DB MDW KATLAB-3 o?2nem> Va foewan MATLAB naw. mmm 1D IN AITO ,AVANG TUES 71977 casesen 799) .A PuMETMA Awa MBN = AE MIT AVM IMMAITD .MIO? MDTAN VMN 12 STM Ae MRR be5,b93 >>ae55 >A 22? Undefined variable or function. Symbol in question **> A >>easesen >A a5 » Fone TWn> wb yn931 oon type-> OPTI O9°N MATLAB©2 O° J7em PEP Pe OPIN ALISA Srey MED) 7702 INN TPN ADDO TY swho TMpON °*y yap IAI ATAyA NEA Ono oan >>whe Your variables are eps,pi,[Link], your_variable!, your_variable2,0,x leaving 256301 bytes of menory free. » yan 7eoR> 3.8 1°32 AM onmNEN MV-A ABAWD NA eps Pane wren oe B-> Maw A) mune wow Ar Ty .15yn floating points TY 995 eps De Twn TR mIU> 1°) .(eps-B UoMION I3wA }op oM°a @ 3 roten Dy mean 7D © 5930 Inf ox SU TAR PID PL yao 92 w/e 1K 6/9 129 Auesin 3y??m (Not A Nuaber) NaN 11133 were 1h) ONIN AAW} IM AMD ID Ty WM ONAD ¥PD Fmps2 waMED> ww AMayn nue iePD Mane pInD> >TD .whos M7193 smiypan clear >>clear a » : Devens *ya clear Fmpan .ATayn noe a AMREGN FR MeMIB NMI +(@99amn w amen 1210 Taz8) TMayn AoE Pane 3 Ae Dinan peony 1th nmayy>.97357 SuaneA 313993 On MATLAB-2 o>3900 5,1.3467,1.60210E-20,6.2925¢23 ~OP3D778 |Pn90m Oa YOND XD wD! MeSND MATLAB orme {oo >>desqre(-1), RIN JB 3D OV) 3+0.5%f IM 1624 misre OPrOCN OPIS IN? HX (2903 On EE! OrrOGOM “OT 939 Naren :kORIT> .NITITD 03 OF 3FEED DyMp 19) 07790 MADD >otdtlete"A very nice graph’ title= A very nice graph » p97) 7710p) ‘nn OTS we? TEN) O°910P7 SY MID1¥N9 NIN MATLAB-3 >Ap°yn Moe waay7> .[ ] 2 ware Nep11> mmo prae[t 2.3 pi 345] ace colums 1 through 4 1.0060 2.0008 3.0000 3.1416 colum 5 3.0000+4 .60061 Ba }132 Ar) OPrGeN Ao) OPPIwA BA AV ODIs» OED a> OD 2 wan) MePTeNd b MR Sno OTD (ox >>ba[i 2 3; 45 6:7 8 9] be 1 2 AOS 7 8 wow >» oy Dap) rein nm >>da[t 2 3 456 789); » 1373Fe_wiBreD ADI MEENA MVPD (5) Broo WBE a> Oe zeros 17303190 Fy oa MTOR MM? ND BEI") FO > ronmwan a Dy a Saa Meo MP Ina zeres(aym) N>xp219n .ones-1 if No3}79 1 > ones(a,n)1 © >>3*ones(1,3) ans = See » size Tp92 waren wr RYTON SY ST1An AK Yaz TD >>asones (1,3); >>size(a) ans = 1 3 » OX B 9¥ 1 misma wen meereon wa3 1 x8n yen ye OPO ane ot Devan \nea) ED) AO Oa Moe Nene ona MATLAB nae 1 Sy on mises ‘eer NIN a OK .FFt=1 plot 1a> MI>aIOOIN MV>¥pI IBN yD PN AHS BBAITD 150 THAN Mee Yn? length(a) rx nro. >>b=zeros (4,1); >>size(b) ans = Hon >>Length(b) ans = 4 » (2a TTPO ayaA sas oY ON Ore SAAS TON TH PADIy OPO 172 ENEMA VAL NIN 93 pRON GAT TD) IN RL K2IS FORT 4X3 MI Ww YOR >SD>oHEN ~aeNM X2_NIN 9:23:27 ans + 4.0000 5.3000 6.6000 » 2>t=@:pt /32:31.1*%pi/32; Baw a> Ore) 9,4/32,2n/32...312/32 on aM 32 TNA AWE Tx TAB MB wy? ova +2000 Ty aPnva> nnd w> anon Se aIen Prem Pra 020 a EnSh XZ ne Orem ON (53D OMIT NIN >yBrOPOR 1mm wapry 24.538 7900) xoaI7 ans = 4.5000 5.50000 6.500 7.5000 >>Dw OB AIM d1D> x2 >252-2.5:0 ans = 5.0000 2.5066 6.0000 >» g79189)_nM1_mx?7en1 Oo» 0P1a_ BPN 2A999 MISA Mee PATS MOTT MePTEO We VOPIA TNS BHO Awa 2-2 Bonn EOI DAN GON HEPA dn -~GNN MK IH als) 2 mien enn re im) a(2,9) PENT MA WEEN TUS Ty o>: +8 Treen J roy SBT DrasSzn1st >>a(3),a(6) ans = 3 ans = 0 >>a(2)=8; >>beones (3,4); >>b(4,2) 277 Index exceeds matrix disensions » PON oPsap0 Teron we TeEIA ST1Ay AB OPTI" OFINID Oy 12IED g27mI77) Wes oy Mant 12 GaN MOD wD a 1? "AeIw 42° > nyx-opa 41 Bonn oo ipew a-2 OPaPRN MR 1M? (41:42:43) , (3) 43050 >>as(7 3.1285 3 11 9); >>a(3:2:8) ams" 183 >>a(T2-1:2) ans 358213 » Yea PONT Mrs waza orrart oem MN mee jn? x(1:2:Length(x}) po By 3 mtn ae am 9(1:5,3:4) | emyeson Se open oa ODD {Day Me pnw yy AST? In) WO Gd .a MPIEEN bw 5 TY 1 nie practi 2 3:4 '5 6:7 8 91; 23) Mya New 2.3 myrveo on a,b OX .[,] aia oy meynD 213) AIOE Ew +82 Pan b Wow IN [a,b] IX MI Su TED IMx Moya 20217 >>[zeros(2,3) ,ones(2,4)] aaa ai » 9513 1X FITIBY 27700) 813 IN ORO UTD THEM) OPT1001 ED TEM? OH OX .transpose-" 10181G VENTE 331) OP >DAD Ao AE Gk .MIB >mI0p1 imasn orasmun meen en atk TKN GX my (conjugate transposed) >>asones(3,1).be[8 4 3] ao 1 1 1 be 843 » me >>La’,b] ans = 111843 >>fa,b'] BPOsTTID] AON WORE 8 N293w> MNO ANN M7EA TD TD e Wew 20n [asd] ee nrTAy 70D INI OY MYM BN bY 3 -a > mn b> Pros-ATIDI WWD 153 a SnD b SV NeW A> TT wN fda “G) 27kaN Aree mew> Mpa in saan 159 2 610 3 7uL FeTB-DY MyrTeH AwI9D ArT Py THY MATLAB-2 waree> w> ornyay Pe Up) IN MEPIA FOP zilch MM Wwe? In?) TH zilch=[] oN .@ on QW MATLAB-9 no? 37m OnNIN 268 MnwD NIN zilch ON OA 93D2 DOO INN Fe selear zilch yx1a ° ROayT> .MITIND Wwe oa In? >>{'Shanah ',' Tova '] ans = Shana Tova » Fran merean W399 ATA In :d9aan 1i1ee6e 1ii1eeee 1116668 eee0011 eeee011 eeao1100 eoe1i09 2ax700) zy mows 3.1 e+) PeINa ROYM DIDIN, 993, NON, NAIN ye MoVWAA TIEN M>WwA 22571 vognon >wanon G10)" MATLAB+2 O>9d70 by AISYID (7, 225+3,7°8,34 ans + 8 ans = 56 ans = 81 » Mera Sy MND +,- MAN TID Mo oyA “am mxse “er “aPR OP TIOpIT >>a = ones(1,3) :b=1:3:asb ms = 234 » 2/9 3 waned ow -ox “ON noma rosn Ix DID!A |993 HAD >> -Poxnna, >>an(2*ones(2,8)).“1:8 as = 2 4 8 16 32 64 128 256 » ROR Pe? ay ADTy9a |P7GNN INN ON MAMRIT EOI “AD ew +29 Ox Aysanp Mien) @NNaN ST1a2 MTA IK TUS ann DON , pe 2NBAITD.7aN >>(128)°2 ass 149 16 25 36 49 64 » 7 2729 RyP7GO VED LAND MPT by D¥I2 KIN WO © TENA >>ones(3,1)*(1:3) ans = 6 >> (123) '*ones(1,3) wun B one we » reneon 7199 a 7a att orerva msm oy afe rowyen sansa Ae me mer rare an AND .(113 woe) Boe moa -Atxeb nu iwan rows yiane Ran rete mR > FTA In D229 oo ouUN eo eonrn ee ew aw 2 022 e® oo 2022006 ©0282 0 0 Dy?y0399 3.2 >9 pOTIAD POW Sap? yn) .MATLAB-2 mn»>p Yor OND! M>xDII9n @PA>pE Sy O3 NIZ¥19 195M MI>¥DI19N yD -help-n FTA >*y ITB MA 3D a ROR MPIEO FY PoIySM my-nen dy ond ne¥p2 190 >>ysabs(x); » (25778 x ox ma) «x SB ODI Dee x De DoMIEN Ten Pe yD IN nexp2 ran >>yssqrt(x) >» (330790 1 *>>e x ox Oa) ox SU EN Ae 2 A aspaisn >>xereal (2); a eeee +y 2 Noa Twn me x 2: z Je CMAN Ten me IM? >>zbareconj (2); » : 2 9e Tian ne zbar-2 mM) nvxpiian >?>excos(x) 5 >>sesin(x) >>tetan(x); >» DY MIDyIS IAW aI VIED -my=aTA MAEMIDIAIAON MP¥DIIDA ID MOAITD “OX “aN M700 3 tO epi/32:4*pdstgnalcos(t) > ow a POS wy m319MM MPTIENIAEN MSDISN ne yaR> OD -Pxp1 150, >>x=acos(c); >>xrasin(s) 5 expo ian >>ywexp (x) 5 » _ syre™ wn Msp} 190 >>yslog(x) s >>yslog10(x) 5 >» -Tennra 18 96> onesaisMm eyaron oneaaidA me MIMD enson sy oa MITRY PO TY DNNW AVxDIISA Sw 31 Wat wr .223970 TOPNN NIA 12-“OR 530 TOP) IN PIED © 7S max(c) M¥DIISN (ye wk may) op enc ok cea APRN FMBva oS oREA © TEP T3D TOD .c-3°Sm> ORIN “aPNN Te IN” max(c) >>memax(max(c)); a opaN “oN Pe 112 sum(sum(c)) .¢-2 rtiay 92 ye O30 12 TEP) 1M12 sum(e) TOIT Masa +6 7G 99 O1D0 re IMD 39 a> ANA aIwN oe Te0O mR MIM) fix(x) n>¥p19n nam? floor(x) —.x-> “Wea ay7~M ade TBO x A Dayn round(x) .@ tom joan Pe nani) ceil (x) .x-a JopM M2 DyTIN Oe ADEN YeFP >on Nesp I9n WIW 2 STAM .x-B 72M ANI oN FRA NEAITA TAK WM? PAID. >oxe[1 1.3 -1.4 1.8 0.9]; >>£ix(x) ons = 1i-tie >> round (x) ans- Laict 2-1 >> floor(x) ans 2a-2 4-1 >>eedl (x) ans = 12-120 » = 10 - 97 2NP913_ OUND 3.3 B2eS1an |WIN wb bea a >»a=b be MW Ww Dra 8 rach b-n loa >>aced bed mow 1 IoD @ (193198 rame9 928-29 Ore) .b-> Miwa a be Mw a boa ON 3K Oy o> ?—RB RITA ON 1 OPP END OM WMATLAB-32 oe9y19 DVwIa MDD A> TD GR TUN I¥Ia? MIDIVIR MYWwe IA 2O78aN @ayENga enNEM we OR re AND noa17 >>akb -(AND) @- Maw b 029 =n mI a Oa EXT Jnr >alb (OR) G-0 naw b I O-D TW a IN OX 1 In? ra =n O-) 0-5 MW a ONL IM 72 G-B MDW TW 92> nonenD MATLAB now,[Link] MTanD >aY 74> ++ TON TGR NO NEED Sy TD1¥9N YNO Ga .FALSE SND O-51 TRUE ?any(v) 20-2 718 v=2 OPN TNX ON 1 Inn >>all(v) - 0-2 07218 v-2 O°°GNN 93 ON 1 PIN wer 12 wD yay rMaY MIDAwO SY MIVA MEDIA HAD sy Su myniayn Sy miso ian mbyon men oA ya 203079 >>ms(1 023 300;100]; >>any(a) ans = Lo. >>all( 1008 >» De21en wea GUNA Fe POTN 1a Ter MeIna find(y) APxPII9n 0-0 Mma 17 >ofind({1 9 3 6 @ 9]) ons « 136 » Pe) OPA SEP OPAA WAR Pw ODTIINN Fee? MAS AMIDA IN D939 (o°190 OPTDPN AMD WP GR OrOPTIN aynop 72 MATLAB-2. myTHA PTD Ao WN TIA POW -AMOID) NTI JO AAD AZAD NYTI_AI THY w AYID1n if mayest On ex ATID. Ye READ IN TTS Fe ANID yIs?2 PwONM LF ATID MEANT .oP PANO NDIA >>if (a>b)&(b>c) ,exb;beazend ene opedIIA NINA GA DT AID? ended ifn ATA ya AYTWIA_yD QM Aw m2 099 dy AYTNPIA MAN AW IID? IN?) «(8-9 ADI) TRUE, o17> (O?°DAA NANA ON) end-A AIDA y9aN eR DI 193127 >>if any(ase0), ) proa-rmipaa YomID MPA Syd? if-2 NINA MIAN (,) BOD (2299R "adw ty ANE MTP 192 (,) DrESA IN (3) _DromRATDIN :no2 17> elseif-2) else-2 vaner> 0 In) peat ies, ali,3)=2; elseif abs(i-j)=1 a(a.i)a1: else a(d,5)=05 end; » elseif-n -wnx ann on 7 nivyann else-> elseif-A 12 nITIDAN 93 mpon if mA Ana elseif mTV73 MIA AMER ny) Oy ANA XO Drelseif-2 1x if-2p QONnD MN AN OR P IID? else-A THe <7 9pnA pinoy 4.2 -Pomwa oma °K GY O°RYD FAD MITIDS NyIAD dy MAIN AwoND for-n ATID rem v7> >>prod=1; >>for i=L:length(x) ,prod=prod*x(i) ,end; » 2 99> TYR 1A MATLAB-2- nno1> «x 7G Ye Mes3ON me prod-a_ 2s aie) Tia My MdWwIN TA AD Dy? AM? TOI ID M7? xea17d MN YeR (PRIA VID XD ABT TTpAN FR YAP THT Dy -21eM) 2p3 >>elear >>for t=0:0.1:4*pis xe(x,sin(t)]; ends » >>tm@20. L:4*p: >>xasin(t); » han TY 99 NTA ye PAID Ww AMPA ¥13 MIND while-n ATIDD :ROB17> .O??onD 73N>>12. pa >ristifacts: >>whdle fact<1e30,i=i+1; fact=fact*ijend; » {2 WO 0 .1536-n MUP V>e MxyMW r>NPOpBN TwWooN rR i-2 inn PING Wen 723.99 TMDIN Te OINED rmpayt> AYU TA MAN Af, for,while Mm71p9 1259 12 >>for ie1:L, if i/3-round(i/3), if 4/5=round(i/5), sidasi5ei; elseif i/7-round(i/7) ‘s2ies21+i; end, end, end; » 2779 3x30 4.3 PNAPW YX OP31W DPIDFA OPBYD TOD AITIDS NIAID Dy TIN w OND +2 Nive Mmo2>AW 72 (noTIM for-A Mpa Sead) POaIeo A ANTIDA GRYTIPIA SAD Ivy OA TOK MVR. NPN M1910 NOD MATLAB X1N “Gian oO .MATLAB De MITA SU TOP 3 DeDND DID? MITIPD “AID moay7>) .m (extension) raven oy DOS-3 "DIN aw ow 5D wa ow MATLAB-n Tina mITIDAN Arp FN D997 PTD (very_long.= Nga 7S .(.m-7 *93) “OIDA ow AK OTD >>very_long MATLAB Tha nyTiDSA Fw IRS EAT Yaw Tina ATID. ye own opin -(MATLAB 2o (prospt) 1207 TR OVD 1°R) anyTipa arp NDaIT ‘sums of partial matrices’ Ye Csum(sum(a(1:5, ‘sun(sum(a(6:10, sum(sum(a(11:15,:) sua (sum(a(16:20,:) 1 sums of partial matrices mien nx Toon dy O97? 1? VeRO AT ID FOOD 39 OW .a-2 NPM My we DwODIDD TOOT Sy ONT D"NND TR NOW? 9D MITA PsA NII Vos 12 -NINw AMD Sy AMIN some -13- MATLAB-9 n1>3319 roovn 4.4 syeny eS 7w?yA 91S) _ NTI NIM NITIDD Gr 8 FwAN ornyDS Dime secre 1) O92 aa OD DINED Way AITIPSN Morn Sy RON FPSPIID “GD -NVMpIIA Pap PTY MMA IT MD .o°37 GPPaOF ‘function FO*nn rx nb?3D IDE AYA Mie ATS aD 20a function kefactorial(n) Zfunction to calculate a! e(]; af size(n)~*[1,1] ‘error ~ argument to factorial must be a scaler’ elseif 2<0 ‘error - argument to factorial must be non-negative’ elseif n“*round(n) ‘ercor - argument to factorial must be integer’ elseif n=-6 keels else fern" factorial (n-1); Fiabe 1p) 1SFwW FeNA IAA .-TPEDIIEN My TINIAN WENN Ne <2 1S ee MK TW kD APxpIINN Twa AW 12Pw ANID TEN DY) oA ¥p}1EN Tima @ WMA yD .OPTeNTN AAD Va yn) . (MATLAB YR FPSpII9D APIA WA VAPspI ANG ER ay Tn DAVID oP>DIDo pronmixa xo on (MBPT TIEN? OroAMIND on) Ty 22 >BIONN OP ITEMS Twn wend NDNA THY PRY IA o> TW AoW] M¥pNIEN 6-9 spr TAI 7eMNy A¥PII7 NAW REN TA On ANS PDA MPMPIIND FREAD 19 AOR TPDIIDD PETA «(ke Toyo Mara) >My nop? Fbyad m>xpI19> MMaITD .MATLAB-3 >>iefactorial (8); FPsps72 AT GX BT We NIA T¥pI19 Fw OB THI MATLAB-n “RO Ar 1owe ww AGI°O OY AID BANA Fe yu woND "NO DB AeD?ID Say Ke PNDIIDD NIV PN TD’ID —.FP¥p219N Owe (nay»On T27N) OA XO IVT WN TD >> MATLAB Se NIA wxDII9 Fe oe NYTIDD Ge mr mn? mxp)I9n ToIND 13 “aIPN Ow “PeEb vw 13 109 PoDnngn min. (factorial.s Moya xara) .m nm70 oy mxDII9n PAA MWK MPA TY AAA NWN Aw .AywA IA f-3 :™m217> .help function_name yx) oY Joon dy 19991? MIVE >ohelp factorial function to calculate a! » Pomme. AeA. (roy? mya 1m) yaXYD NITY MIND? MVPNDIID yooz FPoTpNO yinM> t9x7 MATLAB-2 })99t Avy apy) _NPMV09>x PR MEAIT PROD Aspe DY MAN OOD «(NTO AR TM MBM aa ytd man ,n17s219 gPanr> (MATLAB AN argv 15x) MathWorks wo rinverse fft yix7a9 7xp219n function y = ifft(x) IFFT IFFT(X) is the inverse discrete Fourier transform of z vector X. See FFT, FFT2, IFFT2. z J.N, Little 4-21-85 z Revised 4-17-87 INL -1- z Copyright (c) 1985, 1987 by the Mathiorks. Inc. yreong (ft (cond (x))) + nj = size(y); 1 27800 veay op 45 wearer wma ND 1K _MPMDIID TrAD OPwEON NIV 7WUD NID? 7D sinput mypa2 >>xeinput (‘enter a number '); » jaca wpme wy ronm) enter a oumber nrimnon me Toon >y¥ Pa Tpan 2x TN 020 seve i7Nypaa waned w OID Tind MATLAB=2 ovyTemN rR TED 77D Fmpan >>save fname varl var2 var3 » fe prorows on varl,var2,var3 o> ane ne [Link] G1P2 VTE Donen me 218 yey D.T|yA now g?3nEON 73 ou? oranED mow Frnipaa varerd © T3971 NOD >> load fname » estan Sy 10997 Ww editor-2 WHIP? 1NIW 27900 UIST TNT Bo {g3739 \p0n wy) Jeon oy wow mm 3 .diary ATipsa waned 1nd Fmigan oonw >>diary fname » aynipa ownN BD POA Ta-TON - fname. AIM TWD 37> >>diary off » nny stn) oon by aragen oat ine] To -MATLABSD reexen 1K arpa ome MATLAB-3 +972 029. -plot 7792 wane’ wp? TOI WIV VIED TD >>plot(x) » ENBAITD TOD «x DBA TOON vy Ps? >>eeO:pi/32:4* pi; >>xesin(t] >>plot (x) + 7 mn; rp ripen >>plot(x.y); >» maT? nO. wx Je APMDII9D y YO MA TOON Sy VPN >>tm@zpi/32:8*piixet.*cos(t) sy=t.*sin(t) splot (x.y) + » FRpan Oty OA TRA TIT «ToD NIN Dy PSNR THD WM ODT THD wv nia o>19 .x 8 AYA Je oA I! GPa -AIE x oY plot(x) Toon Ne F3Ie OVX PoTwA AMIR Dy OPIT WOM PND ONION «TEPC A Preview of MATLAB ™ ‘By Jol Litle and Cleve Moter ‘The MathWorks, in, South Natick, MA 01760 “Fel. (S08) 653-1415 Telex 910-240-5521 FAX 508-653-2997 E-mail [Link]@na-net [Link] 21 Eliot CONTENTS 1. What is MATLAR 2. Introduction: Matrices, Polynomials and Vectors 3. Graphics 4. Signal processing 6. Census example 7. Spectral analysis example 8. Summary of current capabilities, 1. What is MATLAB? MATLAD is an interactive program to help you with your scientific ‘and engineering numeric calculations. ‘The mame MATLAB stands. for ‘matris laboratory. Originally weitten in Fortean for mainframe computers, provides easy access to matrix software developed by the LINPACK and EISPACK projects. Together, LINPACK and EISPACK represent the state of the atin software for matrix computation MATLAB is an interactive system whose basic data element is a rx that does not require dimensioning. Problem solutions ae expressed in MATLAB almost exactly as they are writen mathematically - with no programming required. ‘This allows you to solve many numerical problems «fraction of the time it would take fo write a program in a language like Fortran, Basi, or C, MATLAB is recognized as the premier interactive program for ‘numerical linear algebra and matrix computation. Its evolution traces back fover more than a decade, with input from many users. In university environments it has become the standard instructional tool used in imtroductory courses in applied linear algebra, as well as advanced courses, in other areas. In industria! setings, MATLAB is used for research, and (0 solve practical engineering and mathematical problems. ‘Typical uses include general purpose numeric computation, algorithm prototyping, aud solving the special purpose problems with matrix foramilations that s Uisciplines like automatic control theory, statistics, and digital signal pro- cessing (Vime-series analysis). ‘The highly optimized, second generation MATLAD that runs on IBM and other MS-DOS compatible personal computes is called PC: MATLAB. On target computers, like Sun Workstations and VAX computers, the rmodent version of MATLAB is called PRO-MATLAB. On the Macintosh, it's MacMATLAB. Entirely written in the C language, MATLAL tegrated” system, including programmable macros, fast it from the years of experience gai the earlier versions. (oth will find that MATLAB fias evolved ix laboratory" «9 become versatile scientific “spreadsheet for numeric eatculations. 2, Introduction ‘or those of you who have not experienced MATLAB, we would like to introduce you 19 an exciting new way to perform numeric calculations, Part of the usefulness of MATLAB comies from having powerful analytical tools available, and part from being able to do graphics, but the heart of MATLAD’s success is the elegant user interaction. We can say things lke: "The conwnand format is natural; there is mo arbitrary can ‘mand syruax to be learned. This frees you to apply intellect directly tothe task, not on the computer aspects oft." until we are blue inthe face, and although true, it won't get the point across. ‘The best way 10 appreciate MATLAB is, of course, to ty it yourself. Bar- ring that, the best we can do is to show you some sample interactions with MATLAB and let you judge yourself. 21, Entering matrices (MATLAB works with essentially only one kind of object, a rectangu- Jar numerical matrix with possibly complex elements. In some situations, special meaning is attached t0 I-by-1 matrices, which are scalars, and to matrices with only one row or column, which are vectors. 2 A Presew of MATLAB Iroducton Matrices can be introduced into MATLAD in severat different ways. ‘The easiest method for small matrices is (0 use an explicit list. The explicit list is surrounded by brackets, [and J, and uses the semicolon, ;, 10 indicate the ends of the rows. For example, to enter a 3-by-3 matrix, we type: A=(123;456;780] “This results in the oulput Aw 123 456 780 “The miitix A is saved for later use. ‘The individu elements in the input should be separated by commas or blanks and can be any MATLAB expres- sion. For example, typing. x= [-1.3, 415, 4+atan(1)) ‘uses MATLAB like a desk calculator and results in xe 19000 0.8000 9.1416 2.2, Matrix computation We can run through some basic matrix operations, Operations and ‘commands in MATLAB are intended fo be natural, in a matrix sense, not ‘unlike liow they might be indicated on paper. For example, our matix A, ‘can be transposed wit Baw which results in: Be 147 25 8 360 ‘Matrix multiplication i indicated wit C=AsB producing: Cn 14 32a 92007768 23 68 113 A family of functions is available to calculate common mattix pro- pertics and fictorizations. For example, the determinant of a matrix is cal- culated with: dot(A) Which produces rod ans = -1.7778 = 0.8889 -0.1111 1.5556 -0.7778 0.2222 0.4111 0.2222 ~0.1111 Bigenvalues are calculated with eig(A) ‘which results in ans = 0.9884 12.1229 5.7345 4 A Presew of MATLAB Inrodaction We can obtain eigenvectors as well a eigenvalues if we use two arguments ‘on the left hand sic 1V.0] = eig(A) resulting in ve 4.0000 0.4298 -0.3142 0.8810 1.0000 -0.4418. 0.1246 0.9046 1.0000 b= -0.3884 0.0000 0.0000 0.0000 12.1229 0.0000 0.0000 0.0000 -§.7345 The columns of V are thee the corresponding eigenvalues. Stop now and ask yourself: How tong would it take you to invert a ‘matrix orto find its eigenvalues using your existing software? We bet that less you ate using MATLAB, you said minutes or even hours. With MATLAB, it took us several seconds to type in matrix A, and then we inverted it with inv(A) and found eigenvalues with eig(A). ‘There simply is no better way too, Many other matix and tinear algebra functions are available jn MATLAB, including finear-equation solution, last-squates, singular-value ‘decomposition, matix exponentials, condition number ‘estimates, and ‘als anything else you can think of todo with mattces, savectors and the diagonal elements of D are 23. Polynomials ‘The characteristic polynomial of matrix A is found by typing P = poly(A) which results in P 1-6 ~72 -27 ‘The elements of this vector represent the polynomial coefficients in des- ccending powers. ‘The roots of polynomial P are the cigenvalues of A: roots(P) ang = 12.1229 5.7345 ~0.9884 I we have a second polynomial B, and would ike the product of B and P, ve can use convolution, which isthe same operation ss polynomial i plication: Ba(t24h C= conv(P,8) “This results i ce 1-4 -83 -177 -126 -27 ‘Abo available are polyval, for evaluating polynomials, daconv, for poly- ‘nomial division, polyfit, for fiting polynomials to dala (regression), and residue, for calculating the partial-fraction expansion of « quotient of 1wo polynomials. 24, Vectors Vectors with regularly spaced elements may be generated using the ‘colon : operator. The statement D-14 results in D- 123 4 “Two colons may be used (o create vectors with arbitiary rea) increments between the elen 6 A Preview of MATLAB Iron E. 0.0000 0.1000 0.2000 9.9000 0.4000 0.6000 Vectors are used offen in MATLAB because of the ease with which they allow data manipulation and function evaluation, When a function is applied to a vector in MATLAB, the function is applied to each element of the vector. For example, consider taking the sine of the four elements in vector D above. In Fortran, this might be accomplished with the short pro: gram: REAL D(4), Yi4) DO 1001= 1,4 Y(l) = SIN(O()) 100 CONTINUE WRITE(6,(4F10.4)) ¥ In MATLAB, however, this becomes a single concise command, ‘Typing Ye 0.8415 0.9093 0.1411 -0.7568 ‘notion of operating on an array as a whole is a very powerful fone, shared by MATLAB and computer languages like APL. MATLAB users who look back atthe sealar Fortran way of doing things like to say, “Life is 100 short to spend writing DO toops.”* ‘[Link] variety of data analysis functions are available that operate on. vectors. Typical functions include cumulative sum, cumsum(Y) ans = 0.8415 1.7508 1.8919 1.1951 ‘mean and standard deviation, mm = mean(Y), s = std{Y) m= 0.2838, se 0.7758 sat mechanism for individual users to add new fanctions to the fibrary of those already available in MATLAB, Grophies ‘One of the biggest pleasures of MATLAN is the graphics. ‘The graph- jes commands offer that elusive qu being natural and easy-to-use, ye! sill succinct, powerful, and extensible, Once you have tried MATLAR ‘graphics, we think that you will wot want (o do graphies any other way. Sciemilic and engineering data are examined graphically in MATLAB by using a “graph paper"? command to ereate a plot an the screen. “There are seven different types of "graph paper" from whi o choose: GRAPH PAP pot car X-¥ plot loglog loglog X-Y plot semilogx — semi-tog X-Y plot (x-axis logarithmic) semilogy —semi-log X-Y plot (y-axis log polar polar pot tmesh dimensional mesh surface contour _ contour plot ‘The plot command creates is understood, fogarthmic and polar plots ‘commands loglog, semilogx, semilogy, or polar for plot. All five com- mands ure used the same way; they only affect how the axis is scaled and the dat are displayed. 34, Baste form ITY is a vector, plot(Y) produces w linear plot of the elements of Y versus the index of the elements of Y, Por example, suppose we would like to plot the numbers (0, .48, .84, 1., 91, 6, .14). ‘This is quickly accom- plished by typing Y=[0. 48 84 1. 91.6 .14); plot(y) 8 A Preview of MATLAB Graphics Which results in a graph on the sereen: Notice thar the data are auto-sealed and x- and y-axes are drawn, A graph litle, x- and y-labels, and grid lines can be put on the plot wit ‘Mle My frst plot) xfabel‘fortnights') ylabel(turlongs') oid Which results inthe display: Ix and y are vectors, the command plot(x,y) draws a plot of the elements ‘of X versus the elements of y. We can apply what we learned in the previ- ‘ous sections fo plot simple functions. For example, to examine the behavior ‘of the Functions sin (x) and 22/100 on the interval from =15 to 15: 15:08:18; ym sin(x); 21100; Plot(x,y.%.2) which results \ Mo Moog 3.2. Three dimensional perspective plots ‘The command meshjZ) creates a three dimensional perspective plot ofthe clements in matrix Z, A mesh surface is defined by the Z coordinates of points above a rectangular geid in the X-Y plane, The plot is formed by Joining adjacent points with straight lines. Mesh can be used to “look” at large matrices that are otherwise (00 large to print out in numerical form. tt can also be used to graph function of two variables. ‘The frst step towards displaying a function z= f(xy) of two variables {sto generate special X and ¥ matrices that consist of repeated rows and columns, respectively, over the domain of the function. ‘The function is then evaluated and graphed. fer the sin(r)r or sinc function that results inthe “*sombrero™™ verybody likes to show. Here is one way to create this plot: to A Previw of MATLAB Signo processing X = onesty)+x; Y = ysonas(e); Fw sqi(X2 + ¥.-2) + ps; Z = sin(R)/R; mesh(Z) ‘The first command defines the x-domain over which the function isto be ‘evaluated, ‘The thd statement creates a matrix X of repeated rows. After making a Y matin of repeated columns, a matrix R is created cont the distance from the center of the mattix, which is the origin. A small number, 8S. is added to A, so that the next step, forming the sinc function, does not resull in adivide-by-zer0. Applying mosh results in 0, S = dlag(S);, end; lambda = Input( Enter stabilizing parameter. ’); c= Uttdet)'¢p; c= S/(S:t8 + lambda).+c; c= Voc; op90 = polyvale,9) ¥ = polyval.x); Plot(.p. oxy) ond {tis reasonable to fit bitization, ta with a polynomial of degree two, and no sla- Entor polynomial degree. 2 Enter stabilizing parameter. 0 ‘These responses produce numerical results anda graph pop90 = 254.8562 a 7, Spectral analysts example Digital signal processing (and time-series analysis) is easy with MATLAB - vectors are used to hold sampled-data sequences. ‘This example shows a simple use of the FFT function for spectral analysis, A common use of FFT's is to find the frequency components of « signal buried in a ‘noisy time domain signal, First we need to create some data, Consider data sampled at 1000 Hz, We start by forming a time exis for our dato, running from ¢ = 0 untit 1 = 5 insteps of I millisecond: ' 0,001:.5;, [Next we form a signal containing $0 Hz and 120 Me: X= sin(2+pl+50+1) + sin(2rpir 120"); ‘and add some random Gaussian noise with zero mean and standard devia- ton equal to 2: rand(‘normat’) yeXx + 2erandit); Let’ take a took at our noisy signal y by plotting the first 50 points: pplot(y(1:50)) 2 A Preview of MATLAB Spectra analysis example Clearly, itis difficult to identify the frequency components from looking at the original signal; that's why spectral analysis isso useful Finding the discrete Fourier transform of the noisy signal y is easy; ‘we just take the fast-Fourier transform (FFT): Ym tty) ‘The power spectral density, a measurement of the energy at vatbous fre- ‘quencies, is found with: Pyy = ¥ * conj(¥); “To plot the power spectral density, we first form a frequency axis for the first 256 points. (The other 256 points are symmetric.) 1 = 1000+(0:255)/512; ‘We can now plot the power spectral density by typing plot(t,Pyy(1:256)) which shows the frequency peaks at 50 Hz and 120 Ht; yo OOS OS OHO uM Immary of current eapabilities ton asin cos atan atun2, sin gamma rai "ARITHMETIC OPERATORS ENTARY MATH FUNCTIONS absolute value oF complex magni ‘square root real part imaginary part ‘complex conjugate round 0 nearest integer round towards 7270 round towards 0» our quads hyperbolic sine hyperbolic cosine hyperbolic tangent ‘exponential base € ‘natural logatthm log base 10 Bessel functi ‘Gamma funetion rational approximation addition subtraction multiplication right left division power Aeanspose A Preview of MATLAB RELATIONAL AND LOGICAL OPERATORS. Smary of everen copabiier << ess than & AND <= _ less than or equal 1 or seater than "Nor Breater than or equal equal not equal median soet prod ‘maximum value ‘minimum value ‘mean value sum of elements product of elements ‘cumsum cumulative sum of elements ‘cumprod cumulative product of elements approximate derivatives histograms 1-D table took-up 2D table look-up ‘correlation matcix covariance matrix cubic spline interpolation MATRIX CONDITIONING, ‘cond condition number in 2-norm det determinant orm —|-norm, 2-norm, F-norm, ee-norm rank rank Feond condition estimate trace trace 6 26 chol Cholesky factorizat lg eigenvalues and eigenvectors hess Hessenberg form inv inverse tw factors from Gaus ination mull ull space ‘orth omthogonalization piny ar ‘onthogonal-riangutar decomposition qe QL algorithm ref reduced row echelon form rsfest convert real-schur Wo complex-schur ‘schur Schur decomposition DECOMPOSITIONS AND FACTORIZATIONS ince balanced form rdf convert complex-diagonal to real-dingonal singula-value decomposition OTHER MATRIX FUNCTIONS. ‘expm trix exponential fogm matrix fogarithm sqrt matrix square root funn arbiteary matrix functions poly characteristic polynomial kron Kronecker tensor product, fanls non-negative least-squares | poly characteristic polynomial roots polynomial roots ppolyvat polynomial evaluation cony multiplication polyft polynomial curve fiting residue _ partial faci A Preview of MATLAB Summary of arent copes if elseif else end for while ‘brenk return pause pause until key i SPECIAL MATRICES compan flag diagonal matices eye emily matrices ones constant matrices zeros zero marioes Fund random matrices Togspace —logavithunically spaced vectors teh angular pats fankel Hankel mauices toepltz GRAPHICS tot Tinea X-¥ plot loglog loglog X-Y plot semitog. semiog X-Y plots polar polar plo bnesh —_3edhmensiona mesh surface cantour contour plot grid draw gi fines tithe plot title Tabet axis labels text wit text on sereon als tnamal axis eating lg ‘clear graph screen frome home cutsor meta graphics metafiles print hardcopy TROL FLOW ‘conditionally execute statements used with if tused with if terminate if, for, while fepeal statements a number of times do whi break out of for and while loops return from f

You might also like