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

Dashrath Nandan NMOUP (Unit-1) Notes

All my details

Uploaded by

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

Dashrath Nandan NMOUP (Unit-1) Notes

All my details

Uploaded by

Romi Kour
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

classmAte

UNIT-1 Jashgath,
Nomdam
Date
Page
NMOUP

Rthon Ahan is an intexþseteds bject- 0xiùnded s


high -leuel tsgamming Longuage ssed in
MONiBUs alemaind,neludingumihical Lomputatin
and sitndijie comjuding
Featywnea
Readablby
and eate
brtehaibibsty ohem objcot Prouide
Wth libyios. Sowce Otemted GrUI Sabport
PRaintenanCe

DaBa, Types

Numexic DicHonary Boolean Set Seguemce Tyie


Lntegex Comblex Float Tupie.
Numbe

Comments indentafion:
X=5 Print("Dashrath")
y=3"14 else :
name "Dashyath #sting þint ( Nondan")
is true = True
True # boolean
Conrol Shrucures :
Sequenttal Condhonal keeating
For each item
Block1 KCondiHon
Block2l Fatse Block al instn
Bodk 3 Block Block2
classMate
Date
Page

Python Chezatos axe isd to boxfasm Gheralioni On Vauiables


and values
Arthnetic Ohexakoy: t , - , *, , %,*(Batonentol ):
AMTnment Cherator : = t= -=, l= l=) *= ete
Compasisom
logical 1)
nd 04, not.
+Btuise
Conditienal StuctUHeS and Loops :
if Conditisn: in Yange (5): for tn vange(0):
block Code1 þrint ()
else Count= 0 break
block code 2 Wnile caunt (3: if f%2 = =0
Pint ("Counting", Count) ContinUe
Count +=1 Pint () :

*inea alacbya, is a branch ot mathernatics hat deals


Mith itean eguatiens and thei tapresentatien sing
Vectos and matices

Vectousi a mathematial Quantty thauts haue both


maritide &
dection
a tectangular aOay in eus and colunns.
SciR iaJLsed to sk uith inear algebya in bython
dL als less tkimigatin , integnaton , inYnjolakon and
ignal paeceshing snjabiltid:
Nuahy, aHhe most ued lbravy r sting uth
mabrices and ectos
clAsSMate
Date
Page

Yector = np-ooy (cis 2,34,5]) Vector Cl,2,3,4, 5]


þrint "Vector:"vector)
matix = np. anay(E, 2,3), E4.5,6], Ci,8.9)
þnt ("Mahix , mahix) Output
Maix: C2,31
C4,5,6]
matix-tramsbae= mahix.T

Pethon tunctiens i a block statemeri that tchusns


hesbicilic task- Lncreases Code Readabiltty and
Ruaablit
1.
Dalining
yrtx: def functn name (Aramekas):
#func bodly det add (a, b):
Bxi-
Hehen Value Hern a+b

Callin funchtons Syntan : fune- name(arqumenis)


Qai Yeault = add(5, 3)

DPastienat Avgument : Ags pased in bome nder au boomatu:


E de qreet (rame, mesage):
'retwn f"fmenage fname? !"
potrnt (greet('DN'; Hello'))
Qutput : Hello DN!
classmate
Date
Page

eet( mCsage =' ' , name='Dashralh')


i) Dekault Aq: oameBas Lutth deault alus
y: def qeet(name, mesage ='Hella '):
Yem "f mounge3,fname?1"
greet ('ow')
iv) Vaiable- Lenath Arg: 'avg': Non-keyuuoyd yaxiable--knath Na:
retn Sum(args)
Sum_al (ly2,3,4)

X* kwangs : Keyuord
keguuod vaxiable Jergth angunents
for Key, value in kwargd" Item()8
bint(f "fkey ?:fvalue}")
þint.inko (name: Dashath' saqe= 21, job= 'Eny')
Nale: KOg byntan allsuss tha tundin to acopt any
Las a aple
X* Kungs syntar allus Hhefnatien to acapt any
asa detienany?
Yariable in bylhon -
) Gulobal Vaaiabla: defined outsete a functien bsdy
classnate
Date
Page

: total= 0
dek Sum (angl,angz) :
total = gl+ arg2
þrint(" Tnstde thefumct? local fotal:, total)
7etm total
Sum(l0j20)
print'uside the tun" gobal total, tota)
Qutput ? Insde the Functon Local total : 30
Outaide the kunotion glebal total :0
t Data Shuctues: sts, Tuples DeHknaies , Seti .
List Tuble Set Dictio naxy
+Lit i a nen- ble. ia 0non -Tet u aT91- Non- henqRLJ
hemogensw data homogen tus dshemgonaw Ds DS that seres
shucuethat shve haf stres but Btores the Key- Value pais
he elemnt in elembnts in lement in 2

keyz':'ve?
Rebresonded by [] .by )
+ti
Lst is Mutatle. mutable mutable mutable
|List is Ohdered t Ordered Unordered +ded

’Acesstng Llemi my tupde Col y didC'keyr']

(I,2,3,4, 5) $I'a", 2: "'b"?


