MATLAB - Manual (Engineering Mathematics-IV)
MATLAB - Manual (Engineering Mathematics-IV)
Contents
Introduction 2
Modules
2 Complex Analysis 8
3 Statistics 10
4 Probability Distribution 16
5 Markov chain 21
Optimization terminated
x =
4.0000
5.0000
0.0000
z =
-11.0000
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:
Optimization terminated.
x =
15.0000
1.2500
z =
205.0000
Optimization terminated.
x =
2.5000
2.5000
2.5000
0.0000
z =
15.0000
( )
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
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
x =
2.5000
35.0000
z =
1.4750e+04
Exercise:
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.
4. Minimize
Subject to
2 Complex Integration
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 .
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).
3 Statistics
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)
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
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
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)
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.
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.
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:
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
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
4 Probability Distributions
Topic learning outcomes:
Student will be able to:
The binomial distribution models the total number of successes in repeated trials from an
infinite population under the following conditions:
Distribution Parameters
N — Number of trials
positive integer value
p — Probability of success
positive scalar value in the range [0,1]
Creation
'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)
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) =
r(:,:,2) =
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);
x = [0,1,2,3,4];
y = cdf(pd,x)
z = pdf(pd,x)
y = 1×5
Z = 1×5
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.
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.
mc = dtmc(P) creates the discrete-time Markov chain object mc specified by the state
transition matrix P.
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:
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.
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.
Solution
numstates = mc.NumStates
numstates = 4
figure;
graphplot(mc);
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];
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
sum(mc.P,2)
ans = 4×1
1
1
1
1
figure;
graphplot(mc);
Plot a directed graph of the Markov chain. Indicate the probability of transition by using edge
colors.
figure;
graphplot(mc,'ColorEdges',true);
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.
figure;
simplot(mc,X);
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?
[ ] [ ]