You are on page 1of 46

Solved by – Mohammad Abdul Hasib

Answer to the Question No. 1


a)

b)
Answer to the Question No. 2
Answer to the Question No. 3
Answer to the Question No. 4

a)
b)

a)
b)
Answer to the question No. 6

a)

b)
c)
Final exam of Computational Methods and Modeling for Engineering Applications (GENG-8030)
Instructor: Dr. Mohammad Sedigh Toulabi
19th of April 2021
12:00 PM to 2:30 PM

Question 1 (6 marks):
3 companies A, B and C, manufactures TV, Stereos and CD players. Company A sells 5 TVs, 3
Stereos and 1 CD players and earns total $1350. Company B sells 3 TVs, 5 Stereos and 2 CD
players and earns $1100. Company C sells 4 TVs, 4 Stereos and 5 CD players and earns total
$1600.
a) If all three companies are selling TVs, Stereos and CD players at same costs. Find the costs
of TV, Stereos and CD player respectively by the left division method.
b) Imagine only companies A and C are operational, then find the prices of individual
products by pseudo-inverse method.
c) Calculate and report the difference in the costs of individual products found in case a) and
case b).
Question 2 (8 marks):
Object A is moving toward west at the speed of 120 km/h and object B is moving toward east at
the speed of 40 km/h. The original locations of both objects are shown as follows.

a) By building a function(s), obtain an expression for the distance between the objects as a
function of time and plot the absolute distance between them versus time in the first eight
hours. Use the appropriate labels for the axes during the plotting.
b) Using fzero, estimate the first time when the distance between the objects is 50 km.
Question 3 (8 marks):
Considering the table shown below, write a script file using conditional statements (If and elseif
functions) to evaluate if the body temperature of an object is in a safe condition or not. For
example, if the input temperature value is 99.0, the displayed information of the code should be
“Temperature normal”. Show the code’s output for the temperature of 99.0.
Temperature Condition
Less than 97.5 Temperature below normal
97.5 – 99.5 Temperature normal
99.5 – 103.0 Temperature slightly high
Larger than 103.0 Temperature dangerously high
1
Question 4 (8 marks):
The profit information of a company for the last 10 years has been reported in the table below.
Year 2011 2012 2013 2014 2015
Profit 42300 59600 72400 115900 162900
Year 2016 2017 2018 2019 2020
Profit 235400 297600 433200 652800 829800
a) Fit a second-degree polynomial to the data set and estimate the expected profit for 2021.
b) Plot the curve fitting graph and data set in a same figure window. Use the appropriate
legends and labels for axes.

Question 5 (10 marks):


For the following differential equations:
𝑥̇ 1 = 𝑥2
𝑥̇ 2 = 𝑥3
𝑡
𝑥̇ 3 = 5.4𝑡 + 𝑥1 − 4𝑥2 − 0.6𝑥3
2
𝑦 = 8𝑥1 − 𝑥2 + 9
where, 𝑥3 (0) = 0.5, 𝑥2 (0) = 4.2, 𝑥1 (0) = −5.4, 0 ≤ 𝑡 ≤ 5
Using “subplot” command to generate a 2 row-1 column figure format,
a) Show the required code to solve the differential equations using the “ode45” solver and
show the output plot of 𝑥2̈ ,𝑥2̇ and 𝑥2 in a same figure window with appropriate legends
and labels for axes.
b) Show the plot of y with appropriate lagend and labels for axes.

2
Question 1:

CODE:

A=[5,3,1;3,5,2;4,4,5];

B=[1350;1100;1600];

%Cost for each individual product using Left division

disp("Costs of each individual product with left division in place")

X=A\B;

disp(X);

%If comapny B is not operational and the cost by Pinverse method

C=[5,3,1;4,4,5];

D=[1350;1600];

disp("Costs of each individual product using pinverse method")

Y=pinv(C)*D;

disp(Y);

%finding the dfference in costs with left divisona and pinverse method

disp("Cost difference of each individual product")

K=abs(X-Y);

disp(K);
OUTPUT:
Question 2:

