Could I have a thorough explanation of the concepts of all the parts of problems 2 and 3 especially with saving iterations and plotting??

Recitation Problems ? Week 9
440:127 ? Spring 2016 ? M. Gruteser and S. Khan
by your TA. Within 72hrs of your recitation session, you must upload the complete solutions to these problems to
Sakai, so that your TAs can evaluate them in a timely fashion. Collaborative problems can be worked on in teams
of up to 5 people, as long as each team member individually executes all steps in MATLAB, uploads the solution as
part of their own Sakai submission, and lists the names of all collaborators in the Sakai submission. Collaboration
and discussion of solutions is not permitted for questions labeled as individual problems.
Please provide your MATLAB script for every question and all its subquestions (e.g. a, b, c, ).
NEW: To receive full credit, any submitted MATLAB code must contain detailed comments that
clearly explain why and how the submitted solution works. These comments must be in your own
words, even for collaborative problems.
1. [Collaborative] It is desired to solve the equation, x ex = 1. An equivalent equation is:
x = exp(?x)

(1)

a. Solve Eq. (1) iteratively by replacing it by the following iteration, initialized at some arbitrary value, such
as, x1 = 1:
xk+1 = exp(?xk ) , k = 1, 2, 3, . . .
(2)
Implement this iteration using a forever while-loop that exits when two successive iterates become closer to
each other than some speci?ed error tolerance such as, tol = 10?10 , that is, the iteration terminates when,
|xk+1 ? xk | &lt; tol.
Determine the number of iterations N that were required for convergence. The last value x(N ) is the required
solution of Eq. (1). Save the iterates into a MATLAB array x(k) and plot it versus the iteration index k.
Make a plot like the one at the end.
b. Implement the iteration of Eq. (2) using a conventional while-loop. Verify that this method produces the
identical array x(k) as method (a).
c. Solve Eq. (1) directly by using the built-in function fzero. Using trial-and-error determine an appropriate
value for the error tolerance, tol, of part (a) such that the iterative and the fzero solutions agree in at least
12 decimal places.
d. The solution of Eq. (1) lies at the intersection of the two curves:
y=x

and y = exp(?x)

Plot both curves on the same graph over the range 0 ? x ? 2 and place the solution point on the graph.
Figures for Problem 1
iterative solution

1

graphical solution

2
x(k)
x = 0.5671432904

0.9

y=x
y=e-x

sol

x=e

0.8

-x

1.5

y

x(k)

0.7
0.6

1

0.5
0.4

0.5

0.3
0.2

0
0

10

20

30

40

0

iterations, k

0.5

1

x

1

1.5

2

2. [INDIVIDUAL] The acceleration of a car is given by the following formula that includes an acceleration term
A due to the engine torque and an air drag term that is proportional to the square of the velocity:
dv
= A ? C ? v2
dt
It is desired to measure the 0?60 mph performance of the car, as well as its braking performance from 60?0
mph. To this end, the driver ?rst applies maximum torque until the car reaches 60 mph and measures the
corresponding time, say, t60 , and then, she applies the brakes until the car stops, and measures the stopping
time, tstop .
Let us discretize the time as, tn = (n ? 1)T , where n = 1, 2, 3, . . . , and T = 0.001 sec is a small time step. Then,
the above di?erential equation may be replaced by the following di?erence equation:
v(n + 1) = v(n) + T ? [A(n) ? C ? v 2 (n)]

(3)

where v(n) is in units of mph, the drag constant is chosen as C = 0.008, and the initial acceleration and
subsequent braking action can be modeled by:
A(n) =

30 ,

if tn ? t60

?2 ,

if t60 &lt; tn ? tstop

a. Using a forever while-loop and starting with zero initial velocity, iterate equation (3) until v(n) reaches 60
mph, and determine the iteration index, say, n60 when the loop exits, and the corresponding 0?60 mph time,
t60 = (n60 ? 1)T . As you iterate equation (3) in part (a), save the computed velocity and time, v(n), t(n),
into arrays.
b. Then, continue with another forever while-loop that starts at n = n60 , and iterates until the velocity is
reduced to zero. Determine the index upon exit from the loop, say, nstop , and the total stopping time,
tstop = (nstop ? 1)T . Append the new arrays v(n), t(n) into the arrays of part (a) and make a plot exactly
as the one shown below.
80
v(t)
t60 = 4.68 sec

70

tstop = 15.06 sec

60

v (mph)

50
40
30
20
10
0
0

2

4

6

8

10

12

14

16

t (sec)

3. [Collaborative] Recall the 3D question from Recitation 8. The input ?le ?Animal.pcd? contains a point cloud,
a list of points described as 3-dimensional vectors.
a. Skip the header lines (lines with text) at the beginning of the ?le and save the x, y, z coordinates into vectors
named x, y and z.
b. Create a function with name rotation that takes x, y coordinates and an angle as input and calculates the
rotated values for that coordinates. Syntax should be like: function output = rotation(x,y,angle). You can
?nd the rotation matrix in slide 18 of Lecture 9 notes.
2

c. Translate the new coordinates into the range [0; 400] and convert to uint16.
d. Create an image as in the previous recitation.
e. Repeat with 100 di?erent angles of theta in the range [0 2pi] in equal increments to generate 100 images.
f. Combine the images into a video using the VideoWriter, im2frame, and writeVideo functions.
g. [Optional] Play your video using implay function.
4. [INDIVIDUAL] Consider the linear system:
4×1 + 2×2 + x3 = 11
? x1 + 2×2 = 3
2×1 + x2 + 4×3 = 16
Cast it in the matrix form Ax = b and solve it.

3