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

python

Python book

Uploaded by

Krishnendu Patra
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)
16 views

python

Python book

Uploaded by

Krishnendu Patra
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
You are on page 1/ 24
Experiment Name : | Dems oharante-nied? re = Emp. wrnay (Ll 2,3, YD) Ayeex) dears ‘ muenpy and array'S Leo) 4 > tum &) 10 Fermafion & 2D Amray 5" S>> De np. apray (CLP 2, Pog Ese, [2 87)) S>> D qrray (1204-2, [3.42] TLs> dnd im >. yeanvay (IEls, 3. 6) ACY an PT) Tw, 4% 39 Ta, % 2777) % reshape (2,6) - orray China, 6 6, 9 7), T%2,3, 4, 3, zp) Je mp. cmmay (C2, Wt%as wi 21). Ayre 2 Feat), Teacher's a Experiment Name : weray(L2O, Go, 630,250, Who, 26 1) |__2 = mprawroy (T2161 6%, 95, Yl WT, att yre= tomplexd 2 qeray(T2.0+6.0 » C0485 , 69,04 OS, 2504 BF Gio 4 oj, 2010-1) Ridtyp d_type (' complex 2g’) Sima w avesy (CFET 1, 12, 647, Te, 9, Fe] Cie, 2, 37 to, *, 2577). we ne, dinspace Ct, 3, 26). veeton' ged operations ¢ b> x cop-array (Tt, 2, 3.47) >>> Y Snp.avvay (LS, 6, % 87) XY array (TS; t2 2, 927]) . 2> x/y array ([o2, 3%, FREE, %S 7) , > sor ay *? array (L126, 220, 380, 5287), Stowalian en array i ga aps grray (E% S$, 7,979 dey jp fn at print Ci, ends‘ 7) 25 49 Teacher's Signature. ante ysBSsniee Experiment Name : linear Space + lingpace (Start, shop, num: £0, endpoint = True, rats tp2h dtyee = None : anise o). >>> np. LUnepace (to, 20, £). aryay (Tle, 125,15, 1S, 20.7)) Endoving ef array t mony. Grray (12, & tt, ty, 1, IT) . > fol Za frjes 4 xieO=2 pep x Frvtr07 a stant 24, Stops beer 26 ep=2 avray (fs, tl 74). Marnp Methoda om _avrayst + =np.arvay (E24; &, 8, 10, 127), D>> A, shape = C6.) >e> p oA, reshape ( 2.3) Hmvenked A a 9d axiag ty ea >>> me array (TT ow 6] Ls 0, 1271) p> Bishapge = (23). pe A. Tepire (2/3) sop Acarray (LER 4) $2, # Marray is wesieed tee T& ty eID original aay Fp mocified b> ae nparray (L438, 6,72) >> mew = np. append (x, 9) >>> new = AP. apeay (L', 3, S$, %, 9))- o> Yene, ast9y (Lilo, 201). me. oppenad (x) - array = (ee BD AP, KP(A) an ray ( T2711828183, y.UBIe 990%, FS 690SCT, 12. 182493 96)-1) Teacher’ Signature... nt ee Nore ys Experiment Name : plot tee polynomeal ¢ from mumpy _impert poly Jd. import matpbtlib. pyplot ar pdt \ pzBlyld (Lr -s, o)- yt ne dinspaee Ctr uv, leo) . I Plt. plot CX, ylxe)', pw =>) pt, axhlineC ) pik. Show C J fe hs 2b 2s 80 WF vO - . ploting im 2D >> import matPhot Lib »pypdot or pit plt, plot (> >> plete ghow(_) a To create ko plot Example: xt[l 2 3, 4 £7 For olisplay . a Lt, &, %, Ib, 2S). ple (% y) - plots show ©) tile swith ke nerd _ompumonts 4 plts ple Lx, ¥ Lino style 2’ , marker zo, tnouer= "black ). plte_howt ) Ext bl oluc) pled), 9¢70en), 9 (slew) | k (block) _ m(magotad, fri '—' Ceratinuour Ane), ‘~~! (broker fino), ‘_"(Une- Pot) . plet pits anrtays and functions From Numpy ? import numpa ov ne - = 7p, ev P(-*) ple, dot (x, y, '—6') pl. gwd OC) plt chow l/ Teacher's Signature..... nt ae yypssnicre Experiment Name : Pogo No xen Linspace (6.3, 15, tooe )” | on ys rap, exe (~ o) elt + plot (m4) =f \ pltr xtim (©, 16) ‘ \ plt, grid C ) oe \ pltr show ¢ ) \ pla with bnoizontal Line + x= np tingpace (-2 appi, a np.pl, 16d). plt- pbt (hk, ne.sin®, 1822) ple, axhhine Cline style ='--') PLE, x Laat=& 1b) SH Herizoned axis Une olvawn pl. showl ) so £L He spaco in betweon xenf, linepace (© Uaeri, 100) y =70, sin (4) elt, pleat (ay, lowe 2 ‘Wack’, lw +2) , ple, Gib- between (110,¥, wlowt =! gray’) pl. show C) Mutliple plots in one Soune we np Engpace (1, 12,100) yrs nphinw) 2 = negin( Xt"? ) pit plot Ors Xr) » plt show (__) H x-axis Uwabs shown in plot H For feo phi jn a same graph Teacher's Signature...... Experiment Name : arto fol = eval Cinpat loworlin, upper Goutal fr’) ) while ft €le) > 0 > Print ('ne rect in ftis interval”) breaks QLle_ abs (b-a) > Kl; Xm = Cary /e TE fxm) = Print (‘reot!, xm) break iP PON) =4lo) LO box hese 5 aQcam print (*yo0', (otb//2) lower Gm, upper Um, tol F,(0,0,0F weet ew SI PIB AS - O° Bisection Method | - Algorithm ¢ Lb Doline dre Function L(x) . + Tnpuk 4, &, tf 3. TL flys fy) 20 - No woot exist 4: Else sek | Xm = Ee 5. TL #(%m) =o 7 Xm fe KS woot exit &. Tt EO)» Fm) <° Set b= Xm, else set A= Yn, A. Repeal steps a-© unit (6-9) >tol , Finally tgrcot 6 SZ Teacher's Signature Experiment Name : def f(A) F Betw YP Ka S me fal = eval Cimput Cinikie poraty dolarane\w J) dx = 0.00) fen = (Fotds) 4 FO d4y dx) Chle abs (Pm) d= ted | x= x- Fly] F PH print (troot’, x) indial pomt, tlavance % 8.001 Took 21 094 bYlIO4St& SI3SG Brookport numpy 0% ne wane, avrey (Coot wed Le Ht) Dore 2D, Th 27 7) Newton Raphron Method ! ~ ithun ¢ : 2, define ft £10) e. Give ho start pomt a and ttarona valua 3%. caftulal eS) and uplot x until Lfoy/> tol mH) r Experiment Name : improf- numpy a P _ det newdentrrvacd (% 9,29); aczlen (x) A=xTr] - x00] & = (op *Lea VA weft, Keb $= yto) fer i ineromge Cn tos ne nerch f(y) St = weff X9Te] wett* = (t-W)/kty) k+ =I print (8) return (6) TLS 101 1s) 201 251 OY - y= Las, 1081 144, 59 , Bb 496] x int 2 Les 10718] Fnewton tor ward (% xO) feeK pin x _ sat] CE.0 56198 $b 616 G6) 63 SE Fs BXOOIe 5 (B52 pore ae Bae 220092 BLL 5407001, 105.0, 292-4268] Teoeht signa. Experiment Name: imgseot_numpy om ne de{_nedsmbackward Oy *P)*. mz len (x) h = XEIQ- x00} t=lup- xt-/s coeff, kK=bL) Sz yT-n for_f in mange Os 1/-1) 5 ye np. dil C4) St = coffe ¥L-1] coeht* = (+KY/(KD) kKt=l print) ‘refwen (5) xt fel 1S 21 25,36) ye Lag, we. 74, 259, 364, 996) x iat = Ce 13/18] Tnewlonback ward (11 y XP) for xp in %— int] -16t- G00 G000000 4002, [08 » 67999999999 & 49 1 055999999 9F 0° 3441999994 & 1G 125999999 Tay. O3ITIO TAD Tey, CODD Tuy. 740288 757 Teacher's Signature, Experiment Name : 224.56 222,999 2226 39/2 QL BLL $F [56.87 001599999997, 1yy 740268 , 222+ 52.6648 ) a Teacher's Signature, Experiment Namo : Tntog rod i @ [fee [Ped a a Define integral sf a Runchion with single variabls, #2 J’ fo9 det “a So (et) = pt LOY LED py + 4 Ee DE Lam Bras | how ¢ =e we may tusneart the sevice at some poink according do Hor devel et accuracy we may sok and to tan, ombubort im WE may want fo dovle deb POY 1 Thom x**? a,b, n= % 1,100 p—b-V/h T= 0, ORD HOOT Besum (POF) T 0 rangec ay) print (‘value of intagral’ 2) voluc ct Integral o. 250025. impor {-_numpy a? OP x, bh = npeline pate (S004 vetslop= True) bea Yor Be 0,6 eb (LO) + FeI)-+ M(Sumb T!7-ELD) exint (*val ef integra a) wel of Tn tegal 01249 67016000 0003S | 7 Teacher's Signature..... Experiment Name: Rectangle Ruls. (noo) Tis fs simplest mo, Hore rT he Pode 2 hy pod = Yo ne vole” of ie gmitea rad fx the arte ef the meclangle Withe — with hab-a and bight Yo. wrmpotite vectangfe Russ To achive better acewacy we Aivicle the intorv af [ak] into _n equal swhinterval such a2 A=KoAR SKad-_ - S*nN=ZE - Thur tee definite integral in composite, fx orn | D> ft dua Suda f odue--- +S yelx * me my =| we Aave hz b-9 and FOW= Dp above Yt) anh Th2 widte et cach interval h = ee _Aetly Reckang wlare rule 4 jategr abion over oath Ses inforval we get the compose. from ilar T =i ode Hh TRI t Ft oe Frape2vidal Rule C=) bye 2a, Kb and HY PCA) HW Tt Ode gc Jermde =f F9e toyeyan= fly +t yw hdt a * 3 Thy + HGH )S, H Vole tt iotegr al 7s Ha aca of Sac pe het) trapizium Wide ben b= b-4& and boundeol & Fre. ordinals Yo ama | zn composite fem ula. rafyhe BUCA) 1 (G49) 4 -— + Cn Fn) } 1 FIJI] - a = GAN Aesth Sant nn = Eye tA tt” Experiment Name : Ge : Peroah a me Lmentenal array of- 60 randin numbers in sine tater af T0.2) wilddte hel? af an appropiote funcien fro _vwondym modula tn Numpy. tompube She clandand deviation cf those mumberts P_import numpy ee np f ponder numbers = nes tandem. uniform (0, 2/50) std — deviation = mp. stol Crandem —umbots ) print CW’ fandom Numbers“ vandom - numbeua) Crint ("Standard Deviation (2) 1) stl — leviccion ) S fot an eblips® be given by B+ deel Dhars 2 vahume isk 2) deb wmposite-timpsens. yuls(integsand, a, oh)! G hoCb-a)/n x one. Lngpace C9 b, A+) Yrnteagrand (x) pesulp a hy ( alot 4 nf Sure dy Lit t2 27) + 24 028 Um (TE 252)4 91D “) Teacher's Signature... Experiment Name : vefwin result minterwele = (to ® thety min = 0 theta — max = np. pi /2 pz tomposite — cimptens — mule (tnteynand hohe — win thota mon» n — intervals) : iv ("Parc am efor (L) cf tha 2lipso’s” LD ig use) the fmg Gen appro wate numpy function ». create 4 ong Leroy Oo numbers fern | fo 9 and ten eeshape thy aveay in make jk a BX3 array. Now treot this as a mate”) n_& suinmotyie mali. bec sere orclest usin, evden wring Sete matin . Vein Voor 4 ; < dot ae fo pumpy » obtain he ofgan Galie andl cian T oT chock it ts omen vettors att orthoanmnal ta J or nat > import nu np- ev igi nok — array = ne. linspace (lr 2.9) . maleix = oviginol — array» rechope (3,3) ymelne brie — mafia = matrix Q matrix .T eigenvalues , eigenvectors = a np. linale, ey (Symmetry e. andbeint) + | eothoge nad. che ok =rp.ahelose (mp. lob (eigenvectors , eigenve chovs. Tt) es eye(3)) point (“ceiginal Matrix” ) print (matrix) poink ("\nsymmetoic Mabrin W) pork (* \n épenvalues 2) Teacher's Signature. Experiment Name : weind- (ei envaluee) pein (yn Eger ectorss” | i print (Vo Ave fre eigen vectors calhenena) de each other”, othogene/ check ) eat your (9% y) data is given tn tno form ef Usk ct tuptos Gke Howins § [er (23) (3.8), C4 12D,(5:20) ], extrack tine clad. in inches Peon of x-list and y- lst ancl plot foros mat ploHile. Sth X-liolt on tte. x ands pehusen 0 anal andl Y Limit andes. year bertweon o ond os. 7 import matplotlib. pyplot or plt dota = [ltr 2), (432, 8) (MID, (5 205) Ke valucen= Tpoint 1) for pint in dota’) ~voluss = Tpoint 1 fr point in date) elt. plot ¢ _ value values, marker =o’, Gneskyle2'’, eoler= plb_xdim (0, 6) ple. shim (0, 25) plt. xdobel Ux) plt. ydabel Cy) plt. title (‘Data pot) pl. show (_) D ts limabe A) toa fe KO eg ella es: x 8 ry] te [18 | [far yt] ate & [99 [AF so] a q 5 *, use _Nowfim= Greg ory ‘ntenpaladion ak with Fegeseed ot bach Teacher's Signature,.......sscsssessensesssse Experiment Name : xavalues =np, array (['0)12, 14, 1b) 1B, 2, 22) = Valuts = np array (pas, 66, 1,93, 94,53, 36D “ted mewfry ~ gr gary. - intexpolafin (x1 tag et — = len (x) rE NP. 2WvV0s (CNM) 4E,0)=y foe 5 in range (lr n)} fee iin wange (n-j)! £ fei ect Lie 5-1 -F LOF-DV/ Cri +) )- xtD) eresulf = y TS) derm =|/0 foo Fin vange (un)! term = (target x-xl5= esd + 2 florS]” term retyen result tary eb. wets estimated. value = neler giegery —inlenpelatio CX valuxs, yvoluos foxget oo) [pring (8 Extimatod £CIS)i% estimatfed) — value) E ols Maing Pecos tunclions io the same. graph: 42, yse?, y ron Tooke ELerts) D> Lmpor|-_nunpy oF rep ‘mpenri- netplolirb. pyplst a tl dot fine LC) mefyrn Xt” 2_ deb func a(t Teacher's Signature, at he *5eNore pe Dat Experiment Name : mofwm up, acp (7/2) det fune 300i wetwtn s*x xivelues = ne. finspace (0 1% /2) yovaluet 1 = func s(x values) values 2 oA 02 (x- valaos) gvelues 9 = funes Cr _ values) ; pt. plot (x~ valuss y values, dabel =*4 aK pit blot (x valuos, ¥.veluar 9, obola'y = A/2)I pt. ple OF values, yiveluss 3, dobet s'y= 5%) | ptt: x hobo (‘x’) pk. y label Cy!) okt tbe (‘Graphs of Three Functions’) ph, Leo end C) elt. shows) (QF vivite a python cevipl be defer nina of frook ors real ef deo. equation! 24h 990 [16 x24" 22%= 212350 WhIA 7S lose 4021S Bagot numpy se WP Avon Scipy, ophi mize imporl f sh def cauefion xi = x crore M4 — 11992003 FOX "KE 22H - 23> inified. guess a5 | _meot = f solve (equation ind of guns) print (" Root, rat). Teacher's Signature. 4th yyasenire Paga No... Dato... Experiment Name : (S-Given Gos matrics 2=C 5D) ord B= (5 §), weite theps to conframdurt (an)? pl at D_ Tempore numpy or n? Azar. omy (EE. TOD). LEMP. avray (LT 96) D4 81)) Am transposed = np, dot (A, 6) 7 Ph. Peanspa ced 2. dt (8,7, AT) - vesult check =mPanray equal CAB— beans posect, BA Gen print (* Matyin age) L_ frivt (Ad print CMA wy Matyi fo’) print (6) . printC\n (6Y 7) Print ( An —branspos-ed) print coin OT AMT") print ( ptr. ¢ronsposscl ) = Deiat An Aire WOT omni pir att oq vad J” resus chook ) & enpet H& Alinsing integral fsverirty Hs express ont | way 0.00056 + USO Wwmposto upton 274 rubs. a 2 Trapoot mn ustpaA, ae ne - ole t Gn ol (xX) t votunn x/ Ke 4 +1)" ne. 205 (po* x?” 2) ek composite — sinpss — vols (Mtegrdamol, vb, n)! hcl b-o/n REP. baspace Cab, nat) Teacher's Signature......ssssssessesseeseeeee Experiment Name: = int eqrand Os) aa rant HP SE np Sum (HEIs 2) +2 P+ Sum ( yyer- 7 Vay ED) ref geseUt— a= oO ba MP Pi niatermals e Tatbegral value Sompotite. simpsons. rule Cintes rap das n— ntervalr) Print S towpated Entesrod yelust" tateg reef _ value) SB Civan aset of (X19) olota in He form A a oli mary tye 51 2298, BEAD UFOS) OF LHS , thet y against » sit sta hatiol ar‘ Time’ and ye ~Anbol or Temperature” B LE eS) 21947 BBO) 13 Me Sy S424, 55 as Us Pat (a Keys O) cyst (4. values 2) pk. plo€ cu) pln habed C' rime’) ple. ylobel C Temperatiss’ J elk, dle C Temperedures vs Crme') phk. shrw) VF creak a ont dimensional Numpy ama with 2 ranclern Leaumboye befwoem [-41] feshepe fois nto a CWS) 2p array Treat ps are 4s matin, Transpose the Matrix and tak roduck bodweom dix dwo, prirt fra _procluct mafrin, Teacher's Signature,.......ssssesseeereesees nt hy Experiment Name : Pago No. ee I> yapowe Mumpy ovr ne rN Ene. random, anifom (1, 1,267 aern. re Shape Cu S) aint, transpose ca) P= e, dot (aot) prove CAhedhuck Matin” J print @ fee s \ 4 ie tompake Hain € =AR-BA Ohure A= tt ep OTs 4 2 Tempore numpy or WP A= nO arecay (CLI 2, £4 561,09 & DD Bo np oad (TL9, % AY LD TIUDY) . cane. dst Or) —P- dst (8-4) print Mea") pxrivt(e . \F vraba tno Zp rvandlom osutays A lengt each Hh rough onunyy Print trae ovrayc, lompars dro two areas and check zt fhey ane Same. > import numpy ar np- a= np. ee wand Cs) a2 = ne, random ,vancl Lo) print (41) Print (ar) a=nP, array. equal G1,4 2) Print (arrays. are— samt) Teacher's Signature. nthe Experiment Name : - Pago No... Daten Be plat goa%eine, Dhore me vanges doom 6 bo 4h pidho spacing otf « Use_pleting 4usebicy fiom malpletib paetnge . q a) Pmpert nun ar wp impart matpletdib . pyplot oo ple det (x): ref a** 9% NP, Sin CX) XEN avenge (o, 6*np. Pi, OD yotonc ty) elt, plot ,¥, abel =*h9=x"*| Sia (x) #) tht, show (_) Gomerate joo wanda tolegers betwen | 4 100 berm an | appropriate dunckm in and medula tn Nis rage ys Now trek Ha First yo valuas x- date and fre leat fo values 0 y- data. | phot x= trowel amalplatlib a seattersd points Bitt. £4 mbol D Import numpy 0 vP- impor Lothib . Let ove rnznperandam. randimt (4 It, 100) % zrn fi lo] yernf_10!] pit. scatter (xy, marker ‘0’, dabel 2‘ Scattered points’) |_ pl, xlabel (‘x’) elt. Ydekel C' yi) ple, chew () Teacher's Signature, Experiment Name : |& Given mempy queay [Lures], 60D MT) treat He Hest |_clement a xdafa ond Ihe second element or yelala, plot y's * | dhreugh malplotlsb. label He ages 0 '% pale andl Y-Dola’ ond PSmpet_mumpy_oo op import motplotlib, pupl Ld Hg, avray (Lin 23.07 S172 2194 T)) x=d[ yed[) | plk + plst (x, mp squaraty) plt. dle C' Experimental plot ') pli» xlabol ( Pats.” ) plte ylabol ('Y Bata’) |__pltr chow () DF a tandem variate % generale om array ef 0 tandem values befwoen o and (. Find the thuctamn fers — import Mumpy ar np wane, avray ([2,1,37) f= 3S 4h =P» radians (th) RE nprasray (TLAe- 0s 6), np. sin AH), OT, Lng sin (th), mp. os (4h) 0) Ten oT) nyv= npidot (Rit) print ©) Print (av) Teacher's Signature...

You might also like