EEN-291 ENGINEERING ANALYSIS AND DESIGN
ELECTRICAL ENGINEERING DEPARTMENT
INDIAN INSTITUTE OF TECHNOLOGY, ROORKEE
Lab-3: Programming with MATLAB
Maximum marks 17.5
Note: Before solving the exercises, go through the recorded tutorials. We expect you to have
the MATLAB2019 version and above installed in your systems. A tutorial is also available in
the recorded demo. Attached the screen shot of the MATLAB screen for the exercise.
Q.1 Two functions are shown as
3
𝑓1 (𝑥, 𝑦) = (𝑥 + 𝑦)(𝑥 − 𝑦)2
4
1 2
𝑓2 (𝑥, 𝑦) = (𝑥 − 𝑦 2 )
4
(a) Create a user-defined function in the MATLAB that computes𝑓1 (𝑥, 𝑦), 𝑓2 (𝑥, 𝑦) from
the arguments 𝑥 and 𝑦. [1]
(b) Suppose 𝑥 = 𝑦 + 2. Then write a script file that uses your function to plot 𝑓1 (𝑥, 𝑦),
𝑓2 (𝑥, 𝑦) versus y for 0.5 ≤ 𝑥 ≤ 6. [2.5]
Q.2 The sampled voltage and current sensor reading at different timestamps inside the
microcontroller (using analog to digital converter) is shown below
Time (µs) Voltage (V), V(n) Current(I), I(n)
0 0 -12
10 325 0
20 325 12
30 325 12
40 0 12
50 -325 0
60 -325 -12
70 -325 -12
80 0 -12
Note: n is the number of samples
The cycle time for the sensed signals are 80µs. Then
(a) Enter the data in the spreadsheet (Microsoft excel). Then import the data in the
spreadsheet file into MATLAB. Compute RMS current (use MATLAB command),
maximum (use MATLAB command) current, minimum current (use MATLAB
command), average current (use MATLAB command) and average power over one
cycle. [2]
(b) This time use the text editor to create a file containing the above mentioned data.
Then use the load function to load the data into MATLAB. Compute RMS current
(use MATLAB command), maximum current (use MATLAB command), minimum
current (use MATLAB command), average current (use MATLAB command) and
average power over one cycle. [1]
(c) Compute the power corresponding to each sample and export the power data in the
file “Power.dat”. [0.5]
Q.3 The transfer function of the linear time invariant system is shown as
𝑠 + 5𝑝
𝐺(𝑠) =
(𝑠 + 𝑝)(𝑠 + 2𝑝)(𝑠 + 3𝑝)
Where, p is the summation of your enrolment number (for example, if your enrolment number
is 20211234 then p = 15 (2+0+2+1+1+2+3+4)
Create a "mfile” in which G(s) is defined and then find the step response (it will be a plot) of
G(s) using the MATLAB commands. [3.5]
Q.4 Write a MATLAB programme in the “mfile” for the following algorithm flow chart and
report the results along with the program. [3.5]
Start
Set i, j, k= 0
Yes
i > 30
No
k =k+1
i =i+1
k > 15 Yes
Y[j] = %
No j = j+1
Z[k] = *
End
Fig. Algorithm flow chart
Q.5 Following are the list of number of student enrolled in each year
Year No. of students
2010 210
2011 340
2012 440
2013 520
2014 640
2015 660
2016 680
2017 700
2018 740
Write a MATLAB code to fit a polynomial to the data and use the data to estimate the number
of students who will join in 2019. [3.5]