Sie sind auf Seite 1von 4

CEN100 – Introduction to Engineering

MATLAB Assignment # 2: Matrix in MATLAB

Due date October 9th, 2019 at 3:00 PM through D2L

NOTE:
1. All problems should be performed in a group of two or three students.
2. The assignment will be marked out of 15
3. Method of Submission: soft copy through D2L.
4. To earn full credit, you have to submit the codes for all problems on the assignment in
one single “.m” file.
a. To do so, in MATLAB, select new script and write the commands line by line for
each exercise.
b. Your command should start by displaying your names, ID and section.
5. Save your file as A1_SECTION_#_ your student number (YS#)_your partner student
number (YPS#). (e.g.: A1_SECTION_2_500156666_500156345.m)
6. Upload the script file (A1_SECTION_#_YS#_YPS#.m) onto D2L before the due date. To
do so, go to the CEN100 course page, click on “Assessment”, then select “MATLAB # 2 -
Due October 9th” and upload the file. Only one submission per group is allowed.

Question 1

Use MATLAB’s FZERO operator to find the roots of the following functions in the given interval.
a) 6𝑐𝑜𝑠𝜃 = 𝜃/5 on [𝜋 , 2𝜋] (1 mark)
−0.01𝑥 [0 , 3]
b) 𝑒 = 7𝑥 − 2 on (1 mark)

Question 2

Use MATLAB’s ROOTS operator to solve the following polynomial functions


1
a) 𝑓(𝑥) = 2 𝑥 2 − 3𝑥 + 1 (1 mark)
b) 𝑓(𝑥) = 3𝑥 − 𝑥 3 (1 mark)

Question 3

a) Write a function file called q4.m containing the following nonlinear equations.

𝐹(𝑥1 𝑥2 ) = 𝑥12 + 𝑥22 − 26


𝐹(𝑥1 𝑥2 ) = 3𝑥12 + 25𝑥22 − 100
(1 mark)
b) Use MATLAB’s FSOLVE operator to solve these equations with x1 = 2 and x2 = 2 as your
starting point. How many iterations did MATLAB use to solve them? (1 mark)

Question 4
You have learnt how to solve a system of linear equations using elementary operations. Now, use
MATLAB operators and matrices to solve the system of linear equations below (i.e. what is x1, x2 and
x3?):
65x1 + 84x2 + 16x3 = 546
81x1 + 105x2 + 20x3 = 682
84x1 + 110x2 + 21x3 = 713

a. Create a coefficient matrix, M, which is made up of the coefficients of each variable. Each row of
the matrix should correspond to each equation and the columns should represent each variable
(1 Mark)
b. Create a constant column matrix, N, for the constants on the right side of the equations. Again,
each row should correspond to the constants of each equation.
(1 Mark)
c. Find X, the row matrix for the variables for which
(1 Mark)

𝑀 ∗ 𝑋 = 𝑁 and 𝑋 = 𝑀\𝑁

Question 5
The population (in millions) of London by decade in the 19th century is listed in the following
table.

Years Population
since 1800 (millions)
1 0.8795
11 1.040
21 1.264
31 1.516
41 1.661
51 2.000
61 2.634
71 3.272
81 3.911
91 4.422

a) Plot the given data using circles (o). (1 mark)


i. Create vector t containing the number of years after 1800 and p containing the
population of London in millions.
ii. Label the x-axis ‘# of years after 1800’ and the y-axis ‘Population of London in
millions’
iii. Title the figure ‘Population growth in London in the 19th Century’

b) Find the best-fit quadratic curve for the data (1 mark)


2
i. Define a function 𝑓𝑢𝑛 = 𝑞(1)𝑇 + 𝑞(2)𝑇 + 𝑞(3). You can use MATLAB’s
‘inline’ tool. q and T will be your input arguments.
ii. Use MATLAB’s ‘nlinfit’ tool to fit fun to the given data by calculating the best-fit
values for vector q.
E.g. 𝑞 = 𝑛𝑙𝑖𝑛𝑓𝑖𝑡(𝑡, 𝑝, 𝑓𝑢𝑛, [0 0 0]). The vector [0 0 0] is the starting point for
MATLAB to begin calculation.

c) Plot the best-fit quadratic equation on the same figure as the given data using crosses
(x). Hint – Use the command ‘hold on’
i. Create a polynomial (not a function), p_fit, similar to fun using t instead of T.
ii. Plot t vs p_fit. For your legend, call the given data ‘Population Count’ and the
quadratic equation ‘Population Fitted’. (2 marks)

d) Use MATLAB’s ‘polyder’ tool to find the coefficients for the differential of fun. You will
get a vector which you can call ‘r’. E.g. 𝑟 = 𝑝𝑜𝑙𝑦𝑑𝑒𝑟(𝑞)
i. Define a function called ‘f_diff’ using r and T. (1 mark)

e) Estimate the population of London in 1901.


NB: 𝑓(𝑎 + ℎ) = 𝑓(𝑎) + (𝑓’(𝑎) ∗ ℎ). Where f’ is the derivative of function f.

Evaluate ‘fun’ and ‘f_diff’ at a or T = 91 and h = 10 to solve for the population estimate
in 1901. (1 mark)
Note that the corresponding coefficient vectors and T will be input arguments for the
functions. E.g. 𝑓(𝑎) = 𝑓𝑢𝑛(𝑞, 𝑇) and 𝑓 ′ (𝑎) = 𝑓𝑑𝑖𝑓𝑓 (𝑟, 𝑇)
Due date October 9th, 2019 at 3:00 PM through D2L

Students Section: GA:

Student Name Student ID Signature

Evaluation

Task Full Mark Student Mark

Question 1
A 1.0
B 1.0

Question 2
A 1.0
B 1.0

Question 3
A 1.0
B 1.0

Question 4
A 1.0
B 1.0
C 1.0

Question 5
A 1.0
B 1.0
C 2.0
D 1.0
E 1.0

Total Mark 15.0

Das könnte Ihnen auch gefallen