ENEL101 Problem set 6 M File Programming

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

Important Notes:
• This assignment is about writing user defined functions for applications. The questions
are based on content from chapters 8 and 9 of the textbook “Matlab, An introduction with
applications”.
• Complete this assignment by filling in the template file, assign6.m, with your Matlab
function files.
• The function files will be tested by the auto-tester using randomly generated data.
• Do NOT make any plots in your code.
Make sure your final submission runs without syntax error. As usual, template files that do
not run without syntax error will be rejected by the auto-marker, and you will have to visit Chris
in person to demo your code and get the marks.
Q1. Write a function that finds the magnitude of the roots of an input polynomial and outputs
the magnitude of the roots that fall within a user specified range of values LOW and HIGH. The
input polynomial � is entered as a row vector of coefficients as shown in the example on pp.262-
3 of the textbook.
The polynomial � = −0.001�) + 0.051�, − 0.76�/ + 3.8� − 1.4 is entered as � =
[−0.001, 0.051, −0.76, 3.8, −1.4]. The magnitude of the roots are:
29.6177, 10.8776, 10.8776, 0.3995. Now suppose the range is given as say LOW=9 and
HIGH=11, then the second and third roots [10.8776, 10.8776] will be output.
ENEL101 Assignment 6 Page 2
Q2. Write a function that accepts the vector of data points � and ℎ as input arguments and
determines a linear equation in the form of � = �ℎ + � that best fits the data. Then output the
magnitude of the error between the data points and the linear regression curve, denoted by the
vector of �. Use the Matlab polyfit() and polyval() functions. The input arguments are
the boiling temperature of water � at various altitudes ℎ as in
� (meters) 0 608 1520 2280 3040 6384 7904
� (Celsius) 100.00 98.88 95.00 92.22 90.00 81.11 75.55
Q3. Write a function that accepts the vector of data points � and � as input arguments and
determines the best exponential equation in the form of � = ��BC that best fits the data, using
the Matlab polyfit() function. Then output 1×2 vector � � . The input arguments are the
number of bacteria � measured at different times � as
� (min) 10 20 30 40 50
� 38,000 60,000 250,000 500,000 1000,000
Q4. Write a function named that accepts the integration limits of � and � as input arguments
and outputs the integral of ( ) 2 3 hx x x x ( ) sin( )exp = – . Use the Matlab quad() function for this.
That is the function does the following
( ) 2 3 sin( ) exp
B
A
Z x x x dx = – ò
Q5. The following wind tunnel data shows the aerodynamic drag force on a car, �I, as a
function of the car velocity, �.
v km hr ( /) 20 40 60 80 100 120 140 160
F N D ( ) 10 50 109 180 300 420 565 771
Write a function that accepts an arbitrary value for v and output the corresponding interpolated
value of FD . Use Matlab function interp1() with the ‘spline’ method for the interpolation.
ENEL101 Assignment 6 Page 3
Q6. An RLC circuit with an alternating voltage source is assumed. The source voltage �K is
given by �K = �Bsin (�Q�), where �Q = 2��Q in which �Q is the driving frequency. The
normalized amplitude of the current, �, in this circuit is given by
� = 1
�/ + �Q� − 1
�Q�
/
where � (Ω), � (H), and � (F) are the resistance of the resistor, the capacitance of the capacitor,
and the inductance of the inductor, respectively. Write a function named that accepts �, �, and �
as input arguments and finds the natural frequency of the circuit (the frequency at which � is
maximum). The natural frequency of �Z (Hz) is the output argument. Use Matlab’s
fminbnd() for this application and search over 0.5/ �� < �Q < 1.5/ ��. Note that
minimizing −� is equivalent to maximizing �.
Q7. The sudden outbreak of an insect population can be modelled by the equation
� �
� � = �� 1 − �
� − � �/
�_
/ + �/
where � is the number of insects, � is an intrinsic growth rate, and � is the carrying capacity of
the local environment. The first term is a population growth model and the second term
represents the effects of bird predation, which becomes significant when the population reaches a
critical size �_ and has a maximum value of �. Solve for �at time � = 50 days for � = 0.55 per
day, � 0 = 1000, � = 10), �_ = 10), and � = 10) per day. Use ode45(). Note: you must
make your anonymous function a function of both � and � even though � doesn’t appear
explicitly in the differential equation.