E:23.4,5) 2,34,53
llew dubliateALo Denst allgo o nst allos.
element uslicate
Cemord
classmste
Date
Page

* Numeiical Methade
nbencef Numenical MeHhads in Pytoni
Comle bneblem &oluin ABBticatiens
Abþieximation Gf aalutins
Gmbtutakeral elHeciency. Rost findonq:
BOBtimizatien Dnd minizmiplion -lnean alebia Oheatons
Ordinay i- yuatien(ove)
and Pantas BE(PDE)
baies for numenical computing
1. Numy:dt i the fundamantal backage tos mumenical
nmpltinq in Python
Key featuel :
a) Milkdiminsional amys: fectent Ds far hapresatigVecos, matitd,
b) Mathematital Aunctins : klide rarge q math sjenations -
Broodcasling :Powengul mechanisa for porforming feraltons
fdferart shapei
2Seily: dtin build Gn Nonfy Ond þoEuides additonal
unctieralty tor sinty' omjetig
key feakres ?
htepraton, interbolaten sand cphimigakfon tools
4Speíal tenctiens i
4Sional and image fssCRJ`ng
fieaMing unctins
classHAte
Date
Page

bip install Tumby 3APy


fom scy»Chrmige irort Mirine
men Value = nh mean (an) Yeum x*2+4fx +4
brint(mtan- Value) reult= münimiye (obj-fun, X0=0)

Rost-Finding Methods:
D Bisection Method
1) Neustoh- Raphsen mehed
) Secant meted

1o Bisection Method i
selitien
is aHDet fending alguthm Uaed to finda Value
to the egn. f=0*dt u based en dntermudiate
continusus tums. f
heoem, thich statu that to any
hbaite
lGuh am inerval 9, 6] uhene fa) andf6) hawe intenal
Aigni, thexe enist 0t least Ône Stoot in that
Stops &f the Btsectien Mehod
D Thitial tntenwal Selection: Chocse tuo points a and b,such
that fa).{(b) <o Tinterva
r Midpsint Calulatiini Calculate (= 2 t0.aybi
1i Functien Lvaluation : Compute fl
classmate
Date
Page

) Sion Check:
$ {C)= 0, them C sthe root.
" f(a)-fcc) <0 , the Hoot lies in a, C1 , set b=C"

VTtenaton: Kebeat the bhocon ntil Hhe Lntewal [o,b)


Suticiently mall(ie- Jb-o)<þredekmineed tblenana
Ques nd oets e the tntion f)= 4 in înteval ['13
sel- La, b] = I,3] f)=x24
{a= -3
f(3)=5 .. at lest one r0ot iu

Step 2: C= Qtb C= lt3 =2.


2

Step3: f2) = 44 =0
f)=0 ' s i s the 908Bt.

Qucs Find the root o4 the fnctibn fa)= - 2 to


the intewal i,2
Seli fc)= z3--2
f(1)= I--2 =-2 . f)-fle)<o
f(2)= 8-2-2 =4

Note: YT: |Boecton Method Dr: Gaiemdsa Perehit


Cuestt
cAssMate
sign check step.
then use the
Date
Page

Tlorettons)

1 1 2 (H22)= 1-5 (15-15-2


= -0125<0
f(O <o pdate Q=CCb] i be meo insval
1"5 1.15 1-609 >0
"flc) 0, ucake b=d a, c] il be nous rndewa
3 j.5 115 J·625 O·66>0
1-56 2. O"250>o
4 1-5 1"625
|-5 |·562 |531 O"657 >0
6 |"5 |531 1-515 -0036 <o
1·515 1·531 1"523 1-857 >0
1"515 1-523 1"519 -0"14<0
1519 |523 1-521 - O"02<0
1521 l"523 1-522 O"0036>O
1521 1"522 1·5215 O"o007>0
1521 1:5215 1·521)

f. Roct i 1-521,sünce th stantod heheatinq


0r [1-521,15215nteral
i duitienty Smal
Ques frd the Hoot of am eguatien , f)- e3- x-J
uin biectien method PPA-13-3
LMS
fo)= r3-X-)

fo)-1 the inteval is [1,2


classmate
Date
Page

n b C=(at5) fC) ppdate


1 1 0-875 0 h=C
1 1·5 1-25-0-296<o
3 1-25 1-5 1-345 022 4 0
-0-05| <0 a= C
4 1-25 1-345 1-312S
5 1-3125 315 1-3437 O 082 >0 b=C
1-3125 1"3437 1·3281 0"014 20 b=c
1"3125 1"3281 1-3203 -O-Ol8<0
1"3203 1"3281 |·3242 - 0 002 <0 a=C

1"3242 J.3281 1-3261 O-006 70 b=c


13261 1·3262 O- 002 >0 bec
101" 3242
J11:324 2 1-3252 13247
121.3244 J+3252 3249

Since, C stat sepating


r004 1.324.ns
Pseudocoale
funckionf blackon (f0,b, to) end tilo
errorf(a) and 4(6) must have off-Sqn
emd if Hekn(a+b)/2
akile (b-a)/2 >tol |end tanctbn.
C= (atb)2
etusmC

b=c
cdassHAte
Date
Page.

Advantages
DSimplity DMadhantgs
n)
Gusanteid
in)Robustness cnvegence ) Snitial dnteial Reguisemerd

2Neuton- Raphson Method


4 brovides om iteratiue
a eal- sualud tunctionbrocecdlune to
ajaenimate the O
d i
baud on the tdea ot
Daing, the tangent line to the tuntien at a guseol iund
o ihd a teten
abþAexinatien st the 6Gst

Eq
ngeneeslipecialy
a tang- at P(,foa)
shenlee to the 4oot.

y-4()=fa.)lx) y-9,- 1(-)


0-4)=f()x
f'(x)

Fomule :
f'(n)
ne1: Next aspöoximatiln
clAssMAte
Date
Page

*Steba ef the Newton-Rabhacn Method


1o dnihial Gues : Choae an initial aybseimatin Zo fo the aoot.
Qteratton: Apbl the iterafon fomula to Lombuke mesct
Obþeximatien
|Lonveigence Check: Rebeat the ilesatin entil the dih betucon
buccesiue Oybreximaton i smaller than
a bredetmind tolexamce euel
ftMS Word
Exi fndin the Yoots of fr)= x5-x-2 L134

f(c)= -2 fc)= 3x2-1


f(o) = -2
f)=-2
f(2) =4
Oppaait sign , meams there iis at least one.
toet blw l and 2.

’Initial quens : t,== 1-5


’ TBeratfon formula : Cn= Xn- Xn-n-2
3n-1

|Puttn =0; Lo= /-5


X,= 15- 15$-/s -2 = |:5- -012s. 15211
3X/-52-1 5-75
n=l
= 5214
2C,= |:521] - f-5213) 1:5214
n=2, f'(521)
X2= 1.5214
X3= l 5214 - f(-s214) l:5214
f5214)
he roet 5214- , as it Stort sepealenp.
clAssMute
Date
Page

YTNeuon- Rabh20n()-Gajondha urohil


ex: find by Neuton Raphon mekhod , a voot of z°-32-5)
foc)= 3-3x-5 f'c) 3x-3
flo) = s do 200han (16)

f(3)= 16 e

’TteratHg fomula 2 Xn+1= n- n-3Xn-5


3n-3
’Iteaions:
Lo=2
(0-0 X= 2- (23-32-s)
(3x4-3)
= 2-(3) = 2+2 2.333
X 2-333
(n=1) 2= 2-333-52333).2805
f'(2333)
2e2=2-280S
(n=2) = 2 280s - 2:28goS) 22790
f(228OS)

"X= 2-2790
(n-3) X,= 2-2190-2-2790) 2:2190
422190)

Reat 22790
classmate
Date
Page

Pseudocode: nemtonfaphson(f,df, Xo, tols mau ter)


fumcton
XXO
for I= J to maxIter Advamtagei
X_mew = X- f)/df(x) Rabtd Corwegenel.
Simbltity
i! abs (x-neus-X) <tol 6

end if
4ew X-new
Alide ablt
X= Xnew
end tor Disodvantaae:
Dentalive Reguiremert
Convege"
evYor"Method did not onveage" Snital gues enstiuit
emd funclfon

3Secont Method
44isan itoratine umerical tchnigue Aed to fnd
Hhe oet ot men-linean e9uatien
+.his mehed iu uselel ihen the deruatie bf he
unctin i dijieult do compute.
Baaie brinci7le i-Jhiu mchecl assrerimatu the tost
afe functin f) by sing tus initial abEämatien
adX he mehod ileratiuely refines thase
Labbrorimatien byconstuctng sicant lnss betuen
these paint k stng the X- ntrcepta af these liineas
psonimaltbn.
txn) (Xy-Xy-),: Cwment
apanimatin.
maxZker)
classMate enuegne
DatePage
Xn-) ytol
inihial tan)n- til sX1,
tuuo fomula 3
0o
[f,
uthLoamd
L. and maxIter tol
abs(x,-4,)<
secantNethodif
-
Aply Xn 2
stebt
Stont Ln1=
procast to
:gussZS Repeat PEeudocdes ifend functin
j=1 De,=
X2
tenatiue function end
tor
Stabs:I-nibal iRepeat fox
end
4.
m4) (n=3) (n=) Xg
X4= D= |Aecant nEx:
g= 1
f)=-3 flo) = the
XG=0:20]- X2=0"25 0"25-
0-186- A
0:286, Lj
-= intewal real
)X2=0-2.5 method
,
t0-25)(O-25
flo25)-f)
(o- X3= t)2,-)=
1--) H9st
tort86)
t(ov201) tori864
t(0-25) -f0)t4) (0,)
00 s 6(0:201) X4= 186) 0-186 e
0:20) (O-186-O-25 yTSecant .the
0-201 Perlorm
-
1) eguáibn
- toun
-186) O 0"18644 Mehod
~ -3)-u) ileratfonA,
23-5Xt|
O201. (Q1)
20-20081 (1-0)aO-25 Page Date
classmate
of 0=
helics

You might also like