Experiment No. 1: Development of Programs in C++ For Demonstration of Various Types of Functions
Experiment No. 1: Development of Programs in C++ For Demonstration of Various Types of Functions
Experiment No. 1: Development of Programs in C++ For Demonstration of Various Types of Functions
1
Development of Programs in C++ for Demonstration of
Various Types of Functions
0
Aim: Development of Programs in C++ for Demonstration of Various Types of
Functions.
Theory: in this exercise, an integer function ‘mul’ is used which receives two integer
values ‘p’, ‘q’ from main function and returns an integer value to main function. An
integer function ‘mul’ performs multiplication operation on those two values which it
receives from main function and returns product of those two values.
1
Experiment No. 2
Development of Programs in C++ for Demonstration of
Array by Bubble Sort Technique & Binary Search
Technique
2
Aim: Development of Programs in C++ for Demonstration of Array by Bubble Sort
Technique & Binary Search Technique
Exercise 1: Write C++ Program to sort an array using Bubble sort technique
Exercise 2: Write C++ Program to search in an array using Binary search technique
RESULT: Demonstration of bubble sort technique and binary sort technique in C++
is explained and executed successfully.
3
Experiment No. 03
Introduction to MATLAB
4
Aim: Introduction to MATLAB
INTRODUCTION
In 2004, MATLAB had around one million users across industry and academia.
MATLAB users come from various backgrounds of engineering, science, and
economics. MATLAB is widely used in academic and research institutions as well as
industrial enterprises.
The command window: is where MATLAB commands are typed. Hit enter to run
the command just typed. It also provides the output calculated by MATLAB
The current directory: shows the working directory. This directory is where Matlab
expects to find working files (m-files, audio, images, etc). If error like ‘file not found’ is
encountered, it means the file is not in current directory. The working Directory can
be changed by typing into it or clicking through the file browser.
The workspace window: displays information about all the variables that are
currently active. In particular, it displays the type (int, double, etc) of variable, as well
as the dimensions of the data structure (such as a 2x2 or 8000x1 matrix).
The command history window: keeps track of the operations that are performed
recently. This is handy for keeping track of what have or haven’t already tried.
SYNTAX
The MATLAB application is built around the MATLAB language, and most use of
MATLAB involves typing MATLAB code into the Command Window (as an
5
interactive mathematical shell), or executing text files containing MATLAB code,
including scripts and/or functions.
VARIABLES
Variables are defined using the assignment operator, =. MATLAB is a weakly typed
programming language because types are implicitly converted. It is an inferred typed
language because variables can be assigned without declaring their type, except if
they are to be treated as symbolic objects, and that their type can change. Values
can come from constants, from computation involving values of other variables, or
from the output of a function.
6
Experiment No. 4
Development of Program in C++ for Solution of Algebraic
Equation of Nth Degree by False Position Method
7
Aim: Development of Programs in C++ for Solution of Algebraic Equation of Nth
Degree by False Position Method
Objective: Development of programs in C++ for Numerical methods.
Theory:
False position method is successive iterative method used to calculate the root of nth
degree polynomial with one variable.
𝑥1 𝑓(𝑥2 ) − 𝑥2 𝑓(𝑥1 )
𝑥3 =
𝑓(𝑥2 ) − 𝑓(𝑥1 )
In above relationship, x1 and x2 are seed values to be calculated so that f(x1) and
f(x2) must be nearer to zero. Steps to construct cpp program are as follows.
Integer variable ‘N’ is used to store highest degree of x while float array ‘coef’ and
‘ind’ are used to store values of coefficients and indices of polynomial respectively.
In his step, program should ask for start point and end point of the range for which
system will calculate and display f(x) on screen. This is required so that user will
decide and provide the values of x1 and x2.
Here integer variable ‘a’ and ‘b’ are used to store the value of start point and end
point of the range. Nested loops are used to calculate and display value of f(x). Inner
loop is used to calculate f(x) for a particular value of x while outer loop is used to
repeat inner loop to calculate f(x) from a ≤ x ≤b.
In this step, program will receive the values of x1 and x2 from user. User will provide
the values of x1 and x2 by observing the values of f(x) for a ≤ x ≤ b. After receiving
the values of x1 and x2, program will calculate the value of f(x1) and f(x2).
8
Here, ‘x1’, ‘x2’, ‘fx1’ and ‘fx2’ float variables are used to store and calculate
respective values. Loop is used to calculate value of fx1 and fx2.
Now program will ask for number of iterations for which value of x is to be calculated.
Integer variable ‘iteration’ is used to store the value of number of iterations which
provided by user.
Nested loop is used to calculate value of x. Inner loop is used to calculate value of
f(x), while outer loop is used to repeat inner loop to calculate value of x ‘iteration’
times.
Exercise 1: Write C++ Program to find root of following algebric expression by false
position method with seed value 1 and 5
𝑦 = 2𝑥 3 − 2.5𝑥 − 5
Exercise 2: Write C++ Program to find root of following algebric expression by false
position method with seed value 1 and 5
𝑦 = 𝑥4 − 𝑥 − 9
9
Experiment No. 5
Development of Program in MATLAB for Solution of
Algebraic Equation of Nth Degree by False Position
Method
10
Aim: Development of Program in MATLAB for Solution of Algebraic Equation of Nth
Degree by False Position Method
Theory:
False position method is successive iterative method used to calculate the root of nth
degree polynomial with one variable.
𝑥1 𝑓(𝑥2 ) − 𝑥2 𝑓(𝑥1 )
𝑥3 =
𝑓(𝑥2 ) − 𝑓(𝑥1 )
In above relationship, x1 and x2 are seed values to be calculated so that f(x1) and
f(x2) must be nearer to zero. Steps to construct cpp program are as follows.
Integer variable ‘index’ is used to store highest degree of x while float array ‘coef’
and ‘ind’ are used to store values of coefficients and indices of polynomial
respectively.
Step 2. Input ‘startpt’ and ’endpt’ and calculate f(x) from startpt ≤ x ≤
endpt.
In his step, program should ask for start point and end point of the range for which
system will calculate and display f(x) on screen. This is required so that user will
decide and provide the values of x1 and x2.
Here integer variable ‘startpt’ and ‘endpt’ are used to store the value of start point
and end point of the range. Nested loops are used to calculate and display value of
f(x). Inner loop is used to calculate f(x) for a particular value of x while outer loop is
used to repeat inner loop to calculate f(x) from startpt ≤ x ≤endpt.
11
In this step, program will receive the values of x1 and x2 from user. User will provide
the values of x1 and x2 by observing the values of f(x) for startpt ≤ x ≤ endpt. After
receiving the values of x1 and x2, program will calculate the value of f(x1) and f(x2).
Here, ‘temp1’, ‘temp2’, ‘tempf1’ and ‘tempf2’ float variables are used to store and
calculate respective values. Loop is used to calculate value of fx1 and fx2.
Now program will ask for number of iterations for which value of x is to be calculated.
Integer variable ‘iteration’ is used to store the value of number of iterations which
provided by user.
Nested loop is used to calculate value of x. Inner loop is used to calculate value of
f(x). While outer loop is used to repeat inner loop to calculate value of x ‘iteration’
times.
𝑦 = 2𝑥 3 − 2.5𝑥 − 5
𝑦 = 𝑥4 − 𝑥 − 9
12
Experiment No. 6
Development of Program in C++ for Solution of Algebraic
Equation of Nth Degree by Newton-Raphson Method
13
Aim: Development of Programs in C++ for Solution of Algebraic Equation of Nth
Degree by Newton-Raphson Method
Theory:
𝑓(𝑥𝑛 )
𝑥𝑛+1 = 𝑥𝑛 −
𝑓 ′ (𝑥𝑛 )
For n =1
𝑓(𝑥0 )
𝑥1 = 𝑥0 −
𝑓 ′ (𝑥0 )
Like in false position method, x0 is the seed value to be provided by user. Steps to
construct cpp program are as follows.
Integer variable ‘N’ is used to store highest degree of x while float array ‘coef’ and
‘ind’ are used to store values of coefficients and indices of polynomial respectively.
In his step, program should ask for start point and end point of the range for which
system will calculate and display f(x) on screen. This is required so that user will
decide and provide the values of x1 and x2.
Here integer variable ‘a’ and ‘b’ are used to store the value of start point and end
point of the range. Nested loops are used to calculate and display value of f(x). Inner
loop is used to calculate f(x) for a particular value of x while outer loop is used to
repeat inner loop to calculate f(x) from a ≤ x ≤b.
14
Step 3. Input x0 and calculate f(x1) and f’(x1).
In this step, program will receive the value of x0 from user. User will provide the
value of x0 by observing the values of f(x) for a ≤ x ≤ b. After receiving the value of
x0, program will calculate the value of f(x0) and f’(x0).
Here, ‘x0’, ‘fx0’ and ‘fdashx0’ float variables are used to store and calculate
respective values. Loop is used to calculate value of fx0 and fsashx0.
Now program will ask for number of iterations for which value of x is to be calculated.
Integer variable ‘iteration’ is used to store the value of number of iterations which
provided by user.
Nested loop is used to calculate value of x. Inner loop is used to calculate value of
f(x). While outer loop is used to repeat inner loop to calculate value of x ‘iteration’
times.
𝑦 = 2𝑥 3 − 2.5𝑥 − 5
𝑦 = 𝑥4 − 𝑥 − 9
15
Experiment No. 7
Development of Program in MATLAB for Solution of
Algebraic Equation of Nth Degree by Newton-Raphson
Method
16
Aim: Development of Program in MATLAB for Solution of Algebraic Equation of Nth
Degree by Newton-Raphson Method
Theory:
𝑓(𝑥𝑛 )
𝑥𝑛+1 = 𝑥𝑛 −
𝑓 ′ (𝑥𝑛 )
For n =1
𝑓(𝑥0 )
𝑥1 = 𝑥0 −
𝑓 ′ (𝑥0 )
Like in false position method, x0 is the seed value to be provided by user. Steps to
construct cpp program are as follows.
Integer variable ‘N’ is used to store highest degree of x while float array ‘coef’ and
‘ind’ are used to store values of coefficients and indices of polynomial respectively.
In his step, program should ask for start point and end point of the range for which
system will calculate and display f(x) on screen. This is required so that user will
decide and provide the values of x1 and x2.
Here integer variable ‘a’ and ‘b’ are used to store the value of start point and end
point of the range. Nested loops are used to calculate and display value of f(x). Inner
loop is used to calculate f(x) for a particular value of x while outer loop is used to
repeat inner loop to calculate f(x) from a ≤ x ≤b.
17
Step 3. Input x0 and calculate f(x1) and f’(x1).
In this step, program will receive the value of x0 from user. User will provide the
value of x0 by observing the values of f(x) for a ≤ x ≤ b. After receiving the value of
x0, program will calculate the value of f(x0) and f’(x0).
Here, ‘x0’, ‘fx0’ and ‘fdashx0’ float variables are used to store and calculate
respective values. Loop is used to calculate value of fx0 and fsashx0.
Now program will ask for number of iterations for which value of x is to be calculated.
Integer variable ‘iteration’ is used to store the value of number of iterations which
provided by user.
Nested loop is used to calculate value of x. Inner loop is used to calculate value of
f(x). While outer loop is used to repeat inner loop to calculate value of x ‘iteration’
times.
𝑦 = 2𝑥 3 − 2.5𝑥 − 5
𝑦 = 𝑥4 − 𝑥 − 9
18
Experiment No. 08
Development of Program in C++ to calculate Eigen value
& Eigen vector of any square matrix
19
Aim: Development of Program in C++ to calculate Eigen value & Eigen vector of any
square matrix
Theory:
𝑋 =𝐴 ×𝐼
Where A is square matrix whose eigen value and eigen vector is to be find out. ‘I’ is
column matrix with number of rows equal to number of rows of ‘A’ matrix. Lambda (λ)
is eigen value obtained from ‘X’ matrix.
λ = 𝑋(1,1)
For more accuracy, above calculations are repeated several times. Steps to
construct cpp program are as follows.
First of all, Square matrix has to be feed to the program. Matrix is entered by
providing size of matrix first. Then program will ask for its values.
Integer variable ‘N’ is used to store size of square matrix. ‘a’ is used to store various
values of square matrix.
In his step, program will calculate product of ‘A’ matrix and ‘I’ matrix. Then by
extracting eigen value from ‘X’ matrix, eigen vector is obtained. This process will get
repeated ‘iteration’ times. Value of variable ‘iteration’ will be provided by user.
Exercise 1: Write C++ Program to find Eigen Value and Eigen Vector of following
matric
2 3 1
3 2 2
1 2 1
20
Exercise 2: Write C++ Program to find Eigen Value and Eigen Vector of following
matric
1 2 3
2 7 15
3 15 41
RESULT: Program of Eigen Value, Eigen Vector in C++ is explained and executed
successfully.
21
Experiment No. 09
Development of Program in MATLAB to calculate Eigen
value & Eigen vector of any square matrix
22
Aim: Development of Program in MATLAB to calculate Eigen value & Eigen vector
of any square matrix
Theory:
𝑋 =𝐴 ×𝐼
Where A is square matrix whose eigen value and eigen vector is to be find out. ‘I’ is
column matrix with number of rows equal to number of rows of ‘A’ matrix. Lambda (λ)
is eigen value obtained from ‘X’ matrix.
λ = 𝑋(1,1)
For more accuracy, above calculations are repeated several times. Steps to
construct cpp program are as follows.
First of all, Square matrix has to be feed to the program. Matrix is entered by
providing size of matrix first. Then program will ask for its values.
Integer variable ‘N’ is used to store size of square matrix. ‘A’ is used to store various
values of square matrix.
In his step, program will calculate product of ‘A’ matrix and ‘X’ matrix. Then by
extracting eigen value from ‘X’ matrix, eigen vector is obtained. This process will get
repeated ‘iteration’ times. Value of variable ‘iteration’ will be provided by user.
Exercise 1: Write MATLAB Program to find Eigen Value and Eigen Vector of
following matric
2 3 1
3 2 2
1 2 1
23
Exercise 2: Write MATLAB Program to find Eigen Value and Eigen Vector of
following matric
1 2 3
2 7 15
3 15 41
24
Experiment No. 10
Development of Program in C++ to calculate best fit
curve, sensitivity and deviation in output of an
instrument
25
Aim: Development of Program in C++ to calculate best fit curve, sensitivity and
deviation in output of an instrument.
Theory:
Best fit curve of an instrument is calculated from input provided to instrument and
output obtained from instrument. Formula to calculate the best fit curve is
𝑜𝑢𝑡𝑝𝑢𝑡 = 𝑚 × 𝑖𝑛𝑝𝑢𝑡 + 𝑐
Where ‘m’ is slope or it is also known as sensitivity of the instrument and ‘a’ is output
intercept. ‘m’ and ‘a’ can be calculated from following formula.
First of all, input and output are fed to the program by using float array ‘input’ and
’output’ respectively. Before it, number of readings is provided by using integer
variable ‘n’.
Step 2. Calculation & output of Best Fit curve, sensitivity and deviation
Now, float variables sumip, sumop, sumipop, sumipsq are used to calculate
summation of input, summation of output, summation of product of input and output
and summation of square of input respectively. These parameters are calculated by
using ‘for’ loop.
Then by using formulae for ‘m’ and ‘c’, best fit curve, sensitivity and deviation in
output is calculated.
Exercise 1: Write C++ Program to find best fit curve, sensitivity and deviation in
output of an instrument with following data.
Input 0 1 3 4 6 9 10 15 20 22
Output -12 -8 0.5 5 14 27 31 52 74 83
RESULT: Program of Best Fit Curve in C++ is explained and executed successfully.
26
Experiment No. 11
Development of Program in MATLAB to calculate best fit
curve, sensitivity and deviation in output of an
instrument
27
Aim: Development of Program in MATLAB to calculate best fit curve, sensitivity and
deviation in output of an instrument
Theory:
Best fit curve of an instrument is calculated from input provided to instrument and output
obtained from instrument. Formula to calculate the best fit curve is
𝑜𝑢𝑡𝑝𝑢𝑡 = 𝑚 × 𝑖𝑛𝑝𝑢𝑡 + 𝑐
Where ‘m’ is slope or it is also known as sensitivity of the instrument and ‘a’ is output
intercept. ‘m’ and ‘a’ can be calculated from following formula.
First of all, input and output are fed to the program by using array ‘inputs’ and
’outputs’ respectively. Before it, number of readings is provided by using integer
variable ‘n’.
Step 2. Calculation & output of Best Fit curve, sensitivity and deviation
Now, float variables sumip, sumop, sumipop, sumipsq are used to calculate
summation of input, summation of output, summation of product of input and output
and summation of square of input respectively. These parameters are calculated by
using ‘for’ loop.
Then by using formulae for ‘m’ and ‘c’, best fit curve, sensitivity and deviation in
output is calculated.
Exercise 1: Write MATLAB Program to find best fit curve, sensitivity and deviation
in output of an instrument with following data.
Input 0 1 3 4 6 9 10 15 20 22
Output -12 -8 0.5 5 14 27 31 52 74 83
28
Experiment No. 12
Development of Program in C++ to design knuckle joint
29
Aim: Development of Program in C++ to design knuckle joint
Theory
Knuckle joint is used to connect two rods subjected to axial tensile loads. Manual
design procedure of knuckle join which is to be programmed is taken from Design
data for machine elements by B.D. Shiwalkar.
Exercise 1: Write C++ Program to design knuckle joint with following details
Factor of safety :2
30
Experiment No. 13
Development of Program in MATLAB to design knuckle
joint
31
Aim: Development of Program in MATLAB to design knuckle joint
Theory
Knuckle joint is used to connect two rods subjected to axial tensile loads. Manual
design procedure of knuckle join which is to be programmed is taken from Design
data for machine elements by B.D. Shiwalkar.
Exercise 1: Write MATLAB Program to design knuckle joint with following details
Factor of safety :2
32