$\newcommand{\eps}{\varepsilon} \newcommand{\kron}{\otimes} \DeclareMathOperator{\diag}{diag} \DeclareMathOperator{\trace}{trace} \DeclareMathOperator{\rank}{rank} \DeclareMathOperator*{\minimize}{minimize} \DeclareMathOperator*{\maximize}{maximize} \DeclareMathOperator{\subjectto}{subject to} \newcommand{\mat}[1]{\boldsymbol{#1}} \renewcommand{\vec}[1]{\boldsymbol{\mathrm{#1}}} \newcommand{\vecalt}[1]{\boldsymbol{#1}} \newcommand{\conj}[1]{\overline{#1}} \newcommand{\normof}[1]{\|#1\|} \newcommand{\onormof}[2]{\|#1\|_{#2}} \newcommand{\MIN}[2]{\begin{array}{ll} \minimize_{#1} & {#2} \end{array}} \newcommand{\MINone}[3]{\begin{array}{ll} \minimize_{#1} & {#2} \\ \subjectto & {#3} \end{array}} \newcommand{\MINthree}[5]{\begin{array}{ll} \minimize_{#1} & {#2} \\ \subjectto & {#3} \\ & {#4} \\ & {#5} \end{array}} \newcommand{\MAX}[2]{\begin{array}{ll} \maximize_{#1} & {#2} \end{array}} \newcommand{\MAXone}[3]{\begin{array}{ll} \maximize_{#1} & {#2} \\ \subjectto & {#3} \end{array}} \newcommand{\itr}[2]{#1^{(#2)}} \newcommand{\itn}[1]{^{(#1)}} \newcommand{\prob}{\mathbb{P}} \newcommand{\probof}[1]{\prob\left\{ #1 \right\}} \newcommand{\pmat}[1]{\begin{pmatrix} #1 \end{pmatrix}} \newcommand{\bmat}[1]{\begin{bmatrix} #1 \end{bmatrix}} \newcommand{\spmat}[1]{\left(\begin{smallmatrix} #1 \end{smallmatrix}\right)} \newcommand{\sbmat}[1]{\left[\begin{smallmatrix} #1 \end{smallmatrix}\right]} \newcommand{\RR}{\mathbb{R}} \newcommand{\CC}{\mathbb{C}} \newcommand{\eye}{\mat{I}} \newcommand{\mA}{\mat{A}} \newcommand{\mB}{\mat{B}} \newcommand{\mC}{\mat{C}} \newcommand{\mD}{\mat{D}} \newcommand{\mE}{\mat{E}} \newcommand{\mF}{\mat{F}} \newcommand{\mG}{\mat{G}} \newcommand{\mH}{\mat{H}} \newcommand{\mI}{\mat{I}} \newcommand{\mJ}{\mat{J}} \newcommand{\mK}{\mat{K}} \newcommand{\mL}{\mat{L}} \newcommand{\mM}{\mat{M}} \newcommand{\mN}{\mat{N}} \newcommand{\mO}{\mat{O}} \newcommand{\mP}{\mat{P}} \newcommand{\mQ}{\mat{Q}} \newcommand{\mR}{\mat{R}} \newcommand{\mS}{\mat{S}} \newcommand{\mT}{\mat{T}} \newcommand{\mU}{\mat{U}} \newcommand{\mV}{\mat{V}} \newcommand{\mW}{\mat{W}} \newcommand{\mX}{\mat{X}} \newcommand{\mY}{\mat{Y}} \newcommand{\mZ}{\mat{Z}} \newcommand{\mLambda}{\mat{\Lambda}} \newcommand{\mPbar}{\bar{\mP}} \newcommand{\ones}{\vec{e}} \newcommand{\va}{\vec{a}} \newcommand{\vb}{\vec{b}} \newcommand{\vc}{\vec{c}} \newcommand{\vd}{\vec{d}} \newcommand{\ve}{\vec{e}} \newcommand{\vf}{\vec{f}} \newcommand{\vg}{\vec{g}} \newcommand{\vh}{\vec{h}} \newcommand{\vi}{\vec{i}} \newcommand{\vj}{\vec{j}} \newcommand{\vk}{\vec{k}} \newcommand{\vl}{\vec{l}} \newcommand{\vm}{\vec{l}} \newcommand{\vn}{\vec{n}} \newcommand{\vo}{\vec{o}} \newcommand{\vp}{\vec{p}} \newcommand{\vq}{\vec{q}} \newcommand{\vr}{\vec{r}} \newcommand{\vs}{\vec{s}} \newcommand{\vt}{\vec{t}} \newcommand{\vu}{\vec{u}} \newcommand{\vv}{\vec{v}} \newcommand{\vw}{\vec{w}} \newcommand{\vx}{\vec{x}} \newcommand{\vy}{\vec{y}} \newcommand{\vz}{\vec{z}} \newcommand{\vpi}{\vecalt{\pi}} \newcommand{\vlambda}{\vecalt{\lambda}}$

# Homework 1

Please answer the following questions in complete sentences in submit the solution on Blackboard Sept. 2nd, 2016.

# Homework 1

## Problem 1: G & C, Chapter 1, Problem 2 (10 points)

Please complete parts (a) and (b) of G & C, Chapter 1, Problem 2

## Problem 2: A simple economy (10 points)

(From Matries with Applications (Hugh G. Campbell))

Suppose we construct a simple model economy in which there are three industries -- the crude oil industry, the refining industry that produces gasoline, and the utility industry which supplies electricity. Then suppose there are six types of consumers -- the general public, the government, the export firms, and the three industries. Both the industries and the consumers exercise certain consumptive demands on each of the industries. For instance, suppose that the crude oil industry needs to use 4 units of gasoline and 2 units of electricity. The demand vector, then for the crude oil industry, is expressed as Likewise, we specify the other demand vectors. In each case we list the goods demanded in the form: The demand vectors are:

1. Write a mathematical expression for the total demands on all three industries in terms of the demand vectors $\alpha$ and evaluate the total demands.

2. Now suppose that the price of crude oil is 4-dollars per unit, the price of gasoline is 3-dollars per unit, and the price of electricity is 2-dollars per unit. We can express this with the vector $\beta = (4, 3, 2)$. Assuming that the industries produce exactly what is demanded of them determine the profit of the crude oil industry.

## Problem 3: Adding acceleration to the raptor problem (15 points)

In our in-class model for the xkcd raptor problem, we ignored the impact of acceleration. Wired did a long post about acceleration of sprinters. See the url

http://www.wired.com/wiredscience/2012/08/maximum-acceleration-in-the-100-m-dash/

1. (10 points) Using information from this post, construct a mathematical model of the position of sprinter on a line. Document and justify your assumptions

2. Determine difference in the distance traveled by the "idealized" sprinter that immediately begins running at 12 meters-per-second to the "real" sprinter that must accelerate to 12 meters-per-second after six second.

## Problem 4: Search engines (15 points)

1. Write down the matrix for G&C, Chapter 1, Problem 5. You do not have to evalute the similarity

2. Write down the adjacency matrix for the graph in Figure 1.12

3. Evaluate the probability in G&C, Chapter 1, Problem 6a.

## Problem 5: Intro to Julia (15 points)

For this problem, we'll use Julia instead of Matlab.

1. Please complete all parts of G & C, Chapter 2, Problem 2
2. Please complete all parts of G & C, Chapter 2, Problem 3
3. Please complete all parts of G & C, Chapter 2, Problem 7 The hint for Julia would be

Updates based on plotly() errors (And also one correction! Note that the coordinates typed from the book were wrong. The new coordinates are included in the update.)

Original code (This no longer works for me :( )

using Plots
plotly(size=(500,500)) # use plotly for zooming and 500-by-500 for equal size
theta = linspace(0, 2*pi, 10000)
r = sqrt(2)
x = 2. + r*cos(theta)
y = 2. + r*sin(theta)
plot(x,y)


PlotlyJS code (This one works for me, but others have had issues with it.)

Pkg.add("PlotlyJS")
using Plots
plotlyjs(size=(500,500))
theta = linspace(0, 2*pi, 10000)
r = sqrt(2)
x = 2. + r*cos(theta)
y = 1. + r*sin(theta)
plot(x,y)


PlotlyJS code (This one works for me, but others have had issues with it.)

using Plots
pyplot(size=(500,500)) # this won't give you interactivity unless you are running from the command line
theta = linspace(0, 2*pi, 10000)
r = sqrt(2)
x = 2. + r*cos(theta)
y = 1. + r*sin(theta)
plot(x,y)


## Problem 6: Drawing the Julia set (25 points)

In this set of steps, you will write a Julia program to evaluate and draw the mandelbrot set.

1. The Julia set is a fractal. https://en.wikipedia.org/wiki/Julia_set#/media/File:Julia_set_(ice).png Read about the Julia set, either in the textbook or on Wikipedia, or in another reference and answer the following question. The best description I found was here

http://paulbourke.net/fractals/juliaset/

from Wikipedia. Describe how the $(x,y)$ coordinate of this pixel relates to the function $\phi(z) = z^2 + c$.

2. A key step in building the julia set fractal is checking when the sequence
remains bounded. Implement the following Julia function

"""
julia_check is a subroutine useful for working with the Julia
set fract. The function
returns the number of steps that we can iterate the sequence
z = zinput (from input)
znext = z*z + c
until the maginitude of the value z becomes larger than two or
until we hit 256 steps.
"""
function julia_check(z,c)
# fill this part in
end


and report the values of

julia_check(-1, 0.5+0.5im)
julia_check(0, 0.5+0.5im)
julia_check(-1, 0.5+0.25im)
julia_check(0, 0.5+0.25im)

3. We are now going to look at images of the complex plane spanned by $Re(z) = [-1.75,1.75]$ and $Im(z) = [-1.75,1.75]$. (This is the region where the julia fractal is usually drawn.) Suppose we have pixels representing 20 equally spaced points on the real axis and pixels representing 20 equally spaced points on the imaginary axis, fill in the following code

nxpts =
nypts =
Z = zeros(nypts, nxpts)
for jj=1:nypts
for ii=1:nxpts
Z(jj,ii) =
end
end


such that Z(jj,ii) = the magnitude of the point represented by $(j,i)$ in the complex plane. Show the result using the command

grayim(Z/maximum(Z))


Hint To include the output in your homework, note that you can save an image using

using FileIO
using ImageMagick
save("juliaset.png", Z/maximum(Z))


and then looking for the file juliaset in the juliabox file browser.

4. Now update your code and let the value of Z(jj,ii) be the number of iterations taken by the mandelbrot iteration to escape when that point is input to your julia_check function with $c = 0.5 + 0.5i$

5. Improve the resolution of your mandelbrot picture as much as you can. (For full credit, you'll need to use at least 1,000,000 pixels (1000-by-1000).)

6. Change the value of $c$ to $0.3$ and show your new picture.

7. Which one do you like better?

## Problem 7: Fun with Julia (5 points)

Describe what you see or hear after the following commands.

1. Type the command 1:100 |> sum, what does this do?
2. Type the command ?hi
3. Type the command "2 plus 2 is \$(2+2)."