# Assignment 2

Due on October 15 at 11:59pm electronically via email.

## How to submit the assignment

Use a word-processor like Microsoft Word or LibreOffice (free), or $$\LaTeX$$ (also free) to create a single PDF file with all of your answers. If you want to include code, do not put them in this file. This file should include your graphs, equations, tables, and explanations. The name of this file should have the following format: LASTNAME_STUDENTNUMBER_A2.pdf. You can hand-write your answers, but you will have to scan your papers, or take a picture of them. In any case, send me one PDF file. I will not accept paper submissions.

If you want to include multiple code files (.m or .py files), put them all in one folder, zip the folder, and send me only one zip file. The name of this file should look like this: LASTNAME_STUDENTNUMBER_A2.zip

Attach both files to an email and send it to msamani[at]fields.utoronto.ca. Make sure the title of the email starts with MATH3090.

Question 1: Let $$f(x) = -\cos(x) - x^3$$

1. Plot the function between $$x=-2$$ and $$x=+2$$. Plot the line of $$y=0$$ on the same graph. Also plot the point you will find in part b on your graph as a red circle.
2. Use the bisection method to find the root. Use $$a=-2$$ and $$b=+2$$ as your initial interval. Do not use fzero in MATLAB or anything from scipy.optimize in Python. Write your own code. How many steps did it take the bisection method to converge? Report the last two results in the loop. The relative difference between them should be of the same order of magnitude as eps. Hint: Use format long; in MATLAB to display all the digits that are stored in a 64-bit floating point variable.
3. Use Newton's method to find the root of the function. Use $$x_0 = -1$$. How many steps does it take for the method to converge?
4. Could you use $$x=0$$ as your starting point? If no, why not?
5. Use the Secant method to find the root of the function. For your starting points use $$x=-1$$ and $$x=0$$. How many steps does it take the Secand method to converge?
6. How did you decide when to stop the loop for each method? Why do you think you could not find a more accurate answer with the exit strategy that you chose?

Question 2: You can solve a system of non-linear equations in multiple variables $$\begin{cases}f_1(x_1, x_2, ..., x_m) = 0 \\ f_2(x_1, x_2, ..., x_m) = 0 \\ f_3(x_1, x_2, ..., x_m) = 0 \\ ... \\ f_n(x_1, x_2, ..., x_m) = 0 \end{cases}$$ using the Steepest Descent method simply by setting $$g(x_1, x_2, ..., x_m) = \sum_{i=1}^n f_i^2$$ and then finding the set of $$x_i$$ that minimizes $$g$$. Use the Steepest Descent method to approximate the solution to the following system of non-linear equations with tolerance of $$0.01$$: $$\begin{cases} 3x^2 - y^2 = 0 \\ 3xy^2 - x^3 - 1 = 0 \end{cases}$$ Take the point $$(1,1)$$ as your starting point. Bonus marks are given for generating a Contour map of $$g(x,y)$$ and plotting the path taken to arrive at the solution on top of the map.

Questions from the textbook: 5.5, 5.9, 5.12