Méthode d'Euler Équation $y'=y$

Xmin = -1 Xmax = 2 Ymin = -1 Ymax = 3 GradX = 0.1 GradY = 0.1 traceG() traceX() traceY() T = [ [[0,1],[1,1]], [[0.1,1.1],[1,1.1]], [[0.2,1.21],[1,1.21]], [[0.3,1.331],[1,1.331]], [[0.4,1.4641],[1,1.4641]], [[0.5,1.6105],[1,1.6105]], [[0.6,1.7716],[1,1.7716]], [[0.7,1.9487],[1,1.9487]], [[0.8,2.1436],[1,2.1436]], [[0.9,2.3580],[1,2.3580]], [[1,2.5938],[1,2.5938]] ] coef=[ ["","+1"],["1,1","+0,99"],["1,21","+0,968"],["1,331","+0,9317"],["1,4641","+0,8785"], ["1,6105","+0,8053"],["1,7716","+0,7086"],["1,9487","+0,5846"],["2,1436","+0,4287"],["2,3580","+0,2358"],["2,5938",""] ] curseur("k",0,0,10,1) for(i=0;i<{k};i++){ couleur = noir point(T[i][0]) couleur = rouge point(T[i+1][0]) } couleur = rouge point( T[{k}][0] ) couleur = bleu droiteParam( T[{k}][0], T[{k}][1] ) texte("k = "+{k},[-0.8,2]) texte("y = "+coef[{k}][0]+"x"+coef[{k}][1],[-0.8,1.8]) trait = 2 couleur = noir segment([1,0.05],[1,-0.05]) segment([0.05,1],[-0.05,1]) segment([0.05,2],[-0.05,2]) texte("1",[0.96,-0.20]) texte("1",[-0.15,0.95]) texte("2",[-0.15,1.95])

La fonction euler prend en paramètres un nombre $x$, un nombre $y_0$ et retourne la valeur $y(x)$ pour la condition initiale $y(0)=y0$.

def euler(x,y0): y = y0 n = 10**6 p = 1.0*x/n for i in range(0,n): y = y*(1.0+p) return y print euler(1,1) print euler(2,1)

Équation $y'=f$ La fonction euler prend en paramètres une fonction $f$, un nombre $x$ et la condition initiale $(x_0\,;y_0)$. Elle retourne la valeur de $y(x)$.

def f(x): return x*x def t(x): return 1.0/x def euler(f,x,x0,y0): n = 10**5 p = 1.0*x/n y = y0 x = x0 for i in range(0,n): y = p*f(x)+y x = x + p return y print euler(f,2,0,0) print euler(t,10,1,0)

Équation $y'=ay+b$ La fonction euler prend en paramètres un nombre $x$, les nombres $a$ et $b$ (de $y'=ay+b$) et un nombre $y_0$. Elle retourne la valeur $y(x)$ pour la condition initiale $y(0)=y0$.

def euler(x,a,b,y0): n = 10**5 p = 1.0*x/n y = y0 for i in range(0,n): y = (a*y+b)*p+y return y print euler(1,1,1,1)