# TP Objet1, norme, produit scal, moment, produit vectoriel
class vecteur:
x, y, z = 0, 0, 0
def __init__(self, cord):
self.x = cord[0]
self.y = cord[1]
self.z = cord[2]
def affich(self):
print([self.x, self.y, self.z, self.t])
def norme(self):
#Soit M la norme d'un vecteur
M = ((self.x)**2 + (self.y)**2 + (self.z)**2)**(0.5)
print('La norme est: ', M)
def prod(self, other):
#Soit P le produit scalaire de deux vecteurs
P = (self.x)*(other.x) + (self.y)*(other.y) + (self.y)*(other.z)
print('Le produit scalaire est: ', P)
def vectoriel(self, other):
x1 = self.y*other.z - other.y*self.z
y1 = self.x*other.z - other.x*self.z
z1 = self.x*other.y - other.x*self.y
return [x1, y1, z1]
def neg(self):
x1 = -self.x
y1 = -self.y
z1 = -self.z
print([x1, y1, z1])
def add(self, other):
x1 = self.x + other.x
y1 = self.y + other.y
z1 = self.z + other.z
print([x1, y1, z1])
def diff(self, other):
x1 = self.x - other.x
y1 = self.y - other.y
z1 = self.z - other.z
print([x1, y1, z1])
u = vecteur([1, 2, 3])
v = vecteur([4, 5, 6])
u.norme()
v.norme()
u.prod(v)
v.vectoriel(u)
u.neg()
v.neg()
u.add(v)
u.diff(v)
class polynome:
coeff, x, a, b = [], 0, 0, 0
def __init__(self, coeff, x, a, b):
self.coeff = coeff
self.x = x
self.a = a
self.b = b
def poly(self): # poly donne la valeur de P(x) = A0 + A1X^1 + A2X^2 + ... + AnX^n
a0 = self.coeff[0] # ceci est le premier coefficient du polynome (A0)
for n in range(1, len(self.coeff)):
p = a0 + self.coeff[n]*self.x**n
a0 = p
return p
def derive(self): # Cette methode calcul la derive en un point x
a1 = 0
for n in range(1, len(self.coeff)):
v = a1 + n*self.coeff[n]*self.x**(n-1)
a1 = v
return v
def integral(self): # cette methode calcul l'integrale de P(x) sur [a, b], a < b
a2 = self.coeff[0]*(self.b - self.a)
for n in range(1, len(self.coeff)):
h = a2 + (self.coeff[n]/(n+1))*(self.b**(n+1) - self.a**(n+1))
a2 = h
return h
##############
##Class ended##
##############
u = polynome(coeff = [1, 2], x = 1, a = 1, b = 2) #Ici j'appelle la class polynome
print('P(x) = ', u.poly())
print('dP(x) = ', u.derive())
print('integral_P(x) = ', u.integral())
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 20, 100)
def model(y, x, k):
dy= k*y
return dy
k = 0.1
y0 = odeint(model, 5, x, (k, ))
k = 0.3
y1 = odeint(model, 5, x, (k, ))
k = 0.5
y2 = odeint(model, 5, x, (k, ))
k = 1.2
y3 = odeint(model, 5, x, (k, ))
plt.plot(x, y0)
plt.plot(x, y1)
plt.plot(x, y2)
plt.plot(x, y3)
plt.show()
import scipy.integrate as Int
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 20, 100)
def model(x, y, k):
dxdy = -k*y + np.sin(y)
return dxdy
#y = Int.odeint(model, 0, x, (k, ), u)
k = 0.1
y0 = Int.odeint(model, 0, x, (k, ))
plt.plot(x, y0)
plt.show()
from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
1 / 9 100%
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !