
# coding: utf-8

# In[2]:


import matplotlib.pyplot as plt
import numpy as np
get_ipython().run_line_magic('matplotlib', 'notebook')
#%matplotlib inline


# In[3]:


def f(t,y):
    return t**2+y**2

def EulerPsi(hn,tn,yn):
    return yn+hn*f(tn,yn)


# In[4]:


def EulerLsg(t0,y0,T,N):
    y = y0
    t = t0
    ys = [y0]
    ts = [t]
    h = (T-t0)/N
    for _ in range(N):
        t += h
        y = EulerPsi(h,t,y)
        ys.append(y)
        ts.append(t)
    return ts, ys


# In[7]:


plt.figure()
plt.legend()
ts,ys = EulerLsg(-3/2,1.4,-1,42)
plt.plot(ts,ys,'o')
ts,ys = EulerLsg(-3/2,1.4,-1,28)
plt.plot(ts,ys,'x')
plt.show()

