# -*- coding: utf-8 -*- """ Exercice 13-7: résolution de l'équation des ondes avec des conditions aux bords de Dirichlet, méthode des éléments finis Created on Tue Sep 12 11:04:31 2017 @author: ribot/grivet """ import numpy as np import matplotlib.pyplot as plt # Vitesse c=1; # Discrétisation en espace xmin = 0; xmax = 1; h = 0.01 xx = np.arange(xmin,xmax,h) #xx=xx'; npt = np.size(xx) nx = npt-2 xxint = xx[1:nx+1] # Matrice de discrétisation en espace 1D K = 2*np.eye(nx,nx)-np.diag(np.ones(nx-1),1)-np.diag(np.ones(nx-1),-1) K1D = K/h**2 # Discrétisation en temps Tfin = 1; dt = 0.9*h/c ntps = np.ceil(Tfin/dt) # Donnée initiale k = 100 x0=(xmin+xmax)/2 f = np.exp(-k*(xxint-x0)**2) g = np.zeros(nx) u0 = f; u1 = u0+dt*g # Résolution en temps - Euler Explicite for t in range(int(ntps)): # produit matrice x vecteur u = 2*u1-c**2*dt**2*np.dot(K1D,u1)-u0 u0 = u1 u1 = u; if t % 10 == 0: uu = np.hstack((0,u,0)) plt.plot(xx, uu)