# Untitled

a guest
Feb 28th, 2020
83
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # -*- coding: utf-8 -*-
2. """
3. Éditeur de Spyder
4.
5. Ceci est un script temporaire.
6. """
7.
8. from numpy import *
9. from matplotlib.pyplot import *
10. from random import random
11.
12. from mpl_toolkits.mplot3d import Axes3D
13.
14. #1
15. def trace_graphe(f,a,b,pas):
16. plot([a+k*pas for k in range(int((b-a)/pas))],[f(a+k*pas) for k in range(int((b-a)/pas))],"+")
17. show()
18. return
19.
20. #2
21. def petit_nuage():
22. for i in range(50):
23. plot([random()*10],[random()*10],"+")
24. show()
25. return
26.
27. #3
28. def euler(F,a,b,y0,n):
29. listeTemps = [a]
30. listeY = [y0]
31. h = (b-a)/(n-1)
32. for i in range(1,n):
33. listeY.append(listeY[-1]+F(listeTemps[-1], listeY[-1] * h))
34. listeTemps.append(listeTemps[-1]+h)
35. return listeTemps,listeY
36.
37. #4
38. m = asarray
39.
40. def euler_vectorielle(F,a,b,y0,n):
41. listeTemps = [a]
42. listeY = [y0]
43. h = (b-a)/(n-1)
44. for i in range(1,n):
45. deltaY = m(F(listeTemps[-1], listeY[-1])) * h
46. listeY.append(m(listeY[-1]) + m(deltaY))
47. listeTemps.append(listeTemps[-1]+h)
48. return listeTemps, listeY
49.
50. #F = lambda t, u:[-u[0], u[0]-u[1], u[1]]
51. #x, y = euler_vectorielle(F, 0, 10, [1,0,0], 100)
52. #plot(x,y)
53. #show()
54.
55. #5
56. def trajectoire(F,a,b,y0,n):
57. couples = euler_vectorielle(F,a,b,y0,n)[1]
58. listeX = [couples[k][0] for k in range(len(couples))]
59. listeY = [couples[k][1] for k in range(len(couples))]
60. plot(listeX, listeY, "--")
61. # show()
62. return()
63.
64. #F = lambda t,u: [u[0]+3*u[1], -3*u[0]+ u[1]]
65. #trajectoire(F, 0, 10, [1,1], 1000)
66.
67. #6
68. def conditions(F,a,b,y0,n,[])
RAW Paste Data