0% found this document useful (0 votes)
33 views

MATLAB Unit 3 Part 1

matlab unit 3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
33 views

MATLAB Unit 3 Part 1

matlab unit 3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 32
UNITS TIL Numerical methods Usthg MATLAB : — Some. tical probleme that are formulated tn. ‘selene! ‘Engineering’ Will have diffradt or Tmpessible Solutions — For solving such mathematical problems , ‘numerical metnade! ave commenly Used: 7 ManiAa has a large library of functions for numerically Solving, 2 mzthemattcal problem, MATLAB has Symbolic. Tool box for com: ferentiation | TFateGration and Differertahon ave hwo examples of Symbolic applications, — They are. cedined as functions tn MATLAB. Peting irtesration ang —The derivative 4 afinction fx) is denoted as fCx). HS defined as. the Yate q chonge 4G) With tespeet to The derivative 100 can be expressed as, phos Grande tn tes)) _ dito Crone nx] de {fe atta, ! * aes — Hee 4) iy called the frst den'vative. - — FOr periorming: numerical aaxn differentiation in MATLAB, the function ditt is used. (dite -command) — Since, differentiation ts a Symbolic application, The symbotic. differentiattém has the form: [RG] » GREx Here S'can he 2 previously cresied eymbolic Expression or 29 Expression that can be typed» ies) ’ —Here differentianen fe carried aut With espect to one. Symbolic variable , S16 (S.Var) “Here, differentiation Ts carried out hh Yespet fo the Variable var, — RE Ls/n) or Ate Cs, var) =This command is used for Second or hfgner (nn) derivanve. ~Heve'r fsa positive number. — fer ne2 the command vill be AtheC$.2) + this vt] Give ond derivative of 51 for n=3, the command will be dife(s.s) which oilt Sve wd derivative of 5. 4 #OeFine %,Yand + 2s symbolic. Variables, a Bw) sms xye Sz exp(e"4); BreCD a kssignto % the Expression &* vivifferentiaie S 4 ‘ ‘ ett ts dis [Aixistexcta) 7 Araner date" 1S displeyed I Ves Sy Btcsctate):] 7 Aaston Rte me eapression sycostar, ee) % differentiate R SB NOY *cos(3%) Syms Oy 3 = exp(x4) fon: (a x"atenr(X Heb Athexp(aty) 1 Anker towers utet ts Ae abue + USELE MERU REE LELER ET Numerical ptegeation at are = site Gratton 1 3 Corman, matematical operation in Selence and tnGineering , — Examples fiw Integrals are : dcalewating Aes and Volume. di) caleukating Velocity from Acceleration, (it calculating Work from force £ displacement, @ — A definite totegral @ 2 function FOO from 2 @ & has the owen, = = Peo-au —® - 2. A -t's graph ts as shoon beside £ — Fo Bxpessin®, #00 = Ttegrand abe numbers = Limits of integration. tre aiee Lekwen At ond te —ishen & definite tntegral 1s Caleulated, £00 b aways a function. * ishen, ‘the Thiegral tg calculated numerically, fx) can be 2 function ey a cet of ints. == fumerical Integration the total aes 4) fs Eee ey obtained @ by diidingthe area into small sections. — After calulating the area Gf Each Small section, all the fndividual sectional aveas are added, —Thiswill give, the total area‘), 6 fee MATLAB has three bulletin ees Functions, cbayad dhquadt and (fi) trape. | When finds a Runction, quad and quad! com mands are used. | for integration. Sin Bare tint? A = —hohen Fle) (S given by data points, rape ts used - Nee only definite | egrals can be Gvalunied numerically Numerical talearation Methods Tp Aahasie the Integrals numerfeally three. metnods are fplementad “9 MATLAB. They are, QTrapeziuin Method ,1 Simpson's Method ‘and (i) Romberg's Method . Jk the Trapezium Method The Reperiun ene This method ts used-for numeric: al tategration - = xt has two Variants (TyPss): (@ the Tapezsidal rule and i The veeursve trapezoidal rule. @ Wapezoidel rule: Tht vedio caleulate, umerteal Tehegration of £01) ints , b =k wa | Ainetins (#02 [Brees ~ This wle (5 function 5 = trapezordairule(f, a,b) for ket (4-4) Xe athte: S2 sefeval Fie): end Ss h* Cheval, a) feval Eby) Ja4h's » LIRLALVTVAIIOPP LILI VVo LI Nee NPn ee pe Ls ro) | Regursive Soper fille : This mule ts ako tued fo calculate numerical neat ~The Mhtegral 4-the function fi) beteen 2 ant bts caltwlhted using the “formialas | Soc ab Segcws sce) Examples 7 peciursh caleulate the folloitng tntegral using 100 iterations of the, Yecursive trapezdictal rule! ' \_ ae After typing this. program cave it as thtegrandoL-m | — Na type. the folloiaing ta. command. prompt: pp recursivetrapezoidal (‘teqrand' o, 2, 4) The accurate Value-for fhtegral is’ 4.4913993461398, The Recursive trapezoidal wile gives more accurate results compared 40 the Mapexhen trapezoidal rule this methadd ia abo Weed for Tumeyteal integration Of tthe function FOO + 3 =Te's of tho types! @ Simple simpson$ tule and dy Composite Simpson's mde, casingle, Supsepa les Lusing this tule,the definite. tn between the paints af and 'b 18 in the Sfolement + egral oy tre Aumcton fa) found. THs as Shown ath. : YA prograen implesimpson(f,a,b, tolerance). ~ (b-a)p: zeros(4,3)2 (= feval (A, (2 cathyyzie): *(cUn+ 4c) + )/3: S22 Ss tolerance = tolerance: abenlubeaner 2 tolerance: : ze(ab S sa absduteerror toleranced], Pileeoeeeerpevereppeoee 2] 0 4 ty compesiie simpsons wles j TS ule will calculate the definite Integral ey the. i sfunchin Plot) Bt Seustdlistert points, Yo atkh k= e/1,-IM. = Heve %22 and %m=b. —vaing this ‘ule, the funchon F020 fs given by, | rs er Simpson's wule is were accurate than the Trapezcidal rule. This tule Will divide the area Under the function £60, Ti Vertical strips. Simpson& wle Estimaes te tategval 2s, = [ Fea +406) +2 R roy 4B Ate a) \ i “arruaa fenchims MATLAB has three built-in functions fv numerical integrahon They are Wquad @quait ara G)trape The Quad command: —MaTiae has a-function quad to cary out numerfeal integration. —xt5 ake called as, quadrature | ausotive, ~The Quad Command uses “Simpson method GL integration ~The general Symiax op Quad asmmand is, the Quad function can be thered 53 a ‘stving-expessio! of as a'fiuntion handle’. om Use numerteal ae 40 caloukate the following’ Integral: se Ge? onde SE The plot oy the fimction for the given interval o) . 2 . > > > > > > > > > > > ’ 7 : 2) Y=¢ptad(@champasana,o,¢) ays 2 N60q- Were Qchampqsana ts Command. The handle for the function inthe quae! The quad commana ws ale ais —Qusdl command ts alo used -for numerical integration for high accuractes and smooth Integrals. - The Syntax-for quad (last letter is Lone ease L) Is shawn below: a a - Y= @() absit).“expCabsts) T sQuadl-2,4) che tyapz commana : has rere a a — this command 73 used! for integrating 2 function that Ts Given as data fmpoinia = The general eyntax fs as sheont Beeae o PESO! Here Wand Yate Vectors. This command Uses, numerical trapezsidel method ‘of integration. Tealauate the Integral ofa vector ihere the SPaing beticen data points is + os 4 Ie fad+fes — This nile ts aauvalent to approximating (aproaching) the area of the trapezoidal under ‘the Streignttine connecting fla) and fLb)- jumerical Examples 4 W Use “the Wapezoidal rule to numerically tntegrate Pla = 0-2495% from aco to b=2. Sd: —prom the basics, b + Fla) na (Pid -des bear fOr | 3S Here, fons ortes% —-O 26 and bt2. now ne shal) Pind out fla) and fb). fiay=flo= on. 4250) 20:2 —@ Nee, fore PD = 0-2 4252) 50402 7 50:2 @) Noo the Integral Is, x. Com fonela) t- 2-O (F(2)4£E - 2 Te ax(sontee z T= 50-4 is the munerical value. RUVARAVOPPIPLPOVI PP PPP PPPLIOS PPP PRs > The true. solution is, freode = @axtnse) [> ° = (0:2%2-412+5la*) — (0.2%041215 (0) = 50:4. Sohin§ more clearly, 2 foansnss ae I forme + 25a: dk 2 : = og 4 12-5(4) = O4+50 Simpson's Rues: ‘a ee — Using this We, a definite integral ts approvimartec! (Approach With more. accuracy, —This mule uses, higher order polynomials. — There are. two Simpson's wules. They dke+ (b Simpson's Ya rule and Ui Simpsorls ge tule. eo) — Simpson's Ms T This rule will consider function Valu at 2 points - “The polrts are: D (ao, FO%)) dh (48009) and Cy (x2,f0>) « ig) simpsorls Va rule. a = Using this rule /the. tategral for the function £60 15 a Eskmated + on = This wule uses. Lagrange polynomial inter polation t Find cut the tntegral Of tre function, £00, < the Integral can he Hvitten 2, ze [feo rs) f ened Cour ere + we Fo) 4 ((o-%) (70-%2) C1-%0) (4) F043]. doe ve od nD HC ra 3p [Pero +4-F04) + £06)] = bof ay z | wThis mule. gies Exact vests forthiid order polynomisls at's derived from parabola. ARVUARGIAP PORT P ITE sme] use simpsons Vg rule to integrate floor 02 +25%+ 3x44 214. fom azo ED bea, Wen function ts, fO0-0.2 +2524 3x74 2% 4, Here azoand b=2. from ‘the baste formula, the integral con be found Use 5 nay Gf ot 4 PCH) 4 FOL) ) te ay ff (Hed ABC) +031 ay fle) = fla) = 0 2.42.5(0)+ 300)" 42(0) + floy= 012 -O Also, £O4).¢ O2t 250430 20) F 2024254349 Pou)= 202 >@ Nix, flog) = 0% 2502) + 30204 20a)t 2 024504 812+ Ba flt)= 14-2. 9) Neothe integral Value [Ss obtsined fom éqn@), @®> +_-(b-9 [Peoesscont) € re Q-o) (0.2+630.2)494-2) Ee & the Numerical value. he éxact integral 5 obtained as follows, 2 (Gor ease 304 ant) dee 2 ~ 2 a J tare glare ee ea 2 é S 8 fi dct 25 (ede safer alee os 2 2. aoafa]? wey fae : I E th “(F| HE o > = 0r2{2-0] + 2ie*- | +(e + + Sor ef] = fo4 1025x442 r0-4(22)] 4.2] Relative Grrov ts, Jee] = AARDADILP SILI 9 DY | Multi-ctep application of- Tropezoidal rules . = Fora single application of trapezoidal rule, the \ Cuboff error (Truncation érror)is obtained using Taylor series. . =rts given by, Here. = tsa value between a and b. Ee The Fruncation Error (Approximation @veut-off Error) fis ‘teduced by using the Smaller Integration fntewal, - Ep multiple - appuicstion trapezoidal rule, the Integration interval from ‘d to'b fe divided Tnto a number of segments, — Then, Twapezoidal rule ts applied to Bach segment. — Divide (a,b) Into n segments of Equal width. —Now the fntegral fs written s,-fy the function ffod, a , —trs as follows: é m 2 {teorde =f de foe (Fee + fbn oe % uw. a Here az %<%,%——-<%Xy and b= %0<% < Man +h ceseces | + HOC) 4 Fe) = fesse Hpbi tes] os tab feo +25 Feary eee] et fl | [Rowe atone Ft) aa rm (be pean a 7 —The appreximation érror 1s the sum of elvidual Errors, : P v Me uean® gS) 2 — SLE HCG) ia er ee re Example ed Use the 2-segment trapezoidal vule to numerfeally oul integrate, f(x) =O2+25%+32% from azo to b=2. R45 Sel: Given function iS, Pode 02 +25%x4+327,—D i Given Umit are, azo and b=2. She Integra! for fl) using Mult step application y trapezoidal rule fs found 3s, an Here N= No. d, segment = 2. MARA ATAPR RL aes nr» Ronetenee fe "nz2=No Eos5 22> zach) [Penrefore se ¥ ~© here. Fore) =F(02: Flu) = FD 202 Pom) = F@). @BNeed to be eolved. nied, pom Eqn O, Fioe on r25xt Se” F(0d= o.n+2s (prt BOY = 02 = fe23) FU) = 2 42504 30> posta 9 Bar e282) oe p2etae 30 © 2+ 50412 Fi) na flap Wines Fo Eon @ feet] + fore substituting: Ft) FO @are rx (2-0) Ee < 2x 6227] re lee) “z (2) : ca) Fatgtl~ Ea 2 go neat The fxact tiegral value” is obtained as, 2 fe: D+ asa) dot d : ms 2 3, 2 ov (heer 25 (xrdu + ale de x 2° > 9 pelt mS ET: ooo BO +32] 3 orate) 4 jn5(A0+ Ce) a O4450t8 Js the Gxact Volue of integnt. 2 Therefre Relative Error [s, lets PASSE oer oo a oS 3 | oo a 3 Linear Equations | —'& basic problem from Linear algebra. is. | a to fing me $ _aglittion of a linear systern ease = coneider the system of Vi Linear algebraic Equations, with A Err — Vi urviknonins « a —they are Given below: awnasazes rami = ms py i | —hapitn = Genera| form of 2 Ba %t 20. -epyerl Unersr ensoting) —® | sen 4+any%n= bn Anyxit an2%e* Here, the coeees Bu, ia=: Bin 2 324/203-° Dan 2 Bnt,ma—Snn | Be Constante + — our task 1s tp find the unknawn Values Ahan 2 Beare system vepresentect: by ®) as “the cider ‘nl system tee ee, | = the. above tines ~ eee sytters Of linear Equations ave Expressed in matrix x form the seme Aawations Con be written tn MATLAB | Zolution of Linear Systernst The solution of Jinear system of Aurations can be found by to numerical methods: Divect method Ss and Gb Grdirect- methods) poets, metals, 21 Elimination o ianélimination methad 0,6 Elimination ch gaussian elimination methad se —Divecr methods: Uned to_solve a systern op Wi Linear €atiarions with ‘W'no- é Unknarsns, -eonstder the System, A He Butyhan th tua%e =P re Baty Cane +2343 Be © ba agit aante +223% = te the augmented mahi = From this, be shall Wt {an az wa br & -®D Rao Ra Bat py 3 An Bue, DO- ‘1 > asr= Baty, 90 ©- (were |%" Oo aa aa ba| - © O am ass ba cua Ais br VRQARP PROP PI PPP PP REPL PP Piaieenereiameess now we perform, Ry —p Ra~ Sae-(Rd Aan - FBe CRD > O @ = asi~ [au ae we FF Wr cee a3 =| — oe) 16 Ss aaa ba — puagmented mam () 1S an uPpertvianguler System cee eau be soWed by backWard substitatio Lone Exact solution is obtained « aalve the Eeurstions, F ee ee pet %a4%g ZO 5 Bxt 2% TBS using Geuss-Eliminsnon method. $8! |iven Siysten & Eaucations Pre 2a Wrtts = oO yp 204 21 —® byt Ala FVD =16 Now the augmented naire te, CABI= 1d] te 1] -@ ‘the. Glemenils tn the upper triangdar 1g must be mack zero throudh Transformation, Sypem.les 3, — perform, Rp 2R2.—3R; and a> 2B-R A= 940A 9+ 9189-30) 2 0-7 230s 497 ale) — 20) m 6-8a tease | 1A 1GI—~2 — O- aps)~BC10) v Bh-20>6 2 -NoW The augmentécl matrix becomes, [2 1 | 10 023&|-O oF - ©» [2/1110 oss o tlt 22 ANowWe perfor Rs —> Rs-FRa fo get ‘ol value in Upper trionguter systern — Fe F-70090 It 9 1t- F@olt-29 -4 22 22~3(6)~) 22-429 90 =-nod © becomes as, [2 1 | 19 21 3 6 |=Ca8l ~Aibrges oO -4-20 — pron the Sugmented mahicfiern backward substitution, 244% =)0 ° AB & 4, 2-20 -® —Now, — 432-20 > — Substituting %25 tn, e+ 3% SE hp pS) EE ~ wow subghinie We =-7 and Bas Mn eam 22 MaA Ge 10> 2 olay +(-9)4(S = 12 > 2% F=10 = 2x) =I — Hence, the colution for the Linear sysiem op Bauation are, % H, M=-F And Woe, a RRGORePee eee Pee ee Z) solve “the Fomatons, x+y42 262 Fons, aye 262 at aut e222 axtytaE Using pavtal piloting Gauze 2-209 32> 11-2099 1? 3 2-209 3% Bo 3-30) 33-3 3 3-30) 93-3 49 RB 94-32! 252° pp» 20-24) 22-18 ipo 2-2? @ wecones, pit rt 6 pael= lo 51 2|-© = the pivot asa(ze0 Here ts broreformed to ROO=S* performing KR. Tre @xls]* fo a1 Jr® 0012 ) a The set ©) represents on Upper tangubar sxpiem Pom, 4M +e = 7 ata = | eI Za=2 meubstitting, 222 In ~ypee! = ~yte=l a{g=4] —subsiting Z=2 % Ye) in L4y4+256 =» wtlt2=6 = 63 [ezal — Hence, the. solution for The given syaiern oy Eaustions fs, we 3 Ys! and z=2, RURLRPIL PILL PP PL PLePoLroropoDogg> Oa = KX thakat + Kn Xa AX= RAK tH AME Kaba since fon ©. my= Aig. +Katin 6) 7 Bey Wie Ans becomes 2X 730 Ke. OF RABAT Akt Kadai tt kod n@ — Once. aGin@is multiptied by A we Axe KAN M+ AM Ke Pha Agigt +t kn, we Bice KM + Kota) Anes (06D gt == = At En) + Kn Xn 3 Mes Kx te dd tot ke hrat--- — continuing the above process , Ne get vr, %n Aw = kK Ay Ra Mat Ky 398 + Sn let k= Arby Vecer. aFind Ax (he Knad that, Ax Ax.) mainte AK as, fee 28 Uf tes ithe first opprocim ation. — Here SP. First approximation to ‘the Efgen Value, 2 2 giveth approximation tp the Eigen Vector. — similarily we shall find Axon AR. xO] This i= the, Second approkimation » ~ continue thés process 411, x xP becomes negligitie Then, X2Larpeat Eigen value ana Xs Largest &(gen Vector. ARUARDTRPPRIPTIPPP PP PPP PP ISDS Pia 2 [EERE] ~Rind the largest eigen value and the. ls cote sponding Bigen Vechy af the matix A= [ : “Ti 30 ae DSleh he Trttal Aigen vector ts, ya. [: | aX Vo - Ao SAF Shen matiix ° aS 1 (25XD + 1(o) +260) saad Se ne ars | 7 [Ce 12 texer £0x0) 2 o-allo 2.1) + (oxi) +6490) wee Ef] -sie “=[e7]0 2} joos se Jove 2-08, Here, Bee ry ] This bof. the form, AKa AX ov X= 252 Eigen Value, Xo pi dlecee the — $2 the iret approximstion-io the igen Value = Y= a5. First aipproximationtp the Aigen Vector= xO [eed nn, AR. Oy PE 2p AKL Ss AsiXh eels Sel loom 2 6 <4| Loos 2 le + (1x0+04)+ 200-08) Ay + (20-089 4 O(oo8) G (xt) + (Oxo104) +(- 4x10» 08)) (- B+ 004 40:46 \qolz+o 2 +0 -032 Ps wo a a cs a a yy =the Second approximation tO the Bigen value = XP=26: oF Mio, the Second approximation t> the Bigen Vecty = xn, osez ae - Bs 1a3e) =| ia32 404392. 2 @ = aslata |) 00450 o06ee RELLUPL LS PE Non the ‘rtrd Approximation 10 the eigen Value = poiaze = cone spereingly, third 2PPmxKinratia’ 1D the eigen — Vvertor's 2 [tne lo-c6r x x 1 @ Pere w= 11 3 @ || ooas0 ° —4|[oosee EP 2 25-1826 on acta — Here, ‘he theitel apprcximationto the eigen value = 25+ 1826, Now, fourth approximation. to The E/gen Vector = xn [: fourth 01045 ovnses| Gs ya 1 a). mre, ax | 1S ||ooasi 2 0-4 looses = (esteat ' 11353) = 25/82! | sis03, ae 351621 126 | eat | be — } ws asneai|— ! | 210451 \ o.06es H ~ Here, the Fifth approximation tp "he. ergen Value =X8 2g tsa), Aus, fth approximation tothe Bigen vector = = [7 Leni] 2 e6es| = oO . | + the. lavgest -Cigen Value = 25-182) ang “the Comespending’ €igen Vector = ‘ogsi). ~ 068s i) =stnce x

You might also like