## Description

## Problem 1 — Tradeoffs and Regularization

A hobbyist pilot is planning her next flight. She is concerned about minimizing fuel usage so she can fly as long as possible. The flight plan includes numerous altitude changes. Each increase or decrease of 1 foot of altitude consumes 0.05 gallons of fuel. There are 100 discrete points where the pilot will need to change altitude. The desired altitudes are shown in the graph produced by the code snippet below.

Abrupt changes in altitude are risky and could potentially cause a loss of control of the aircraft, potentially inducing a stall or even resulting in structural damage. The pilot would like to find an alternative sequence of altitudes that gives her a tradeoff between matching the desired altitudes in the graph below and smoother transitions between successive altitudes. Denote the aircraft’s altitude at each discrete time byΒ u1,u2,...,u100π’1,π’2,…,π’100. We can characterize smoothness by using the sum of the squared differences between each successive altitude:

Of course, the smaller we makeΒ R(u)π (π’)Β the smoother the transitions will be. Find a set of optimal sequences of altitudes that explores the tradeoff between matching the desired seuqence given in the graph below and keeping the transitions smooth. Include a plot comparing the desired altitudes to at least 4 different smoothed versions. Use regularization weights of 0.1, 1, 10, and at least one other weight of your choice. Also plot your solutions on a Pareto curve. Either graph a curve or describe in a few words what you think the Pareto curve would look like if you filled in all the points.

Use the code provided below to generate data for your model.

```
using Random
# set a seed so we get the same output every time
seed = 787439
Random.seed!(seed)
# initialize the vector of altitudes
val = 0; u = zeros(100); u[1] = val
# set a density that determines how often the speed changes
# low density corresponds to infrequent speed changes
dens = 0.3
# build speed vector for all times between now and time 99
for i in 2:99
# if a uniform(0,1) variable is < density
if rand() < dens
# increase the altitude
val = val + 1
u[i] = val
# if a uniform(0,1) variable is >= 1 - density
elseif rand() >= 1.0-dens
# decrease the altitude
val = val - 1
u[i] = val
else# otherwise the altitude stays the same
u[i] = val
end
end
# the final altitude must be 0
u[100] = 0
T = length(u)
# plot the altitudes (your figure should match the one in the assignment!)
using PyPlot
figure(figsize=(12,4))
plot(u,"-");
```

## Problem 2 — Plotting Polynomials

While out on a hike one day, you stumble upon a mysterious looking map with 20 “x” marks scattered all over. On the back of the map is a note:

“As you hunt for the buried treasure, you should use the markings on this map as your guide. The final location you visit will require you to enter a series of numerical codes to open the treasure chest. The codes are the optimal coefficients of a polynomial function of the formΒ y=a1x3+a2x2+a3x+a4π¦=π1π₯3+π2π₯2+π3π₯+π4. How do you know you’ve found the optimal function? It will be the one that most closely fits the data shown on this treasure map!”

What values ofΒ aπΒ give the best match between your polynomial model and the given data?

You can use the following code snippet to initialize your model and view the given data points.

```
using Random
# set a seed so we get the same output every time
seed = 43539
Random.seed!(seed)
# create 200 random (x,y) pairs
x = [Random.rand(0:100) for i in 1:20]
y = [Random.rand(-120:120) for i in 1:20]
using PyPlot
plot(x,y,"x");
```