[PDF] Informatique en CPGE (2015-2016) Corrigé TP 10 : résolution





Previous PDF Next PDF



Informatique en CPGE (2015-2016) Corrigé TP 10 : résolution

Objectif : programmer la méthode d'Euler pour résoudre l'équation différentielle y/ On reprend le programme de l'exercice 1. ... from numpy import array.



T.P.

21 févr. 2021 3 Modifications de la méthode d'Euler . ... Les exercices ici proposés sont classés en fonction de leur niveau de dif- ... max de python.



Résolution numérique dune équation différentielle

Exercice 1. On commence par importer les import numpy as np import matplotlib.pyplot as plt ... Enfin la méthode d'Euler implicite est définie par :.



Mathématiques et méthodes numériques (exercices)

Enoncés des séances d'exercices pour les cours LICAR1104 Ecrire un programme python qui calcule u(4) par les méthodes d'Euler explicite d'Euler.



python.pdf

Le langage de programmation utilisé est Python 3.6. Ces exercices Exercice 3.2 : Opérations sur les tableaux . ... Exercice 10.1 : Méthodes d'Euler .



Analyse numérique avec Python

22 mai 2014 Python) quelques algorithmes classiques d'analyse numérique. ... d'Euler qui est la principale méthode de résolution numérique d'équations ...



Informatique TP5 : Initiation aux outils de calcul scientifique CPP 1A

Exercice 1 (NumPy et les fonctions) Que donne le code suivant? Dans la suite on se propose d'étudier la méthode d'Euler qui consiste à approcher la ...



Équations différentielles : Euler vs. Heun vs. RK4 vs. odeint 1

array de numpy pour que les additions se passent comme des additions et non des concaténations de listes). EXERCICE 4 Adapter



Informatique en PCSI et MPSI Champollion 2013-2014 Méthodes d

19 févr. 2014 Implémentation de la méthode d'Euler en. Python. Runge Kutta d'ordre 4 ... Exercice: L'équation de. Van Der Pol (1924).



M62_CM9 : Révisions Table of Contents

1 avr. 2019 ensuite la tracer avec Python et la comparer à la solution exacte. ... Même exercice avec la méthode d'Euler explicite.



PX1224 - Week9: For Loops If Statements and Euler's Method

