Julia Programming Language for Scientific Computing University of Konstanz, SS 2015 EXERCISE SHEET 3 Read the Julia Language Documentation, Sections 1.7 to 1.8: Strings and Functions until Monday, April 27, and Sections 1.9 to 1.10: Control Flow and Scope of Variables until Thursday, April 30. Solve the following exercises by filling in the details (JULIA code only). Submit by email to dietmar.saupe@uni-konstanz.de by Thursday, April 30, 12 noon. These exercises were suggested by Thomas Sargent, John Stachurski. However, find your own solutions! Exercise 1 Part 1: Given two numeric arrays or tuples x_vals and y_vals of equal length, compute their inner product using zip() Part 2: Using a comprehension, count the number of even numbers in 0,...,99 Hint: x % 2 returns 0 if x is even, 1 otherwise Part 3: Using a comprehension, take pairs = ((2, 5), (4, 2), (9, 8), (12, 10)) and count the number of pairs (a, b) such that both a and b are even Exercise 2 Consider the polynomial (1) p(x)=a0+a1*x+a2*x2+⋯+an*xn Using enumerate() in your loop, write a function p such that p(x, coeff) computes the value in (1) given a point x and an array of coefficients coeff Exercise 3 Write a function that takes a string as an argument and returns the number of capital letters in the string Hint: uppercase("foo") returns "FOO" Exercise 4 The Julia libraries include functions for interpolation and approximation. Nevertheless, let’s write our own function approximation routine as an exercise. In particular, write a function linapprox that takes as arguments A function f mapping some interval [a,b] into ℝ two scalars a and b providing the limits of this interval An integer n determining the number of grid points A number x satisfying a <= x <= b and returns the piecewise linear interpolation of f at x, based on n evenly spaced grid points a = point[1] < point[2] < ... < point[n] = b Aim for clarity, not efficiency Exercise 5 The following data lists US cities and their populations new york: 8244910 los angeles: 3819702 chicago: 2707120 houston: 2145146 philadelphia: 1536471 phoenix: 1469471 san antonio: 1359758 san diego: 1326179 dallas: 1223229 Copy this text into a text file called us_cities.txt and save it in your present working directory. That is, save it in the location Julia returns when you call pwd(). Write a program to calculate total population across these cities. Hints: If f is a file object then eachline(f) provides an iterable that steps you through the lines in the file. int("100") converts the string "100" into an integer.