2. Course Goals and Themes:   Homework

Author: YourNameGoesHere

Last revision:  January 13 1998

Keep in mind that although you may have Mathematica input cells which derive the answer to a given question, it is always better to follow your Mathematica code with a text cell explaining your answer in complete sentences.  Not only is it better, but it will earn your more credit!

When you are finished, make sure that your instructor has a copy of your completed work.  Save a copy under a file name identifying both the assignment and the author (you) (e.g., HW02-MyName.nb).  Drag a copy of this file to your instructor's drop box on the network.

Solving Equations

1. Determine the intersection points of "x^4+x^3-x^2" and "Sin[x]+Cos[x]".

2. Use "?Solve" or the Help facility to learn about the Mathematica function "Solve[]", and then find the solutions to
     x^2 + y^2 = 8
     (x - 4)^2 + (y + 1)^2 = 4
for x and y.  Hint:  the equations should be in one list, and the variables in another.  Remember to use double equals signs!

Tradeoffs

3. We have a function "f" into which we can only input a positive integer.  Suppose that we have one method for computing the values which takes 10 seconds each time we execute the method.  Suppose also that we have another method which takes 5 seconds if the input value is odd, and 20 seconds if the input value is even.  Which method would you use, and why?  Under what conditions would each method perform better?

4. Two students present programs to an instructor.  Both programs appear solve the problem as stated.  The first program is difficult to read, with few comments and an algorithm which it is hard to confirm would work for all input values; however, the program executes in 1 second.  The second is well documented yet uses a terribly slow algorithm and executes in 20 seconds; however, it is easily shown that the algorithm works in all cases.  Which program is better?

5.  We have a function "f" into which we can input any integer.  The function should return a 0 if the input value is 369; otherwise it should return a 1.  Two programs are submitted to an instructor which purport to solve the problem, but this time the instructor cannot check the algorithms or the source code.  The first program executes in 1 second every time, while the second program executes in 2 seconds every time.  The instructor attempts to check correctness by running each program with the input values 0, 1, 2, ..., 200, and both programs work.  How should the instructor grade the assignment?  What issues about correctness and evaluation appear in this situation?

6. Seven cities are connected by a series of toll roads, as shown below.  The price of the toll appears on the road.  Suppose we want to write a function "bestRoute[i,j]" which will  tell us the cheapest route to get from city "i" to city "j". The user first asks for the cheapest route from city 1 to city 2, and after a good deal of computation our function returns the correct route "1->5->6->2". Discuss the possible benefits of storing this result based on the assumption that the user might next request "bestRoute[5,2]".