Appendix E — Homework: Plotting vectors and functions

Submit this homework via Dropbox. For the deadline please consult the schedule posted on Blackboard.

  • Python-scripts are submitted in one file called: homework4.py

Note

In this homework the focus is on plotting mathematical functions. You don't need to define these functions with the def keyword. Just calculate the yv values given the xv values.

E.1 Exercise 1:

Plot the following function:

\(F(K,L) = A \times K ^ \alpha L ^ {(1-\alpha)}\)

In order to plot this function set: \(A = 10, \alpha= 0.33\) and \(L=20\). Plot this function against values of \(K \in [0,10]\)

E.2 Exercise 2:

Plot the above function again into a new figure. Then change the total factor productivity \(A\) to \(20\) and plot the function again into the same graph. Repeat this for

\(A = 21\), \(A = 22\), \(A = 23\), and \(A = 24\).

Add a legend and labels for the axes as well as a title. You should have 6! functions plotted inside your figure. And you should now see how total factor productivity increases output.

E.3 Exercise 3:

Suppose that queue = ["Steve", "Russell", "Alison", "Liam"] and that this queue represents a supermarket queue with Steve first in line. Update the supermarket queue successively as follows - printing the entire queue in each round:

  1. Barry arrives
  2. Steve is served
  3. Pam talks her way to the front because she only buys one item
  4. Barry gets impatient and leaves
  5. Alison gets impatient and leaves

For the last case you should not assume that you know where in the queue Alison is standing.

E.4 Exercise 4:

Make a plot of the function \(y(t) = v_0 \times t - 0.5 \times g \times t^2\) for \(v_0 = 10, g = 9.81\), and \(t \in [0, 2v_0/g]\). The label on the x-axis should be time t and the label on the y-axis should be height m.

E.5 Exercise 5:

Plot the following functions into a single graph BUT use a subplot for each function. So your figure has 3 subplots inside. Add super title to the graph. Then for each subgraph add axes labels and a title.

  • \(f(x) = ln(x)\) for \(x>0\),
  • The derivative of \(f(x)\) that you can call \(g(x) = f'(x)\) for \(x>0\) and
  • \(h(x) = |x|\) for \(x\in[-4, 4]\).

Note

This is not a composite function! Just three separate functions. You do not need an if command for this. Just define the xv vector for the ranges given.

E.6 Exercise 6:

Plot the following composite function. You probably want to use if statements and a loop to "build" it. Plot the function in the interval from \([-3, 5]\).

\[\begin{aligned} f(x) = \begin{cases} |x| & x < 0 \\ -1 & 0 \leq x < 1 \\ +1 & 1 \leq x < 2 \\ ln(x) & 2 \leq x \end{cases} \end{aligned}\]