Experiment No. 1: Development of Programs in C++ For Demonstration of Various Types of Functions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 33

Experiment No.

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.

Objective: Development of application programs in C++ exploring use of functions,


vectors, arrays.

Exercise 1: Write a C++ Program to Multiply Two Numbers by Using Function

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.

Exercise 2: Write C++ Program To Display Fibonacci Using Recursion

Theory: in this exercise, Fibonacci series is generated. In Fibonacci series, number


in the series is obtained by adding previous two numbers of the series. Hence in this
exercise, an integer function ‘func_fib’ is used to receive a single integer value & to
return a single integer value. The value given to function is the location of the value
in the series (place of the value in the series i.e. first, second, third....etc) and
function generates the actual value of that location by adding last two values.

RESULT: Demonstration of functions in C++ is explained and executed successfully.

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

Objective: Development of application programs in C++ exploring use of functions,


vectors, arrays.

Exercise 1: Write C++ Program to sort an array using Bubble sort technique

Theory: Bubble sorting is a sorting technique in which two consecutive elements in


an array are compared and interchanged if required. In this exercise, an integer
array ‘a’ is used. Two nested loops are used for sorting purpose. Outer loop is used
for number of passes while inner loop is used to interchange the value if required.

Exercise 2: Write C++ Program to search in an array using Binary search technique

Theory: Binary search is a technique in which a particular number is searched in an


indexed array.

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

Objective: Exposure to commercial software for the application of Mathematical


Software for solution of problems in the areas of Mechanical Engineering.

INTRODUCTION

MATLAB (MATrix LABoratory) is a multi-paradigm numerical computing environment


and fourth-generation programming language. Developed by MathWorks, MATLAB
allows matrix manipulations, plotting of functions and data, implementation of
algorithms, creation of user interfaces, and interfacing with programs written in other
languages, including C, C++, Java, and ForTran.

MATLAB is an abbreviation for "matrix laboratory." While other programming


languages usually work with numbers one at a time, MATLAB operates on whole
matrices and arrays. Language fundamentals include basic operations, such as
creating variables, array indexing, arithmetic, and data types.

Although MATLAB is intended primarily for numerical computing, an optional toolbox


uses the MuPAD symbolic engine, allowing access to symbolic computing
capabilities. An additional package, Simulink, adds graphical multi-domain simulation
and Model-Based Design for dynamic and embedded systems.

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.

GRAPHICS AND GRAPHICAL USER INTERFACE PROGRAMMING

MATLAB supports developing applications with graphical user interface features.


MATLAB includes GUIDE (GUI development environment) for graphically designing
GUIs. It also has tightly integrated graph-plotting features. For example the function
plot can be used to produce a graph from two vectors x and y. The code:

RESULT: New mathematical package MATLAB is introduced and its functionality is


demonstrated successfully.

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.

Consider following polynomial whose root is to be found out.

𝑦 = 𝑓(𝑥) = 𝑎𝑛 𝑥 𝑛 + 𝑎𝑛−1 𝑥 𝑛−1 + 𝑎𝑛−2 𝑥 𝑛−2 + 𝑎𝑛−3 𝑥 𝑛−3 … … … … … … … + 𝑎0 𝑥 0 = 0

Then following formula is used to find successive values of x

𝑥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.

Step 1. Input polynomial.

First of all, polynomial has to be feed to the program. Polynomial is entered by


means of three parameters i.e. highest degree of polynomial, coefficients of x and
indices of x.

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.

Step 2. Input ‘a’ and ’b’ and calculate f(x) from a ≤ x ≤ b.

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.

Step 3. Input x1 and x2 and calculate f(x1) and f(x2).

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.

Step 4. Calculate x for N number of iterations

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

RESULT: Program of False Position Method in C++ is explained and executed


successfully.

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

Objective: Application of Mathematical Software for solution of problems in the


areas of Mechanical Engineering.

Theory:

False position method is successive iterative method used to calculate the root of nth
degree polynomial with one variable.

Consider following polynomial whose root is to be found out.

