You are on page 1of 25

Experiential Learning Department of Mathematics

Contents

Introduction 2

Modules

1 Linear programming Problem 3

2 Complex Analysis 8

3 Statistics 10

4 Probability Distribution 16

5 Markov chain 21

RV College of Engineering® 1 Enjoy Learning…


Experiential Learning Department of Mathematics

1 Linear Programming Problems


Topic learning outcomes:
Student will be able to:

Solve linear programming models.

Syntax and description:

 x = linprog (f,A,b) solves min f'*x such that A*x ≤ b.


 x = linprog(f,A,b,Aeq,beq) includes equality constraints Aeq*x = beq.
set A = [] and b = [] if no inequalities exist.
 x = linprog(f,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds
on the design variables, x, so that the solution is always in the range lb ≤ x ≤ ub.
Set Aeq = [] and beq = [] if no equalities exist.

Example 1.1: Find the values of so that


Minimize
Subject to

f=[1 -3 2]; % defining the function to be maximized


A =[3 -1 3;-2 4 0;-4 3 8;-1 0 0;0 -1 0;0 0 -1]; % the constraints
b=[7 12 10 0 0 0]; % lowerbound for the variable
x=linprog(f,A,b)
minz=f*x

Optimization terminated
x =
4.0000
5.0000
0.0000
z =
-11.0000

Example 1.2: Solve linear programming problem


Maximize
subject to

RV College of Engineering® 2 Enjoy Learning…


Experiential Learning Department of Mathematics

f=[5 3]; % defining the function to be maximized


A =[1 1;5 2;3 8]; % the constraints
b=[2 10 12];
lb=[0 0];
x=linprog(-f,A,b,[],[],lb) % gives the point at which f attains maximum
z=f*x

Optimization terminated
x =
2.0000
0.0000
z =
10.0000

Example 1.3: Food X contains 6 units of vitamin A per gram and 7 units of vitamin B per
gram and costs 12 paise per gram. Food Y contains 8 units of vitamin A per gram and 12
units of vitamin B and costs 20 paise per gram. The daily minimum requirements of vitamin
A and vitamin B are 100 units and 120 units respectively. Find the minimum cost of product
mix by simplex method.
Hint: Let grams of food X and grams of food Y be purchased. Then the problem can be
formulated as:
Minimize
Subject to:

f=[12 20]; % defining the function to be maximized


A =[-6 -8;-7 -12]; % the constraints
b=[-100 -120];
lb=[0 0];
x=linprog(f,A,b,[],[],lb) % gives the point at which f attains minimum
z=f*x

Optimization terminated.
x =
15.0000
1.2500
z =
205.0000

Example 1.4: Solve LPP:


Maximize
Subject to

RV College of Engineering® 3 Enjoy Learning…


Experiential Learning Department of Mathematics

f=[1 2 3 -1]; % defining the function to be maximized


Aeq =[1 2 3 0;2 1 5 0;1 2 1 4]; % the constraints
beq=[15; 20; 10];
lb=[0 0 0 0];
x=linprog(-f, Aeq,beq,[],[],lb) % gives the point at which f attains maximum
z=f*x

Optimization terminated.
x =
2.5000
2.5000
2.5000
0.0000
z =
15.0000

Example 1.5: Solve the following linear programming problem:


Min.
Subject to

( )

f = [-1 -1/3];
A = [1 1;1 1/4;1 -1;-1/4 -1;1 -1;-1 1];
b = [2 1 2 1 -1 2];
Aeq = [1 1/4];
beq = [1/2];
lb = [-1,-0.5];
ub = [1.5,1.25];
x=linprog(-f,A,b,Aeq,beq,lb,ub)
z=f*x

Optimization terminated.
x =
0.1875
1.2500
z =
-0.6042

RV College of Engineering® 4 Enjoy Learning…


Experiential Learning Department of Mathematics

Example 1.6 A manufacturer produces two models and of a product. Each unit of
model requires 4 hours grinding and 2 hours polishing. Each unit of model requires 2
hours grinding and 5 hours polishing. The manufacturer has 2 grinders each of which works
for 40 hours a week. There are 3 polishers each of which works for 60 hours per week. Profit
of model is Rs.300 per unit and profit of model is Rs. 400 per unit. The manufacturer
has to allocate his production capacity so as to maximize his profit. Formulate the LPP.

Hint: Maximize
subject to

f=[300 400]; % defining the function to be maximized


A=[4 2;2 5]; % the constraints
b=[80 180];
lb=[0 0]; % lowerbound for the variable
x=linprog(f,A,b,[],[],lb) % gives the point at which z attains maximum
z=f*x

x =
2.5000
35.0000
z =
1.4750e+04

Exercise:

1. A firm produces an alloy having the following specifications.


(i) Specific gravity ≤ 0.98%
(ii) Chromium content ≥ 8%
(iii) Melting point ≥450°C
Raw materials A and B are used to produce the alloy. Raw material A has specific gravity
0.92, chromium content 7% and melting point 440°C. Raw material B has specific gravity
0.99, chromium content 13% and melting point 490°C. If raw material A costs Rs.90 per kg
and raw material costs Rs.280 per kg . Find the rate at which the raw material should be
blended keeping cost in mind.

RV College of Engineering® 5 Enjoy Learning…


Experiential Learning Department of Mathematics

2. Minimize
subject to

3. The following table gives the various vitamin contents of three types of food and daily
requirements of vitamins along with cost per unit. Find the combination of food for minimum
cost.

Vitamin(mg) Food F Food G Food H Minimum daily


requirement(mg)
A 1 1 10 1
C 100 10 10 50
D 10 100 10 10
Cost/unit(Rs) 10 15 5

4. Minimize
Subject to

RV College of Engineering® 6 Enjoy Learning…


Experiential Learning Department of Mathematics

2 Complex Integration

Topic learning outcomes:


Student will be able to:

1. Evaluate line integral and contour integral in the complex plane

2. Verify Cauchy's theorem

Syntax and description:

• q = integral(fun,zmin,zmax)- integrates complex function fun from zmin to zmax.


•q = integral(fun,zmin,zmax,Name,Value) specifies additional options with one or more
Name,Value pair arguments. For example, specify 'WayPoints'followed by a vector of
real or complex numbers to indicate specific points for the integrator to use.

Example 2.1: Compute around the square with vertices at (0,0), (1,0), (1,1),
(0,1).

Example 2.2: Obtain along the line joining the points A(1,-1) and B(2,3).

Example 2.3: Evaluate where c is the upper half of the circle |z-2|=3.

Hint: Take .

RV College of Engineering® 7 Enjoy Learning…


Experiential Learning Department of Mathematics

Example 2.4: Find where c is the square with vertices at

Exercise:
1. Find
2. Integrate the function along the curve c: circle of radius 2, centre origin.
3. Verify Cauchy's theorem for the integral of taken over the triangle
formed by the points (1,2), (3,2) and (1,4).
4. Evaluate along the line joining the points A(1,-1) and B(2,3).

RV College of Engineering® 8 Enjoy Learning…


Experiential Learning Department of Mathematics

3 Statistics

Topic learning outcomes:


Student will be able to:

1. Find measures of central tendency: moments, skewness and kurtosis.

2. Fit data into several types of curves.

3. Obtain correlation coefficient and regression lines.

Syntax and description:

 m = moment(X,order) returns the central moment of X for the order specified by


order.
 y = skewness(X) returns the sample skewness of X.
 k = kurtosis(X) returns the sample kurtosis of X.
 R = corrcoef(A,B) returns coefficients between two variables A and B.
 fitobject = fit(x,y,fitType) creates the fit to the data in x and y with the model
specified by fitType.
 R = corrcoef(A,B) returns correlation coefficient between two random variables A and B.
 [r,m,b] = regression(x,y) returns correlation coefficient ‘r’ between two
variables x and y, slope ‘m’ of the regression line of y on x, i.e., y= mx+ b and
constant term ‘b’.
Note: fitType can be
1. Linear model ‘Poly1’:
f(x) = p1*x + p2
2. Quadratic model ‘Poly2’:
f(x) = p1*x^2 + p2*x + p3
3. General model ‘Exp1’:
f(x) = a*exp(b*x)
4. General model ‘Power1’:
f(x) = a*x^b

Example 3.1 Wages of workers in a company are given in the following table:
Wages 50-70 70-90 90-110 110-130 130-150 150-170 170-190
No. of 4 8 12 20 6 7 3
workers(f)

Calculate the first four central moments, skewness and kurtosis for the following distribution.
Note : ‘x’ is taken as the middle value of class interval, ‘f’ is no. of times x is repeated.
x=[60 60 60 60 80 80 80 80 80 80 80 80 100 100 100 100 100 100 100 100 100 100
100 100 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120 120
120 120 120 140 140 140 140 140 140 160 160 160 160 160 160 160 180 180 180];
y1=moment(x,1)

RV College of Engineering® 9 Enjoy Learning…


Experiential Learning Department of Mathematics

y2=moment(x,2)
y3=moment(x,3)
y4=moment(x,4)
sk = skewness(x)
k = kurtosis(x)

ans =
y1 = 0
y2 = 926.5556
y3 = 4.7747e+03
y4 = 2.1951e+06
sk = 0.1693
k = 2.5569

Example 3.2: Fit a straight line to the following data.


x 1 6 11 16 20 26
y 13 16 17 23 24 31

x = [1 6 11 16 20 26]';
y =[ 13 16 17 23 24 31]';
f=fit(x,y,'Poly1')
plot(f,x,y)

f =
Linear model Poly1:
f(x) = p1*x + p2
Coefficients (with 95% confidence bounds):
p1 = 0.7008 (0.4936, 0.908)
p2 = 11.32 (8.057, 14.59)

Example 3.3: The following table gives the results of the measurements of train resistances;
V is the velocity in mile per hour and R is the resistance in pound per ton.
V 20 40 60 80 100 120
R 5.5 9.1 14.9 22.8 33.3 46

If R is related to V by the relation R= a + bV + cV2 .

RV College of Engineering® 10 Enjoy Learning…


Experiential Learning Department of Mathematics

x=[20 40 60 80 100 120]';


y=[5.5 9.1 14.9 22.8 33.3 46]';
f=fit(x,y,'Poly2')
plot(f,x,y)
f =
Linear model Poly2:
f(x) = p1*x^2 + p2*x + p3
Coefficients (with 95% confidence bounds):
p1 = 0.002871 (0.002753, 0.002989)
p2 = 0.002411 (-0.01447, 0.01929)
p3 = 4.35 (3.834, 4.866)

Example 3.4: An experiment gave the following values


v(ft/min) 350 400 500 600
t(min) 61 26 7 26
It is known that v and t are connected by the relation v = atb .

v=[350 400 500 600]';


t=[61 26 7 26]';
f=fit(v,t,'Power1')
plot(f,v,t)

f =
General model Power1:
f(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 4.802e+11 (-2.764e+13, 2.86e+13)
b = -3.902 (-13.81, 6.005)

RV College of Engineering® 11 Enjoy Learning…


Experiential Learning Department of Mathematics

Example 3.5: Fit a curve of the form y = a e b x to the data by the method of least squares.

x 0 2 4
y 8.12 10 31.82

x=[0 2 4]';
y=[8.12 10 31.82]';
f=fit(x,y,'Exp1')
plot(f,x,y)

f =
General model Exp1:
f(x) = a*exp(b*x)
Coefficients (with 95% confidence bounds):
a = 4.989 (-27.4, 37.38)
b = 0.4593 (-1.273, 2.192)

Example 3.6 The following table gives the stopping distance y in meters of a motor bike
moving at a speed of x kms/hour when the breaks are applied.

RV College of Engineering® 12 Enjoy Learning…


Experiential Learning Department of Mathematics

x 16 24 32 40 48 56
y 0.39 0.75 1.23 1.91 2.77 3.81

Find the correlation coefficient between the speed and the stopping distance, and the
equations of regression lines. Hence estimate the maximum speed at which the motor bike
could be driven if the stopping distance is not to exceed 5 meters.
x=[16 24 32 40 48 56]';
y=[0.39 0.75 1.23 1.91 2.77 3.81]';
R = corrcoef(x,y)
[r,m,b] = regression(x,y)

ans =
R = 2×2
1.0000 0.9827
0.9827 1.0000

r = 0.9827
m = 0.0851
b = -1.2551

Exercise:
1. Find the second, third and fourth central moments of the frequency distribution
given below. Hence, find (i) a measure of skewness and (ii) a measure of kurtosis.

Class 110.0 – 115.0 – 120.0 – 125.0 – 130.0 – 135.0 – 140.0 –


limits 114.9 119.9 124.9 129.9 134.9 134.9 144.9
Frequency 5 15 20 35 10 10 5

2. Find the second, third and fourth central moments of the frequency distribution
given below. Hence, find (i) a measure of skewness and (ii) a measure of kurtosis.

x 5 10 15 20 25 30 35
f 4 3 2 8 10 10 5

3. Estimate the mean radiation dose at an altitude of 3000 ft by fitting a curve y=a to the
given data:

Altitude(x) 50 450 780 1200 4400 4800 5300


Dose of 28 30 32 36 51 58 69
radiation

RV College of Engineering® 13 Enjoy Learning…


Experiential Learning Department of Mathematics

4. The latent heat of vaporisation of steam r is given in the following table at different
temperature t:

t 40 50 60 70 80 90 100 110
r 1069.1 1063.6 1058.2 1052.7 1049.3 1041.8 1036.3 1030.8

Fit a relation to the form r =a+bt.

5. The following table gives the result of the measurement of train resistances; V is the
velocity in miles per hour; R is the resistance in pounds per ton:

V 20 40 60 80 100 120
R 5.5 9.1 14.9 22.8 33.3 46.0

6. The following data represent carbon dioxide( ) emission from coal-fluid boilers (In
units of 1000 tons) over a period of years 2005 to 2017. The variable (year) has been
standardized and yield following table.

Years(x) 0 5 8 9 10 11 12
emission (y) 910 680 520 450 370 350 340
Find regression model of y on x.

7. Obtain the lines of regression and hence find the coefficient of correlation for the
following data
X 1 3 4 2 5 8 9 10 13 15
Y 8 6 10 8 12 16 16 10 32 32

RV College of Engineering® 14 Enjoy Learning…


Experiential Learning Department of Mathematics

4 Probability Distributions
Topic learning outcomes:
Student will be able to:

1. Generate probability distributions based on given parameters.


2. Plot the probability distribution functions.
3. Fit a probability distribution.

Syntax and description:

A BinomialDistribution object consists of parameters, a model description, and sample


data for a binomial probability distribution

The binomial distribution models the total number of successes in repeated trials from an
infinite population under the following conditions:

 Only two outcomes are possible for each of n trials.


 The probability of success for each trial is constant.
 All trials are independent of each other.

The binomial distribution uses the following parameters.

Parameter Description Support

N Number of trials positive integer

P Probability of success 0≤p≤1

Distribution Parameters
N — Number of trials
positive integer value
p — Probability of success
positive scalar value in the range [0,1]

Creation

There are several ways to create a BinomialDistribution probability distribution object.

 Create a distribution with specified parameter values using makedist.


 Fit a distribution to data using fitdist.
 Interactively fit a distribution to data using the Distribution Fitter app.

RV College of Engineering® 15 Enjoy Learning…


Experiential Learning Department of Mathematics

'Name'
Input Input
Distribution
Parameter A Parameter B
p probability of
'Binomial'
Binomial n number of
success for each
Distribution trials
trial
Chi-Square ν degrees of
'Chisquare' —
Distribution freedom
Exponential
'Exponential' μ mean —
Distribution
'Gamma'
Gamma a shape b scale
Distribution parameter parameter
Normal σ standard
'Normal' μ mean
Distribution deviation
Poisson
'Poisson' λ mean —
Distribution

Example 4.1: The probability that a man aged 60 will live to be 70 is 0.65. What is the
probability that out of 10 men now aged 60,
(i) at most 6,
(ii) at least 7
will live to be 70?
Solution:
pd = makedist('Binomial','N',10,'p',0.65)
x = [6];
y = cdf(pd,x)
z=1-y

pd =
BinomialDistribution
Binomial distribution
N = 10
p = 0.65
y =
0.4862
z =
0.513

Example 4.2: Create a binomial distribution object by specifying the parameter values. Also
compute the mean of the distribution.

pd = makedist('Binomial','N',30,'p',0.25)
m = mean(pd)

RV College of Engineering® 16 Enjoy Learning…


Experiential Learning Department of Mathematics

pd =
Binomial distribution
N = 30
p = 0.25
m =
7.5000

Example 4.3: Generate a plot of the binomial pdf for n = 10 and p = 1/2.
x = 0:10;
y = binopdf(x,10,0.5);
plot(x,y,'+')

Example 4.4: Create a normal probability distribution object with mean 50 and SD 30.
Generate a 2-by-3-by-2 array of random numbers from the distribution.

pd = makedist('Normal','mu',50,'sigma',30)
r = random(pd,[2,3,2])

pd =
NormalDistribution

Normal distribution
mu = 50
sigma = 30
r =
r(:,:,1) =

31.4751 98.6682 42.3748


122.9576 48.9985 25.4413

r(:,:,2) =

RV College of Engineering® 17 Enjoy Learning…


Experiential Learning Department of Mathematics

96.1240 24.0135 17.3124


1.8054 36.8490 13.3768

Example 4.5: Create an exponential probability distribution object using the default
parameter values, generate random numbers from the distribution. Construct a histogram
using 100 bins with Exponential distribution fit.

pd = makedist('Exponential')
rng('default') % For reproducibility
r = random(pd,10000,1)
histfit(r,100,'Exponential')

pd =
ExponentialDistribution

Exponential distribution
mu = 1
r = 10000×1
0.2049
0.0989
2.0637
0.0906
0.4583
2.3275
1.2783
0.6035
0.0434
0.0357

Example 4.6: Create a Poisson distribution object with the rate parameter, λ, equal to 2.
Compute the pdf and cdf values for the Poisson distribution at the values in the input vector x
= [0,1,2,3,4].

lambda = 2;
pd = makedist('Poisson','lambda',lambda);

RV College of Engineering® 18 Enjoy Learning…


Experiential Learning Department of Mathematics

x = [0,1,2,3,4];
y = cdf(pd,x)
z = pdf(pd,x)

y = 1×5

0.1353 0.4060 0.6767 0.8571 0.9473

Z = 1×5

0.1353 0.2707 0.2707 0.1804 0.0902

Exercise:
1. Execute the example questions for different distributions with different parameter values.

2. The probability that an individual will suffer a bad reaction from an injection of a given
serum is 0.001. Determine the probability that out of 2000 induviduals
(i) exactly 3
(ii) more than 2
induviduals will suffer a bad reaction. (use lambda = np)

3. The length of a telephone conversation on a cell phone has been an exponential distribution
and found on an average to be 3 minutes. Find the probability that a random call made from
this phone ends in less than 3 minutes.

4. In a test of 2000 electric bulbs, it was found that the life of a particular make was normally
distributed with an average life of 2040 hours and standard deviation of 60 hours. Estimate
the number of bulbs likely to burn for
(i) more than 1950 hours
(ii) more than 1920 and less than 2160 hours.

RV College of Engineering® 19 Enjoy Learning…


Experiential Learning Department of Mathematics

5 Markov Chain
Topic learning outcomes:
Student will be able to:

1. Create a discrete time markov chain from a given state transition matrix.
2. Plot a directed graph of a markov chain.

Syntax and Description

mc = dtmc(P) creates the discrete-time Markov chain object mc specified by the state
transition matrix P.

mc = dtmc(P,'StateNames',stateNames) optionally associates the names stateNames to


the states.

State transition matrix, specified as a numStates-by-numStates nonnegative numeric matrix.

P(i,j) is either the theoretical probability of a transition from state i to state j or an


empirical count of observed transitions from state i to state j. P can be fully specified (all
elements are nonnegative numbers), partially specified (elements are a mix of nonnegative
numbers and NaN values), or unknown (completely composed of NaN values).

dtmcnormalizes each row of P without any NaN values to sum to 1, then stores the
normalized matrix in the property P.

Properties

You can set writable property values when you create the model object by using name-value
pair argument syntax, or after you create the model object by using dot notation. For
example, for the two-state model mc, to label the first and second states Depression and
Recession, respectively, enter:

mc.StateNames = ["Depression" "Recession"];

NumStates — Number of states


positive scalar

This property is read-only.

Number of states, specified as a positive scalar.

RV College of Engineering® 20 Enjoy Learning…


Experiential Learning Department of Mathematics

StateNames — State labels


string(1:numStates) (default) | string vector | cell vector of character
vectors | numeric vector

State labels, specified as a string vector, cell vector of character vectors, or numeric vector of
length numStates. Elements correspond to rows and columns of P.

Example: ["Depression" "Recession" "Stagnant" "Boom"]

Data Types: string

Visualize Markov Chain


distplot Plot Markov chain redistributions

eigplot Plot Markov chain eigenvalues

graphplot Plot Markov chain directed graph

simplot Plot Markov chain simulations

Example 5.1 Consider this, right-stochastic transition matrix of a stochastic process.

Element Pij is the probability that the process transitions to state j at time t + 1 given that it is
in state i at time t, for all t.

Create the Markov chain that is characterized by the transition matrix P.

Solution

P = [0.5 0.5 0 0; 0.5 0 0.5 0; 0 0 0 1; 0 0 1 0];


mc = dtmc(P);

mc is a dtmc object that represents the Markov chain.

Display the number of states in the Markov chain.

numstates = mc.NumStates
numstates = 4

Plot a directed graph of the Markov chain.

figure;
graphplot(mc);

RV College of Engineering® 21 Enjoy Learning…


Experiential Learning Department of Mathematics

Observe that states 3 and 4 form an absorbing class, while states 1 and 2 are transient

Example 5.2 Consider this transition matrix in which element (i,j) is the observed number of
times state i transitions to state j.

For example, P32=7 implies that state 3 transitions to state 2 seven times.

P = [16 2 3 13;
5 11 10 8;
9 7 6 12;
4 14 15 1];

Create the Markov chain that is characterized by the transition matrix P.

mc = dtmc(P);

Display the normalized transition matrix stored in mc. Verify that the elements within rows
sum to 1 for all rows.

mc.P
ans = 4×4

0.4706 0.0588 0.0882 0.3824


0.1471 0.3235 0.2941 0.2353
0.2647 0.2059 0.1765 0.3529
0.1176 0.4118 0.4412 0.0294

sum(mc.P,2)
ans = 4×1

RV College of Engineering® 22 Enjoy Learning…


Experiential Learning Department of Mathematics

1
1
1
1

Plot a directed graph of the Markov chain.

figure;
graphplot(mc);

Example 5.3 Consider the, right-stochastic transition matrix of a stochastic process.

Create the Markov chain that is characterized by the transition matrix P.

P = [ 0 0 1/2 1/4 1/4 0 0 ;


0 0 1/3 0 2/3 0 0 ;
0 0 0 0 0 1/3 2/3;
0 0 0 0 0 1/2 1/2;
0 0 0 0 0 3/4 1/4;
1/2 1/2 0 0 0 0 0 ;
1/4 3/4 0 0 0 0 0 ];
mc = dtmc(P);

Plot a directed graph of the Markov chain. Indicate the probability of transition by using edge
colors.

figure;
graphplot(mc,'ColorEdges',true);

RV College of Engineering® 23 Enjoy Learning…


Experiential Learning Department of Mathematics

Simulate a 20-step random walk that starts from a random state.

rng(1); % For reproducibility


numSteps = 20;
X = simulate(mc,numSteps)
X = 21×1

3
7
1
3
6
1
3
7
2
5

X is a 21-by-1 matrix. Rows correspond to steps in the random walk. Because X(1) is 3, the
random walk begins at state 3.

Visualize the random walk.

figure;
simplot(mc,X);

RV College of Engineering® 24 Enjoy Learning…


Experiential Learning Department of Mathematics

Exercise:
1. Find the fixed probability vector of the following transition matrices. Also, plot the
directed graph of the markov chain and color the edges based on the transition probability.

[ ] [ ]

Hint: Obtain the system of equations by using the definition of a fixed vector.
2. Which of the following matrices are regular?

[ ] [ ]

Hint: Use matrix multiplication

RV College of Engineering® 25 Enjoy Learning…

You might also like