"Given an initial guess $\\mathbf{x}_{0}$, Newton's method is used to compute successively better approximations to the solution of the above equation by the following iterative formula\n",

Newton's method is used to solve a *general* system of equations, written in vector form

$$\mathbf{f}(\mathbf{x}) = \mathbf{0}$$

Given an initial guess $\mathbf{x}_{0}$, Newton's method is used to compute successively better approximations to the solution of the above equation by the following iterative formula

Your stopping condition should be $\|\mathbf{f}(\mathbf(x_k))\|<tol$ or $\|\mathbf{x}_k-\mathbf{x}_{k+1}\|<tol$ (or both). Where $\|\mathbf{x}\|$ is the 2-norm of the vector $\mathbf{x}$ (i.e., Pythagoras' theorem).

Here we have written the vectors with 0-based index to make it consistent with how you would index them in Python.

### Q1)

In this assignment, we will use Newton's method for solving the following set of algebraic equations:

\begin{gather}

x_1−x^3_0=0 \\

x^2_0+x^2_1−1=0

\end{gather}

#### 1a)

Write a function called **f(x)**, that accepts a vector $\mathbf{x} = (x_0,x_1)^T$ and returns a vector that corresponds to $\mathbf{f}(\mathbf{x})$ such that the above set of equations can be written in the form $\mathbf{f}(\mathbf{x}) = \mathbf{0}$.

To do this, instead of inverting the matrix $\mathbf{f}'(\mathbf{x_k})^{-1}$, we will directly solve for $\mathbf{v}$ by solving the following linear system

Write a function called vsolve(x,df,f), that accepts a vector x, the Jacobian df and the function f and returns a vector v that solves the above linear system.

Note: you can use a built-in function for solving linear systems such as scipy.linalg.solve

If you have written your code correctly, then

x = np.array([1,1])

print(vsolve(x,df,f))

should return

[0.125 0.375]

%% Cell type:code id: tags:

``` python

```

%% Output

[0.125 0.375]

%% Cell type:markdown id: tags:

#### 1d)

Write a function called **newton(x,f,df,tol)**, that accepts a vector **x**, a vector-valued function **f**, it's Jacobian derivative **df**, a tolerance, and returns a solution **x**, that solves **f(x)=0**.

Run your code with the initial guess $\mathbf{x} = (0,0)^T$ and $tol = 10^{-15}$.

If your code has been written correctly, then it should return a value $\mathbf{x}$ that solves $\mathbf{f}(\mathbf{x})$ to within your tolerance.