𝑦 = 𝑓(𝑥) = 𝑎𝑛 𝑥 𝑛 + 𝑎𝑛−1 𝑥 𝑛−1 + 𝑎𝑛−2 𝑥 𝑛−2 + 𝑎𝑛−3 𝑥 𝑛−3 … … … … … … … + 𝑎0 𝑥 0 = 0

Then following formula is used to find successive values of x

𝑥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.

Step 1. Input polynomial.

First of all, polynomial has to be feed to the program. Polynomial is entered by


means of three parameters i.e. highest degree of polynomial, coefficients of x and
indices of x.

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.

Step 3. Input x1 and x2 and calculate f(x1) and f(x2).

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.

Step 4. Calculate x for N number of iterations

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 MATLAB 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 MATLAB Program to find root of following algebric expression by


false position method with seed value 1 and 5

𝑦 = 𝑥4 − 𝑥 − 9

RESULT: Program of False Position Method in MATLAB is explained and executed


successfully.

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

Objective: Development of programs in C++ for Numerical methods.

Theory:

Newton-Raphson method is successive iterative method used to calculate the root of


nth degree polynomial with one variable.

Consider following polynomial whose root is to be found out.

𝑦 = 𝑓(𝑥) = 𝑎𝑛 𝑥 𝑛 + 𝑎𝑛−1 𝑥 𝑛−1 + 𝑎𝑛−2 𝑥 𝑛−2 + 𝑎𝑛−3 𝑥 𝑛−3 … … … … … … … + 𝑎0 𝑥 0 = 0

Then following formula is used to find successive values of x

𝑓(𝑥𝑛 )
𝑥𝑛+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.

Step 1. Input polynomial.

First of all, polynomial has to be feed to the program. Polynomial is entered by


means of three parameters i.e. highest degree of polynomial, coefficients of x and
indices of x.

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.

Step 2. Input ‘a’ and ’b’ and calculate f(x) from a ≤ x ≤ b.

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.

Step 4. Calculate x for N number of iterations

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


Newton Raphson 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


Newton Raphson method with seed value 1 and 5

𝑦 = 𝑥4 − 𝑥 − 9

RESULT: Program of Newton Raphson Method in C++ is explained and executed


successfully.

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

Objective: Application of Mathematical Software for solution of problems in the


areas of Mechanical Engineering

Theory:

Newton-Raphson method is successive iterative method used to calculate the root of


nth degree polynomial with one variable.

Consider following polynomial whose root is to be found out.

𝑦 = 𝑓(𝑥) = 𝑎𝑛 𝑥 𝑛 + 𝑎𝑛−1 𝑥 𝑛−1 + 𝑎𝑛−2 𝑥 𝑛−2 + 𝑎𝑛−3 𝑥 𝑛−3 … … … … … … … + 𝑎0 𝑥 0 = 0

Then following formula is used to find successive values of x

𝑓(𝑥𝑛 )
𝑥𝑛+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.

Step 1. Input polynomial.

First of all, polynomial has to be feed to the program. Polynomial is entered by


means of three parameters i.e. highest degree of polynomial, coefficients of x and
indices of x.

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.

Step 2. Input ‘a’ and ’b’ and calculate f(x) from a ≤ x ≤ b.

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.

Step 4. Calculate x for N number of iterations

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


Newton Raphson 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


Newton Raphson method with seed value 1 and 5

𝑦 = 𝑥4 − 𝑥 − 9

RESULT: Program of Newton Raphson Method in MATLAB is explained and


executed successfully.

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

Objective: Development of programs in C+ + for Numerical methods

Theory:

An eigen vector v of a linear transformation T is a non-zero vector that, when T is


applied to it, does not change direction. Applying T to the eigenvector only scales the
eigen vector by the scalar value λ, called an eigen value. This condition can be
written as the equation

𝑋 =𝐴 ×𝐼

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.

Step 1. Input Matrix.

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.

Step 2. Calculation & output of eigen value and eigen vector

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

Objective: Application of Mathematical Software for solution of problems in the


areas of Mechanical Engineering.

Theory:

An eigen vector v of a linear transformation T is a non-zero vector that, when T is


applied to it, does not change direction. Applying T to the eigenvector only scales the
eigen vector by the scalar value λ, called an eigen value. This condition can be
written as the equation

