Functions
i8olakol
isolatcol unit of Code
unit Code
a 8mall
lion is
AA Hune
unclion
pecdoco
C olefinle
toook. e
tCcun
name
name Cnd Call ths e
an paat of he
pe0qramme, Cwe
can
und
will exe cule thal- Cade
Le th
lo a
name un Compuka
O
the defined job. when coe ase ccll
Ccl aa anckon,
luncitn
upctO haue dlaule lo be Pas o paope
CoOaking sR dala vaaiable elcae Coilleol Anstumh
A func tHon Co have han Oe AcrquneN
Punclioo Ca be dedine Cuying Combina ton ot
de and elua Stauem ent T de s &ollowet
by Sosm oftcun clron and a Colon. Tue indente
olock ot Code Careates adeunelioo. T aekan
8tate rment de ciclas cohat Val s pa ec ko
bao ur cow unetio0 Colleal
uncloDs divioluo ot
Bull-1o funeon. Sunekon od braa
use delioed
unclions
.Bault iD funclion
Majort ciduantage lanqucge is Owou ably
o Ptho
Uaaiouy libcnis fos VCLsiOugS ke
aPpcaO%
SCientilic Coopulalon, raphits etc. u slandcad bgay
iqay
s duidd
ino many moclules te ime, andom
picxle ek. man butin
Cacb oodule ConsisOF bne od moeandtonr.
math Anmpoat Heare Sn) is CalCcelat
o Sin.
frro math occlcilebaaoy
Peciot Sincx)
drom mert) impos Cwe Ca m pos
paupt Sinca) , Cosc)skant entae mathe mat fal
opoc mctb as
Pc m. incx bsa name fs
Pom m Coscx
Hus coco
o e s Sencton
mo numpyioporst
+ooro puleub impoat
functions
List of important mathematical
(From math library)
integer value greater than or equal
Function returns the smallest
ceil(x)
to x. Input x must be float
x=12.8
y-12.3
ceil(x)=13
ceil(y=13
equal to x.
floor() Function returns the smallest integer value less than or
Input x must be float.
x=12.8
y-12.3
floor(x)=12
floor(y)=12
Function returns the absolute value ofx as a float. Input x may be
fabs(x)
integer or float.
factorial(x): Function returns factorial of x as an integer. X must be a positive
integer.
fmodx,y): Function returns the reminder in x/y as a float. Inputs may be
integer or float. It is almost identical to x%y. But there may be a
37
Computational Physics
the developing teg
in According to
slight difference accuracy.
Python fmod() is more accurate
working with
when floats, w
floats,
integers.
Xoy 1s more accurate when working with
de
x=10
y-9
Co
fmod(x.y)=1.0
fsum(x): Function returns an accurate floating point sum of values in the lis
named x
x{1,2,.3,4
fsum(x)=1.0
the integer part of the float
x after truncation.
truncx): Function returns
x=12.473
trunc(x)=12
exp(x): Function returns e**x.
With one argument, fünction returns the natural logarnthm ofxh
logor, b):
base e. With two arguments, return the logarithm of x to the given
base b
Function returns the logarithm ofx base-10. This 1s usually more
log10()
accurate than log(x, 10)
powr, y): Function returns x raised to the power y.
sqrt(c) Function returns the square root ofx as a float.
acos(x) Function returns the arc cosine ofx, if x is in radians.
asin(x): Function returns the arc sine of x, if x is in radians.
atan(x) Function returns the arc tangent of x, if x is in radians.
cos(x) Function returns the cosine of x, if x is in radians.
sin(x) Function returns the sine of x, if x is in radians.
38
Computational Physics
tan() Function returns the tangent of x, ifx is in radians
degrees(r): Function converts angle x from radians to degrees.
radians(x) Function converts angle x from degrees to radians.
cosh(t): Function returns the hyperbolic cosine of x, if x is in radians
sinh(x): Function returns the hyperbolic Sine ofx, if x is in radians
tanh(x) Function returns the hyperbolic tangent of x, if x is in radians