Final Submission of Fundamental of Mathematics & Statictis
Final Submission of Fundamental of Mathematics & Statictis
CERTIFICATE
This is to certify that Mr/Ms Esai Seshan S Thanga Perumal of FYBSc [Computer Science],
Semester I , Seat No FCS2425025 has successfully completed the practicals and submitted
it online in Microsoft Teams for the subject of FMS (Fundamental Mathematics and
Statistics) as a partial fulfilment of the degree BSc(CS) during the academic year 2024-
2025.
________________ _______________
Faculty-in-charge Internal Examiner
Rajesh Yadav Rajesh Yadav
1 Practical 1 2
Basics of R
2 Practical 2 10
Measure of central
tendency
3 Practical 3 18
Measure of dispersion
4 Practical 4 26
Moments: Raw & Central
Moments
5
Practical 5 28
Skewness & Kurtosis
6 Practical 6 31
Correlation and
Regression
7 Practical 7 34
Combination and
Permutation
8 Practical 8 35
Tower of Hanoi
1
________________________________________________________
Practical 1
________________________________________________________________
1] DATA INPUT
- Arithmetic Operators
Explanation :
a = 23; b = 92
v=a+b
The variable v stores the result of adding a and b. This is simple addition:
v=23+92=115
w=a-b
x=a*b
y=a/b
2
The variable y stores the result of dividing a by b. This is division:
y=23/92=0.25.
z=a^b
The variable z stores the result of raising a to the power of b. This is exponentiation:
z=2392≈1.900907×10125
v; w; x; y; z
Finally, the values of v, w, x, y, and z are printed to the console, showing the results of
each operation in the following order:
v = 115
w = -69
x = 2116
y = 0.25
z = 1.900907e+125
- Mathematical Functions
Explanation:
log(25)
sqrt(625)
exp(50)
3
This computes the exponential function, which is e raised to the power of 50:
e50=5.184706×1021e^{50}
round(3.184628425)
-Trigonometric Functions
Explanation :
sin(0)
cos(270)
- Combinatiorial Function
Explanation ;
Choose(8,2) computes the number of ways to choose 5 items from 10 without regards bto
order , which is 28
2] Vector Operation
4
Explanation :
j <- c(25, 3, 61, 4, 52, 63): This creates a vector j with the values 25, 3, 61, 4,
52, 63. The c() function is used to combine these elements into a vector.
rank(j): This calculates the ranks of the elements in the original vector j. The rank is based on the
element's position in the sorted vector, where the smallest value is ranked 1
log(j): This calculates the natural logarithm (log base e) of each element in the vector j
Explanation :
N = scan() allows the user to input values directly from the console. The user has input 14
values, and they are read into the variable N
After the scan() function reads the inputs, the output shows the list stored in N as:After the
scan() function reads the inputs, the output shows the list stored in N as: 3 4 2 1 3 4 5 2 1 6 7
94
Explanation :
5
A data frame named data_frame is created using the data.frame() function
The data frame includes three columns:training: A vector of character strings representing
different types of training ("strength", "stamina", and "other").pulse: A numeric vector
indicating the pulse rate associated with each training type (10, 15, and 20).duration: A
numeric vector indicating the duration (in minutes) for each type of training (60, 30, and 45).
The command data_frame prints out the created data frame, which consists of the following
rows and columns
Explanation :
s <- c(3, 4, 2, 1, 3, 4, 5, 2, 1, 6, 7, 4, 9, 9, 4):
This line uses the table() function to count the frequency of each unique value in s and stores
it in u.u:
When u is called, it prints the frequency table of s. In this case, the numbers 1, 2, 3, 4, 5, 6, 7,
and 9 appear in the vector, with their respective counts shown.transform(u):
This line transforms the table into a data frame with two columns:s: The unique values in the
vector.Freq: The frequency of each value
6
Explanation :
abs(j) returns the absolute values.
rank(j) assigns ranks to the elements based on their magnitude , handling ties by assigning
ranks
7
prod(y) computes the product of elements.
Explanation :
byrow ="false" creates a matrix filled by columns.
8
A[1,1] Accesses the element in the 1st row and 1st column of the new matrix A, which is 2
x <- c(1, 3, 5, 9, 10) creates a vector x with the elements 1, 3, 5, 9, and 10.
The function c() is used to combine or concatenate these values into a vector.
9
__________________________________________________
Practical 2
__________________________________________________
- Mean = Mean is the average of the given numbers and is
calculated by dividing the sum of given numbers by the total
number of numbers
Family A B C D E F G H I J
Income 850 700 100 750 5000 80 420 2500 400 360
Explanation :
1. x <- c(850, 700, 100, 750, 5000, 80, 420, 2500, 400, 360) creates a vector x containing the values:
850, 700, 100, 750, 5000, 80, 420, 2500, 400, and 360.
2. When you run mean(x), R calculates the mean (average) of the values in the vector x.
10
Explanation :
1.y <-c(9,8,6,4,7,5,3,7) creates a vector y containing the values: 9,8,6,4,7,5,3 and 7.
2. When you run mean(y), R calculates the mean(average) of the values in the vector y. Thus,
the mean (average) of the values in y is 6.125
Explanation :
1.x <- c(9, 8, 6, 4, 7, 5, 3, 7) creates a vector x containing the values: 9, 8, 6, 4, 7, 5, 3,
and 7.
2.When you run mean(x),R calculates the mean (average) of the values in the vector
x .Thus, the mean (average) of the values in x is 6.125.
Find the arithmetic mean for the given number using scan
function to create a vector for the following values
16,19,27,10,5,7,12,15,NA
11
Explanation :
X = scan()prompts you to input a series of numbers.
In this case, you entered the values 16,19,27,10,5,7,12,15 and NA . After pressing enter on
the blank line, R stops reading inputs. When you run a ,it displays the vector x containing the
values: 16,19,27,10,5,7,12,15 and NA. Running mean(b,na.rm=T) calculates the mean
(average) of the values in the vector x Thus, the mean (average) of the values in b is 7.575.
Formula :
Explanation :
1. x <- c(1100, 1150, 1080, 1120, 1200, 1160, 1400) creates a vector x with the values: 1100,
1150, 1080, 1120, 1200, 1160, and 1400.
2. y =sort(x) sorts the vector b in ascending order, resulting in the vector a: 1080, 1100,
1120, 1150, 1160, 1200, 1400.
3. When you run median (y), R calculates the median of the sorted vector y
12
Find the median of number 3,4,4,6,8,8,5,8,10.
Formula :
Explanation :
1. x <- c(3, 4, 4, 6, 8, 8, 5, 8, 10)creates a vector x with the values: 3, 4, 4, 6, 8, 8, 5, 8, and
10.
Find the median for the given number with missing value
7,9,11,12,15,18,55
Formula :
Explanation :
1. x <- c(7, 9, 11, 12, 15, 5, 5, 18, NA)creates a vector x containing the values
7,9,11,12,15,18,55 (which represents a missing value).
2. y = sort(x)sorts the vector x, excluding the NA value, resulting in the sorted vector y:
7,9,11,12,15,18,55
13
3. Running median(y), na.rm = TRUE)calculates the median of the sorted vector y, removing
the NA with na.rm = TRUE
Explanation :
1. a <- c(2, 7, 10, 15, 10, 7, 8, 10, 2)creates a vector x containing the values: 2, 7, 10, 15,
10, 7, 8, 10, and 2.
2. b = table(x)creates a frequency table of the elements in a. This table shows how many
times each value appears in a. The output of table(a) would look like this: names by b)[b
== max(b)]extracts the names (i.e., values) from the frequency table b where the
frequency is equal to the maximum frequency (i.e., the most frequent value).
max(b)returns the highest frequency in the table (which is 3, for the value 10).
b == max(y)creates a logical condition to find which values have the highest frequency.
Explanation :
1. a <- c(10.5, 6.5, 2.3, 6.5, 8.9, 4, 4)creates a vector a with the values: 10.5, 6.5, 2.3, 6.5, 8.9, 4,
and 4.
14
2. b = table(b)creates a frequency table for the values in a. This table shows how many times
each value appears in a. The output of table(a) would look like this:
3. names(b)[b == max(b)]extracts the names(i.e., values) from the frequency table b where the
frequency is equal to the maximum frequency (i.e., the most frequent values)
Explanation :
1. a <- c(20, 30, 31, 25, 30, 31, 30, 32, NA)creates a vector a with the values: 20, 30, 31,
25, 30, 31, 30, 32, and NA (which represents a missing value).
2. b = table(a)creates frequency table for the values in a, excluding the NA value. The
table would count how many times each value appears in a.
15
Explanation :
1. p <- c(4, 7, 1, 3, 5, 8, 23)creates a vector p with the values: 4, 7, 1, 3, 5, 8, and 23
. 2. Q1 = quartile(x, 0.25)calculates the first quartile (Q1), which is the value below which
25% of the data falls. The result is 3.5. This means 25%of the data values are less than or
equal to 3.5.
3. Q2 = quartile(x, 0.50)calculates the second quartile (Q2), which is the median. The result
is 5. This means 50% of the data values are less than or equal to 5.
4. Q3 = quartile(x, 0.75)calculates the third quartile (Q3), which is the value below which
75% of the data falls. The result is 7.5. This means 75%of the data values are less than or
equal to 7.5
Explanation :
16
1. p <- c(4,6,5,9,8,10,3)creates a vector p with the values4,6,5,9,8,10 and 3
. 2. Q1 = quartile(x, 0.25)calculates the first quartile (Q1), which is the value below which
25% of the data falls. The result is 3.5. This means 25%of the data values are less than or
equal to 10.
3. Q2 = quartile(x, 0.50)calculates the second quartile (Q2), which is the median. The result
is 5. This means 50% of the data values are less than or equal to 12.
4. Q3 = quartile(x, 0.75)calculates the third quartile (Q3), which is the value below which
75% of the data falls. The result is 16.5. This means 75%of the data values are less than or
equal to 16.5
17
_____________________________________________
Practical 3 :- Measure of dispersion
_____________________________________________
{The range in statistics for a given data set is the difference
between the highest and lowest values. The coefficient of range is
a normalized measure that shows the relative spread of the data.
It is calculated by dividing the difference between the maximum
and minimum values by their sum}
1] Create a vector with the following values 8,9,8,10,11 . Find the
range and coefficient of range
Formula:-
Range=Maximum Value−Minimum Value
Coefficient of Range=Maximum Value + Minimum
Value/Maximum Value−Minimum Value
Explanation :
a <-c(8, 9, 8, 10, 11) creates a vector a with the values: 8, 9, 8, 10,
and 11
18
l = max(a) calculates the maximum value in a, which is 11.
s = min(a) calculates the minimum value in a, which is 8.
r = l-s calculates the range, which is 11- 8 = 3.
cora = (l- s) / (l + s) calculates the coefficient of range: 0.1578947
Formula:-
Range=Maximum Value−Minimum Value
Coefficient of Range=Maximum Value + Minimum
Value/Maximum Value−Minimum Value
Explanation :
a <-c(26,113,120,95,60,42,21,14,5,4) creates a vector a with the
values: 26,113,120,95,60,42,21,14,5 and 4
19
l = max(a) calculates the maximum value in a, which is 120.
s = min(a) calculates the minimum value in a, which is 4.
r = l-s calculates the range, which is 120-4 = 116.
cora = (l- s) / (l + s) calculates the coefficient of range : 0.9354839
Formula:-
Range=Maximum Value−Minimum Value
Coefficient of Range=Maximum Value + Minimum
Value/Maximum Value−Minimum Value
Explanation :
20
a <-c(59.5,62.5,66.5,68.5,74.5) creates a vector a with the values:
59.5,62.5,66.5,68.5 and 74.5
l = max(a) calculates the maximum value in a, which is 74.5.
s = min(a) calculates the minimum value in a, which is 59.5.
r = l-s calculates the range, which is 74.5-59.5=15.
cora = (l- s) / (l + s) calculates the coefficient of range : 0.1119403
{Quamtiles are values that divide a dataset into four equal parts.
They help to describe the spread and distribution of data by
providing insight into the data’s central tendency and variability.
The quantile deviation, also known as the semi-interquartile
range, measures the dispersion of the middle 50% of the data. It
tells us how spread out the data is around the median .The
coefficient of quartile deviation is a relative measure of
dispersion, indicating the spread of the middle 50% of data
relative to the size of the quartiles}
21
Explanation:-
First Quartile (Q1): 1331 (25% of the data falls below this value).
Third Quartile (Q3): 1752.5 (75% of the data falls below this
value).
Quartile Deviation (QD): 210.75, indicating the spread of the
middle 50%ofthedata.
Coefficient of Quartile Deviation (coQD): 0.1367, reflecting that
the middle 50%ofthedatais spread out by approximately 13.67%
of the sum of Q1 and Q3
X 5 15 20 50 70 82
F 8 12 20 10 7 3
Formula :-
Q1=[(n+1) /4] −th value Q3=3[(n+1) /4]−th value
Quartile Deviation=(Q3−Q1)/2
22
Coefficient of Quartile Deviation=(Q3+Q1)/(Q3−Q1)
Explanation :
First Quartile (Q1): 7.25. This means 25% of the data falls below
7.25
Third Quartile (Q3): 11.5. This means 75% of the data falls below
11.5.
Quartile Deviation (QD): 2.125. This measures the spread of the
middle 50%ofthedata.
It’s calculated as Q3−Q12\frac{Q3 Q1}{2}2Q3−Q1 .
Coefficient of Quartile Deviation (coQD): 0.2267. This relative
measure of dispersion indicates that the spread of the middle
50%of the data is approximately 22.67% of the sum of Q1 and Q3.
23
{The standard deviation is the square root of the variance, which
is the average of the squared differences between each data point
and the mean.
Variance provides a measure of the variability or spread in a
dataset, with higher variance indicating more dispersion and
lower variance indicating less dispersion.
The coefficient of variation is the ratio of the standard deviation
to the mean, multiplied by 100 to express it as a percentage. It
provides a relative measure of variability compared to the mean
of the dataset}
Formula :
σ=1/N [ i=1∑N (xi −μ)2]
σ2=N1 i=1∑N (xi −μ)2
Coefficient of Variation (CV)=μ/σ ×100%
24
Explanation :
Dataset: x = {14, 23, 27, 21, 15}
Standard Deviation: Measures the spread of data points around
the mean
Variance: The square of the standard deviation, indicating the
spread of data.
Mean :The average value of the dataset.
Coefficient of Variation (CV): The standard deviation expressed
as a percentage of the mean, showing relative dispersion
25
________________________________________________________
Practical – 4
________________________________________________________
MOMENTS:
Raw Moments: The Moments about zero distribution are known as Raw Moments
Formula:
Central moments: The Moments about the mean of distribution are known as Central
Moments
Moments:
The raw moments and central moments can be calculated using all. moments() function from
moments package.
The syntax to compute raw and central moments of a data set using R is
all.moments(x,order.max=2,central=FALSE) where , • x: a numeric vector of data
26
• central: a logical value (FALSE for raw moments or TRUE for central moments. 1. Create a vector
which represents student marks 98 87 96 91 85 89 93 96 99 86 Find the raw moments and Central
moments.
27
________________________________________________________
Practical – 5
________________________________________________________
SKEWNESS AND KURTOSIS SKEWNESS:
Skewness gives us an idea about the concentration of higher or lower data values around the
central value of the data. Karl Pearson's defined the coefficient of skewness based on moments
as
Where
KURTOSIS:
The literal meaning of kurtosis is peakedness or flatness of the data. The kurtosis measures
how peaked or how flat the histogram is relative to the bell-shaped histogram. The bell-shaped
histogram is based on normal (Gaussian) distribution.
. • If the histogram has too many observations in the tails compared to normal histogram, then
the kurtosis is larger than 3.
28
• If the histogram has short tails and most of the observations are tightly clustered around the
mean, then the kurtosis is less than 3. The moment coefficient of kurtosis (also known as β2
Pearson's moment coefficient of kurtosis) is denoted by and is defined as
Where
x is sample mean
Moments Package:
The R Studio "moments" package can be thought of as a collection of tools that make it easier for
us to comprehend our data. It is similar to having a math assistant that performs all of these
necessary calculations for us, making it simpler to describe and evaluate our data.
29
30
__________________________________________________________________________________
Practical – 6
__________________________________________________________________________________
AIM:
A. Karl Pearson’s correlation coefficient
---------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------
31
--------------------------------------------------------------------------------------------------------------------------
32
REGRESSION
AIM:
A. Coefficient of Regression
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
33
__________________________________________________________________________________
Practical – 7
__________________________________________________________________________________
34
___________________________________________________________________________
Practical – 8
___________________________________________________________________________
TOWER OF HANOI
toh=function(n,s,d)
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
35
--------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
36