# Homework 4¶

### 1. Stiff system¶

(a) Implement the trapeziodal method (see p423) to solve the stiff system 7.97, with the initial condition y(0.2) = [0.33530156, 0.33501848, 0.0003807 ], going to t=5 with h=.05. Use a fixed number of Newton iterations. Since the DE happens to be linear, Newton will actually solve the system in 1 iteration. Plot your solution.

(b) Compare with using Euler's method with the same step size.

Compose your formal answer using GoodNotes, Notability, OneNote, Xournal, or a similar tool of your choice, with text, code, graphics all displayed in an integrated way so that your "story" can be read in one pass. Upload this to Gradescope.

### 1. Stiff system: the question I meant to ask. Do this one if you haven't committed to the other one yet.¶

(a) Implement the trapeziodal method (see p423) to solve the stiff system,

$$Y^\prime = \begin{bmatrix} x^\prime\\ y^\prime\\ z^\prime \end{bmatrix} = \begin{bmatrix} -y\\ x\\ -100(z-x^2-y^2) \end{bmatrix}.$$

with the initial condition $Y(0) = [3,0,18]^T$, going to t=5 with h=.05. Use a fixed number of Newton iterations. Plot your solution.

(b) Compare with using Euler's method with the same step size.

Compose your formal answer using GoodNotes, Notability, OneNote, Xournal, or a similar tool of your choice, with text, code, graphics all displayed in an integrated way so that your "story" can be read in one pass. Upload this to Gradescope.

### Hints¶

You need to create functions like:

In [1]:
def f(t,y):
...

def Df(t,y):
...


To solve the matrix-vector equation Ax=b:

np.linalg.solve(A, b)

To get the identity matrix:

np.eye(3)

Calculate the Newton step $s = -Dg^{-1} g$ by solving $Dg\ s = -g$ for $s$.

Don't confuse the jacobian of the function $g$ whose root you want to find with the jacobian of $f$ (the right hand side of the differential equation), though the former is expressed simply in terms of the latter.

In [ ]: