```python
import numpy as np
import sympy as sp
import math

import hw10 as p1

import matplotlib.pyplot as plt

%matplotlib inline
```

# Homework 10

## Chinmai Raman

### 5/22/2016

1. Consider the coupled set of ODEs with initial conditions $u(0) = 1$, $v(0) = 0$:
   
   $$u'(t) = v(t)$$
   $$v'(t) = -u(t)$$
   
   Show that the solution $u(t) = \cos(t)$ and $v(t) = -\sin(t)$ satisfies these equations. Explain what $u(t)$ and $v(t)$ could correspond to in a physical system.

$u'(t) = -sin(t) = v(t), v'(t) = -cos(t) = -u(t)$ 

$cos(0) = 1$ and $-sin(0) = 0$

Therefore $u(t)=cos⁡(t)$  and $v(t)=−sin(t)$ satisfy the coupled ODEs

In the below graphs, the red 

## Euler


```python
p1.plot('euler', 1000)
```


```python
p1.plot('euler', 5000)
```


```python
p1.plot('euler', 15000)
```

The Euler method provides us with a first order approximation of -sin(x) and cos(x) given the initial values. An order of magnitude of 4 for the value of n seems to provide us with a qualitatively correct solution to the system of ODEs.

## Heun


```python
p1.plot('heun', 100)
```


```python
p1.plot('heun', 200)
```


```python
p1.plot('heun', 500)
```

Heun's method, a second-order method, provides us with a better approximation of the functions than Euler does. An order of magnitude of 2 for n provides us with an graph virtually indistinguishable from the true functions.

## Runge-Kutta (second order)


```python
p1.plot('rungekutta2', 1000)
```


```python
p1.plot('rungekutta2', 10000)
```


```python
p1.plot('rungekutta2', 50000)
```

The second order Runge-Kutta method proves worse than the Euler and Heun methods in this case. Even at relatively high values of n--whereas using other methods the graph would have already been indistinguishable from the true functions--Runge-Kutta2 displays an upward oscillatory trend that requires an order of magnitude of at least 4 in order to curtail. Although it also of second order like Heun, Runge-Kutta2 proves highly inefficient for these particular coupled ODEs.

## Runge-Kutta (fourth order)


```python
p1.plot('rungekutta4', 1000)
```


```python
p1.plot('rungekutta4', 10000)
```


```python
p1.plot('rungekutta4', 30000)
```

This fourth order method proves no more qualitatively efficient than its second order counterpart, as it still requires an order of magnitude of 4 in order to match the actual functions. It would seem that Runge-Kutta is poorly adapted to functions that display oscillatory behavior. Heun's method, although of second-order, is by far the most efficient in solving the coupled ODEs with a low number of timesteps. 


```python

```

621f3813cf45428e20bedb3c9f6c57537fbdff72
ipynb
Jupyter Notebook
hw10.ipynb
chapman-phys227-2016s/hw-10-ChinmaiRaman
8d61fdd4313a1081c0b8f0884f1b3db114e68109
MIT
hw10.ipynb
chapman-phys227-2016s/hw-10-ChinmaiRaman
8d61fdd4313a1081c0b8f0884f1b3db114e68109
MIT
hw10.ipynb
chapman-phys227-2016s/hw-10-ChinmaiRaman
8d61fdd4313a1081c0b8f0884f1b3db114e68109
MIT
Qwen/Qwen-72B
1. YES
2. YES