function [deltaD] = question2_a(t)

deltaD= abs(400-((120+40)*t));

end

function [deltaD] = distance_Q2_B(t)


%shifting teh plot by 50

deltaD= abs(400-((120+40)*t))-50;

end

Question:3

CODE:

temp=input('enter the value of temperature: ');

if temp < 97.5

disp('Temperature below normal')

elseif temp > 97.5 && temp < 99.5

disp('Temperature normal')

elseif temp > 99.5 && temp < 103.0

disp(' Temperature slightly high')

elseif temp > 103.0

disp('Temperature dangerously high')

end
OUTPUT:

Question 4:

years=[2011 2012 2013 2014 2015 2016 2017 2018 2019 2020];

profit=[423 596 724 1159 1629 2354 2976 4332 6528 8298];

x=years-2011;

y=profit*100;
coeff=polyfit(x,y,2);

answer=polyval(coeff,10);

plot(x,y,x,polyval(coeff,x),x,y,'o',x,polyval(coeff,x),'*'),legend('Actual Data','Curve Fitting


Graph'),title('Profit for next 10 years'),xlabel('Year'),ylabel('Estimated Profit');

disp('The Estimated Profit in 2021 was:');

disp(answer);

Output:
Question 5:

function xdot=question5(t,x)

xdot(1)=x(2);

xdot(2)=x(3);

xdot(3)=(5.4*t)+((t/2)*x(1))-4*x(2)-0.6*(x(3));

xdot=[xdot(1);xdot(2);xdot(3)];

end
OUTPUT:
Solved by - Mohammad Abdul Hasib

Answer to the Question No. 1

a)
b)

c)
d) For intersecting point,
𝑓1 (𝑥) = 𝑓2 (𝑥)
or, −𝑥 2 + 10𝑥 = 2𝑥 2 − 8𝑥 + 3
or, 3𝑥 2 − 18𝑥 + 3 = 0
Answer to the Question No. 2

a)

b)

c)
Answer to the Question No. 3
a)
b)
c)
The response is not under control.

d)
Answer to the Question No. 4
a)

b)
5𝑦̈ = sin(𝑡) + 𝑡𝑒 −4𝑡 − 5𝑡 − 2.4𝑦
1
or, 𝑦̈ = (sin(𝑡) + 𝑡𝑒 −4𝑡 − 5𝑡 − 2.4𝑦)
5
c)
Answer to the Question No. 5
1)
𝑥 = 3.5𝑦 − 1.7
By substituting 𝑥 to 𝑥 2 = 6.2𝑦 this equation we get,
(3.5𝑦 − 1.7)2 = 6.2𝑦
or, 3.52 𝑦 2 − 2 ∗ 3.5𝑦 ∗ 1.7 + 1.72 = 6.2𝑦
or, 3.52 𝑦 2 − (2 ∗ 3.5 ∗ 1.7 + 6.2)𝑦 + 1.72 = 0

2)
3)

By observing the graph we get, A(-1.0626,0.1821) and B(2.8340,1.2954).

4)

5)
Final exam of Computational Methods and Modeling for Engineering Applications (GENG-8030)
Instructor: Dr. Mohammad Sedigh Toulabi
19th of April 2021
3:30 PM to 6:00 PM

Question 1 (6 marks):
The below table shows the falling trend of Bit Error Rate (BER) with increase in Signal to Noise
Ratio (SNR) for four various modulation schemes, i.e., BPSK, QPSK, 8 QAM and 16 QAM.
SNR: 1 2 3 4 5
BPSK 0.0190 0.0100 0.0046 0.0020 0.0008
QPSK 0.1316 0.0941 0.0630 0.0384 0.0202
(BER)
8 QAM 0.0377 0.0202 0.0096 0.0041 0.0016
16 QAM 0.0478 0.0252 0.0119 0.0049 0.0018
Write a MATLAB script to generate the exact replica of the following plots using the given table.
BIT ERROR PERFORMANCE
10 0
BPSK
QPSK
8QAM
16QAM

-1
10
BER

10 -2

-3
10