𝑋 =𝐴 ×𝐼

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.

Step 1. Input Matrix.

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.

Step 2. Calculation & output of eigen value and eigen vector

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

RESULT: Program of Eigen Value, Eigen Vector in MATLAB is explained and


executed successfully.

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.

Objective: Development of programs in C++ to solve the problem in the areas of


Mechanical Engineering.

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.

𝑛 × ∑(𝑖𝑛𝑝𝑢𝑡 × 𝑜𝑢𝑡𝑝𝑢𝑡) − ∑ 𝑖𝑛𝑝𝑢𝑡 × ∑ 𝑜𝑢𝑡𝑝𝑢𝑡


𝑚=
∑(𝑖𝑛𝑝𝑢𝑡 × 𝑖𝑛𝑝𝑢𝑡) − ∑ 𝑖𝑛𝑝𝑢𝑡 × ∑ 𝑜𝑢𝑡𝑝𝑢𝑡

∑ 𝑜𝑢𝑡𝑝𝑢𝑡 × ∑(𝑖𝑛𝑝𝑢𝑡 × 𝑖𝑛𝑝𝑢𝑡) − ∑(𝑖𝑛𝑝𝑢𝑡 × 𝑜𝑢𝑡𝑝𝑢𝑡) × ∑ 𝑖𝑛𝑝𝑢𝑡


𝑎=
𝑛 × ∑(𝑖𝑛𝑝𝑢𝑡 × 𝑖𝑛𝑝𝑢𝑡) − ∑ 𝑖𝑛𝑝𝑢𝑡 × ∑ 𝑖𝑛𝑝𝑢𝑡

Step 1. Input ‘input’ and ’response’/ ’output’ of instrument.

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

Objective: Application of Mathematical Software for solution of problems in the


areas of Mechanical Engineering.

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.

𝑛 × ∑(𝑖𝑛𝑝𝑢𝑡 × 𝑜𝑢𝑡𝑝𝑢𝑡) − ∑ 𝑖𝑛𝑝𝑢𝑡 × ∑ 𝑜𝑢𝑡𝑝𝑢𝑡


𝑚=
∑(𝑖𝑛𝑝𝑢𝑡 × 𝑖𝑛𝑝𝑢𝑡) − ∑ 𝑖𝑛𝑝𝑢𝑡 × ∑ 𝑜𝑢𝑡𝑝𝑢𝑡

∑ 𝑜𝑢𝑡𝑝𝑢𝑡 × ∑(𝑖𝑛𝑝𝑢𝑡 × 𝑖𝑛𝑝𝑢𝑡) − ∑(𝑖𝑛𝑝𝑢𝑡 × 𝑜𝑢𝑡𝑝𝑢𝑡) × ∑ 𝑖𝑛𝑝𝑢𝑡


𝑎=
𝑛 × ∑(𝑖𝑛𝑝𝑢𝑡 × 𝑖𝑛𝑝𝑢𝑡) − ∑ 𝑖𝑛𝑝𝑢𝑡 × ∑ 𝑖𝑛𝑝𝑢𝑡

Step 1. Input ‘input’ and ’response’/ ’output’ of instrument.

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

RESULT: Program of Best Fit Curve in MATLAB is explained and executed


successfully.

28
Experiment No. 12
Development of Program in C++ to design knuckle joint

29
Aim: Development of Program in C++ to design knuckle joint

Objective: Development of programs in C++ to solve the problem in the areas of


Mechanical Engineering.

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

Tensile load to be carried : 50 KN

Factor of safety :2

Yield strength of material : 440 Mpa

Shear strength of material : 360 Mpa

RESULT: Program of design of Knuckle Joint in C++ is explained and executed


successfully.

30
Experiment No. 13
Development of Program in MATLAB to design knuckle
joint

31
Aim: Development of Program in MATLAB to design knuckle joint

Objective: Application of Mathematical Software for solution of problems in the


areas of Mechanical Engineering.

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

Tensile load to be carried : 50 KN

Factor of safety :2

Yield strength of material : 440 Mpa

Shear strength of material : 360 Mpa

RESULT: Program of Design of Knuckle Joint in MATLAB is explained and executed


successfully.

32

You might also like