misc py euler py output py: Python files 1 1 2 Open the JupyterLab (JL) application on your PC Select/create an appropriate folder where you want JupyterLab to contain your Numerical Analysis code and select/create an appropriate folder for this worksheet (maybe call that folder 'Exercise_1 1'



Explanation to the rst thirty problems from Project Euler

This is a good exercice to master ranges in Python (the last element of the range not being included is an easy concept to forget at rst) First of all we have to copy/paste the number into a Python script and edit it so that it’s considered a prime In my solution I quoted it and made it readible



Searches related to exercice python euler PDF

Python Practice Book Release 2014-08-10 As already mentioned methods are also functions They can be assigned to other variables can be called separately >>> f=x upper >>>print f() HELLO Problem 13: Write a function istrcmp to compare two strings ignoring the case >>> istrcmp('python''Python') True >>> istrcmp('LaTeX''Latex') True

What is Euler's method in Python?

We will make use of Euler's method. It is the most basic method for solving differential equations. For Loops - The basics of for loops in Python (This page talks about lists because, as previously mentioned, arrays are a feature of NumPy rather than Python itself.) If statements - The basics of if statements in Python.

What is the formula for Euler function?

The Euler function is given by the following beautiful formula. Theorem 7.13. ?(m) = m Y pjm (1 1 p )5 Proof: Obviously if pis prime ?(p) = p 1. Moreover there are pn 1numbers between 1 and pndividable by pnamely the numbers 1p;2p;3p;4p;:::;pn 1p.

What are the rules of Project Euler?

According to the rules of Project Euler, it is only allowed to share the solutions to the first 100 exercises in a informative manner online. While I am trying to solve the exercises in ascending order (which mostly resembles ascending difficulty), I will solve some exercises from a later stage without having done some preceding ones.

How to solve a differential equation with explicit Euler formula?

Starting from a given initial value of S 0 = S ( t 0), we can use this formula to integrate the states up to S ( t f); these S ( t) values are then an approximation for the solution of the differential equation. The Explicit Euler formula is the simplest and most intuitive method for solving initial value problems.

http://mathematice.fr

Informatique en CPGE (2015-2016)

Corrigé TP 10 : résolution numérique

d"équations différentielles; méthode d"EulerExercice 1

Objectif : programmer la méthode d"Euler pour résoudre l"équation différentielley0=ysur l"inter-

valle[0;4]avecy(0) = 1.

1.def euler(a,b,y0,h,f):

x=a y=y0 liste_x=[a] liste_y=[y0] while x+h<=b: y+=h *f(x,y) liste_y.append(y) x+=h liste_x.append(x) return liste_x,liste_y def f(x,y): return y

2. On complète le programme avecprint(euler(0,4,1,1,f)). Le résultat doit être :([0,

1, 2, 3, 4], [1, 2, 4, 8, 16]).

3.# calcul de l"erreur

e=0 h=0.1 x,y=euler(0,4,1,h,f) for i in range(len(x)): if abs(exp(x[i])-y[i])>e: e=abs(exp(x[i])-y[i]) print("Pour h = ",h,"l"erreur est ",e) # ou bien x,y=euler(0,4,1,h,f) print(x[-1],y[-1],exp(4)-y[-1]) # l"erreur max est sur le dernier terme

Pour la dernière valeur des deux listes, il y a un problème d"arrondi, donc le x final n"est pas toujours

égal à 4. Pour remédier à ce problème, on peut modifier le test "while" dans la fonctioneuleren écrivant :

while round(x+h,6)<=b:.

4. Afin que l"erreur maximale soit de l"ordre de102, on prendh= 0:0001.Serge Bays1Lycée Les Eucalyptus

http://mathematice.fr

5. Représentations graphiques.import matplotlib.pyplot as plt

# écriture solution exacte x=[i *0.1 for i in range(41)] y=[exp(u) for u in x] plt.plot(x,y) # écriture sol approchée h=1 x,y=euler(0,4,1,1,f) plt.plot(x,y) # écriture sol approchée h=0.5 x,y=euler(0,4,1,0.5,f) plt.plot(x,y) # écriture sol approchée h=0.2 x,y=euler(0,4,1,0.2,f) plt.plot(x,y) # écriture sol approchée h=0.1 x,y=euler(0,4,1,0.1,f) plt.plot(x,y) plt.show()

Exercice 2

On reprend le programme 1 avec les modifications nécessaires sur l"écriture de la fonction f, l"écriture

de la solution exacte et l"appel de la fonctioneuler.from math import exp,cos,sin import matplotlib.pyplot as plt def f(x,y): return cos(2 *x)-y # solution exacte def solex(x): return 3.8 *exp(-x)+0.2*cos(2*x)+0.4*sin(2*x) xex=[i *0.01 for i in range(1201)] yex=[solex(u) for u in xex] plt.plot(xex,yex,"r") # solution approchée h=0.1 x,y=euler(0,12,4,0.1,f) plt.plot(x,y) plt.show()

Exercice 3

Objectif : résoudre l"équation différentielley0=yavecy(0) = 1sur l"intervalle[0;30].

1. On reprend le programme de l"exercice 1. On modifie la fonctionf(x;y) =yet les appels de la

fonctioneuler.Serge Bays2Lycée Les Eucalyptus http://mathematice.fr import matplotlib.pyplot as plt def euler(a,y0,b,h,f): x=a y=y0 liste_x=[a] liste_y=[y0] while x+h<=b: y+=h *f(x,y) liste_y.append(y) x+=h liste_x.append(x) return liste_x,liste_y def f(x,y): return -y # solution approchée h=3 x,y=euler(0,1,30,3,f) plt.plot(x,y) # solution approchée h=2.5 x,y=euler(0,1,30,2.5,f) plt.plot(x,y) plt.show()

2. Stabilité pourh2.# solution approchée h=1.5

x,y=euler(0,1,30,1.5,f) plt.plot(x,y) # solution approchée h=2 x,y=euler(0,1,30,2,f) plt.plot(x,y) plt.show()

3. L"erreur de discrétisationeest inférieure à101pourh= 0:4. (On utilise le code de l"exercice 1

en modifiant la valeur exacte.# calcul de l"erreur e=0 h=0.4 x,y=euler(0,1,30,h,f) for i in range(len(x)): if abs(exp(-x[i])-y[i])>e: e=abs(exp(-x[i])-y[i]) print("Pour h = ",h,"l"erreur est ",e)Serge Bays3Lycée Les Eucalyptus http://mathematice.fr

Exercice 4

Objectif : résoudre l"équation différentielle du second ordrey00+y= 0pourx2[0;10]avec les conditions initialesy(0) = 0ety0(0) = 1. On reprend les éléments du programme de l"exercice 1 avec quelques modifications.

1. Modification de la fonctionf.def f(x,y): # y est un couple

return (y[1],-y[0])

2. Modification de la fonctioneuler.def euler(a,b,y0,h,f):

x=a y=y0 liste_x=[a] liste_y=[y0] while x+h<=b: y=(y[0]+h *(f(x,y)[0]),y[1]+h*(f(x,y)[1])) # la difficulté liste_y.append(y) x+=h liste_x.append(x) return liste_x,liste_y

3. L"appel de la fonction.# solution approchée h=0.01

x,y=euler(0,10,(0,1),0.01,f)

4.from math import sin # pour la sol exacte

import matplotlib.pyplot as plt u=[y[i][0] for i in range(len(y))] plt.plot(x,u) # solution exacte y(x)=sin(x) x=[i *0.01 for i in range(1001)] y=[sin(u) for u in x] plt.plot(x,y) plt.show()Serge Bays4Lycée Les Eucalyptus http://mathematice.fr

Exercice 5

La définition de la fonctioneulers"écrit comme dans l"exercice 1. On modifie la définition de la

fonctionfqui renvoie un objet de typearrayet l"appel de la fonctioneuler:# y""+y=0 soit (y,y")"=(y",-y)=F(y,y")

from math import sin from numpy import array def f(x,y): return array((y[1],-y[0])) # utilisation d"un array def euler(a,b,y0,h,f): x=a y=y0 liste_x=[a] liste_y=[y0] while x+h<=b: y=y+h *f(x,y) # plus aucun problème de calcul liste_y.append(y) x+=h liste_x.append(x) return (liste_x,liste_y) x,y=euler(0,10,array((0,1)),0.01,f) u=[y[i][0] for i in range(len(y))] plt.plot(x,u) plt.show()

Exercice 6

Objectif : l"équation00=k1sink20.# y""= -k1 sin(y) - k2 y" pendule amorti (si k2=0, pendule simple)

# soit (y,y")"=(y",-k1 sin(y)- k2 y)=F(y,y") from math import sin,pi from numpy import array def f(x,y): return array((y[1],-5 *sin(y[0])-0.5*y[1])) # les valeurs de k1 et k2 def euler(a,b,y0,h,f): x=a y=y0 liste_x=[a] liste_y=[y0] while x+h<=b: y=y+h *f(x,y) liste_y.append(y) x+=hSerge Bays5Lycée Les Eucalyptus http://mathematice.fr liste_x.append(x) return (liste_x,liste_y) # solution approchée h=0.01 x,y=euler(0,20,array((pi/6,0)),0.01,f) for i in range(len(x)): u=[y[i][0] for i in range(len(y))] v=[y[i][1] for i in range(len(y))] plt.plot(x,u) plt.plot(u,v) plt.show()

Exercice 7

Pour une équation du typex0(t) =f(x(t);t), on utilise la fonctionodeintde scipy.integrate.from math import sin, pi

import numpy as np import matplotlib.pyplot as plt import scipy.integrate as integ def f(u,t): return [u[1],-5 *sin(u[0])-0.5*u[1]] t=np.linspace(0,20,num=400) sol=integ.odeint(f,[pi/6,0],t) plt.subplot(2,1,1) plt.grid() plt.plot(t,sol[:,0]) # angle fonction de t plt.subplot(2,1,2) plt.grid() plt.plot(sol[:,0],sol[:,1]) #diagramme de phase plt.show()Serge Bays6Lycée Les Eucalyptusquotesdbs_dbs27.pdfusesText_33
[PDF] le médecin malgré lui acte 2 scène 4

[PDF] méthode dichotomie python

[PDF] le message andrée chedid résumé détaillé

[PDF] résolution équation différentielle matlab ode45

[PDF] le message andrée chedid genre

[PDF] algorithme méthode d'euler implicite matlab

[PDF] méthode de tir équation différentielle

[PDF] le message andrée chedid quiz

[PDF] le message andrée chedid extrait

[PDF] méthode euler implicite matlab

[PDF] le message andrée chedid texte intégral

[PDF] fonction ode45 matlab

[PDF] memoire de fin detude en telecommunication

[PDF] grille évaluation projet

[PDF] comment bien faire l amour ? son mari pdf