-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler.py
More file actions
37 lines (32 loc) · 660 Bytes
/
euler.py
File metadata and controls
37 lines (32 loc) · 660 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from math import *
import numpy as np
import matplotlib.pyplot as plt
from random import *
xo=0
yo=1
step=0.1
def func(x,y):
return x*y
y=[yo] #given
x=[xo] #given
f=[xo] #given
cnt=0
for i in range(40):
y_i=y[cnt]+(func(x[cnt],y[cnt])*step)
y.append(y_i)
x.append(x[cnt]+step)
f.append(func(x[cnt],y[cnt]))
cnt+=1
print x
print y
xval= np.arange(-10., 10.,0.01)
axes = plt.gca()
axes.set_xlim([-10,10])
axes.set_ylim([-10,10])
#print xval*(1.0-xval)
# plt.plot(xval,np.exp(xval)-np.sin(pi*xval), 'b')
plt.plot(x,y,'b')
plt.xticks(np.arange(min(x), max(x)+1, 2))
plt.axhline(0, color='black')
plt.axvline(0,color='black')
plt.savefig("euler.png")