You are on page 1of 3

Practical 1

Functions in Mathematica
1. Testing Symbols
a) “==” is used to test if one quantity is equal to another
In[5]:= Sqrt[50 653] ⩵ (50 653) ^ (1 / 2)
Out[5]= True

b) “b” is used to test if one is less than or equal to another


In[6]:= Sqrt[ 50 653] ≤ 225
Out[6]= False

In[7]:= Sqrt[ 50 653] ≤ 226


Out[7]= True

2. Numerical Approximation Command : N


In[8]:= N[Pi]
Out[8]= 3.14159

In[9]:= N[Pi, 100]


Out[9]= 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089
98628034825342117068

In[11]:= N[(15) ^ (20), 20]


Out[11]= 3.3252567300796508789 × 1023

3. Degree : Its value is equal to π /180


In[12]:= Sin[90 Degree]
Out[12]= 1
2

In[13]:= Sin[90°]
Out[13]= 1

4. Factoring Integers: The command “FactorInteger[n]”


gives the prime factors of any integer n.
In[15]:= FactorInteger[324]
Out[15]= {{2, 2}, {3, 4}}

In[16]:= FactorInteger[4 832 875]


Out[16]= {{5, 3}, {23, 1}, {41, 2}}

Note: The output tells us that 324=2^2 3^4 and 4832875=5^3 23^1
41^2

5. Factoring and Expanding Polynomials:


Commands are "Factor" and "Expand"
In[17]:= Factor[a ^ 2 - b ^ 2]
Out[17]= (a - b) (a + b)

In[18]:= Expand[(a - b) (a + b)]


Out[18]= a2 - b2

6. To calculate Binomial Coefficient: Command is


“Binomial”
In[19]:= Binomial[7, 2]
Out[19]= 21

7. Prime Number : The function Prime[n] gives the nth


prime number.
In[20]:= Prime[3]
Out[20]= 5
3

In[21]:= Table[Prime[n], {n, 1, 100}]


Out[21]= {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79,
83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163,
167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251,
257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347,
349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433,
439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541}

In[22]:= Table[Prime[n], {n, 5, 20}]


Out[22]= {11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}

8. Modular Function : The function Mod[a,b] evaluates a


mod b.
In[23]:= Mod[21, 6]
Out[23]= 3

In[24]:= Mod[21, 7]
Out[24]= 0

9. Extracting Digits from a Number: To get list of digits the


command is “IntegerDigits”, to form a number the
command is “FromDigits”
In[25]:= IntegerDigits[2010]
Out[25]= {2, 0, 1, 0}

In[26]:= 1 + {2, 0, 1, 0}
Out[26]= {3, 1, 2, 1}

In[27]:= FromDigits[{2, 0, 1, 0}]


Out[27]= 2010

You might also like