Code for Math 514A homework 4, problem 3.17