10 -4
1 1.5 2 2.5 3 3.5 4 4.5 5
SNR

And

BPSK QPSK
10 -1 10 0

-2
10
BER

-1
10
-3
10

-4 -2
10 10
1 2 3 4 5 1 2 3 4 5
SNR SNR

-1
8 QAM -1
16 QAM
10 10
BER

10 -2 10 -2

10 -3 10 -3
1 2 3 4 5 1 2 3 4 5
SNR SNR

1
Question 2 (8 marks):
Use MATLAB to create Matrix A as follows,
… √1000
𝐴 = (√2 √4 )
1 √3 … √999
Write a code to:
a) Find the average value of the elements in an array once each element of that array is made
by the corresponding product of the 1st row and 2nd row of Matrix A. (Hint: the length of
array is 500).
b) Extract all the elements in the 258th through 264th columns of Matrix A.
c) Extract all the elements in 2nd row and 120th through 125th columns of Matrix A.
d) Create a diagonal matrix of the elements of 1st row of Matrix A, i.e.,
√2 0 0 0
D = 0 √4 0 0
0 0 ⋱ 0
[0 0 0 √1000]
Question 3 (8 marks):
If x = [25; 9; 21; 7; 2; 43; 28; 47; 35; 29], use MATLAB to calculate the value of 𝑟𝑖 based on the
following formula and take the sum of 𝑟𝑖 , where 𝑥̅ is the average of the elements of x.
∑10
𝑖=1(𝑥𝑖 − 𝑥̅ )
𝑟𝑖 = , 𝑖 = 1,2, … ,10;
√∑10
𝑖=1(𝑥𝑖 + 𝑥̅ )
2

Question 4 (8 marks):
For the following differential equation:
6𝑦̈ − 3.6𝑦 = tcos 𝑡 + 𝑒 −3𝑡 + 1.5𝑡 0≤𝑡≤6
where 𝑦̇ (0) = 4.2, 𝑦(0) = −6
It is required to:
a) Show the Simulink model structure to plot the solution of the above differential equation
and show the output plots of 𝑦̈ , 𝑦̇ , 𝑎𝑛𝑑 𝑦 on the same scope (The scope consists of 3 rows
and 1 column).
b) Show the required code to solve the differential equations using the “ode45” solver, and
show the output plots of 𝑦̇ and 𝑦. Note: use suitable legends (i.e., ydot and y).
c) Plot the solution of the equation (𝑦) that is determined from a) and b) on the same figure
(The figure consists of two columns and 1 row, where the Simulink figure will be plotted
on the right). Please show the code used and the output figure with suitable titles (i.e., code
results and Simulink results).
2
Question 5 (10 marks):
The gain (G(s)) of a dynamic vehicle longitudinal model is given in the form of a transfer function
as follows,
𝑉(𝑠) 2.4767
𝐺(𝑠) = =
𝑈(𝑠) (𝑠 + 0.0476)(𝑠 + 5)(𝑠 + 1)
where, 𝑉(𝑠) 𝑎𝑛𝑑 𝑈(𝑠) represent output and input of the vehicle model, respectively.
It is required to:
a) Simplify the transfer function and plot the output open loop response (V) and input (U) of
the dynamic vehicle model on a same scope (the scope has only one port) when a step input
(U) with step time = 1s and amplitude = 1 is applied for 0 ≤ 𝑡 ≤ 100.
b) Now similarly plot the output closed-loop response (V) and input (U) of the vehicle
dynamic model in a negative feedback scenario on a same scope.
c) Add a PID controller to the closed-loop system to enhance the output response (V) and
force it to follow the defined step input (U). The PID controller parameters, i.e., Kp, Ki and
Kd, are obtained by two methods namely, Ziegler Nichols method and genetic algorithm
method. The values are given in the table below.
Method Kp Ki Kd
Ziegler Nichols 7.65 5.54 2.64
Genetic algorithm 3.5907 0.163 3.3021
Show the output response and input signals using both methods.

3
Question 1

CODE

SNR=1:5;

BPSK=[0.0190,0.0100,0.0046,0.0020,0.0008];

QPSK=[0.1316,0.0941,0.0630,0.0384,0.0202];

EIGHT_QAM=[0.0377,0.0202,0.0096,0.0041,0.0016];

SIXTEEN_QAM=[0.0478,0.0252,0.0119,0.0049,0.0018];

semilogy(SNR,BPSK,'b-O', SNR,QPSK,'r-^', SNR,EIGHT_QAM,'m-s', SNR,SIXTEEN_QAM,'k-d'),


legend('BPSK','QPSK','8QAM','16QAM'), title('BIT ERROR PERFOMANCE'), xlabel('SNR'), ylabel('BER'),
axis([1 5 10^-4 1])

BIT ERROR PERFOMANCE


10 0
BPSK
QPSK
8QAM
16QAM
10 -1
BER

10 -2

10 -3

10 -4
1 1.5 2 2.5 3 3.5 4 4.5 5
SNR

subplot(2,2,1)

semilogy(SNR,BPSK,'-O');axis([1 5 10^-4 10^-1]), xlabel('SNR'),ylabel('BER');title('BPSK');

subplot(2,2,2)

semilogy(SNR,QPSK,'r-^');axis([1 5 10^-2 1]), xlabel('SNR'),ylabel('BER');title('QPSK');


subplot(2,2,3)

semilogy(SNR,EIGHT_QAM,'m-s');axis([1 5 10^-3 10^-1]), xlabel('SNR'),ylabel('BER');title('8 QAM');

subplot(2,2,4)

semilogy(SNR,SIXTEEN_QAM,'k-d'); axis([1 5 10^-3 10^-1]), xlabel('SNR'),ylabel('BER');title('16 QAM');

BPSK QPSK
10 0 10 0
BER

BER
10 -2 10 -1

10 -4 10 -2
1 2 3 4 5 1 2 3 4 5
SNR SNR
8 QAM 16 QAM
10 -1 10 -1
BER

BER

10 -2 10 -2

10 -3 10 -3
1 2 3 4 5 1 2 3 4 5
SNR SNR

Question 2

for r=1:2

for c=1:500

a(r,c)=sqrt((2-r+1)+2*(c-1));

end

end

a
a)

for c=1:500

b(c)=a(1,c)*a(2,c);

end

b;

mean(b)

500.4991

b)

a(:,258:264)

22.7156 22.7596 22.8035 22.8473 22.8910 22.9347 22.9783

22.6936 22.7376 22.7816 22.8254 22.8692 22.9129 22.9565

c)

a(2,120:125)

15.4596 15.5242 15.5885 15.6525 15.7162 15.7797

d)

for c=1:500

d(c,c)=a(1,c);

end

d;

Question 3

x=[25;9;21;7;2;43;28;47;35;29];

xmean=mean(x)

num=0;den=0;

for i=1:10

num=num+(x(i)-xmean);

den=den+(x(i)+xmean)^2;

r(i)=num/sqrt(den);

end
r

rtotal=sum(r)

Answers

xmean = 24.6000

r = 0.0081 -0.2537 -0.2497 -0.4458 -0.6870 -0.3715 -0.3067 -0.1051 -0.0288 -0.0000

rtotal = -2.4402

Question 4

a)

function y=fcn(u)

Y=1/6*(u.*cos(u)+exp(-3*u)+1.5*u;

end

b)
function ydot=func(t,y)

ydot(1)=y(2);

ydot(2)= 1/6*(t.*cos(t)+exp(-3*t)+1.5*t+3.6*y(1));

ydot=[ydot(1);ydot(2)];
end

[t,y]=ode45(@func,[0,6],[-6,4.2]);
plot(t,y),xlabel('t'),ylabel('y'),legend('y','ydot')

c)

[t,y]=ode45(@func,[0,6],[-6,4.2]);

>> subplot(1,2,1);

>> plot(t,y),xlabel('t'),ylabel('y'),legend('y','ydot')

>> subplot(1,2,2);

>> plot(out.integ.time,out.integ.signals.values)
Question 5

You might also like