Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News Sign UpSign In
| Download
Views: 121
Image: ubuntu2004
Kernel: Python 3 (Anaconda 2020)
import numpy as np from matplotlib import pyplot as plt from scipy import stats def f(x,test,m) : if test==1: return (m**2)*np.sin(m*x) elif test==2 : return (m**2)*np.cos(m*x) def ue_npen(x,test,m,c): if test==1 : return np.sin(m*x) elif test==2 : return np.cos(m*x)+c def ue_pen_dir(x,eta,m) : k=((1/np.pi)*np.exp(-np.pi/np.sqrt(eta)))-((1/np.pi)*np.exp(-2*np.pi/np.sqrt(eta)))+((1/np.sqrt(eta))*np.exp(-2*np.pi/np.sqrt(eta))) k_p=((1/np.pi)*np.exp(np.pi/np.sqrt(eta)))-((1/np.pi)*np.exp(2*np.pi/np.sqrt(eta)))-((1/np.sqrt(eta))*np.exp(2*np.pi/np.sqrt(eta))) k1=((1/np.pi)*np.exp(-np.pi/np.sqrt(eta)))-((1/np.pi)*np.exp(-2*np.pi/np.sqrt(eta)))+((1/np.sqrt(eta))*np.exp(-np.pi/np.sqrt(eta))) k1_p=((1/np.pi)*np.exp(np.pi/np.sqrt(eta)))-((1/np.pi)*np.exp(2*np.pi/np.sqrt(eta)))-((1/np.sqrt(eta))*np.exp(np.pi/np.sqrt(eta))) B2_d=(-k*m*((-1)**m)-k1*m)/((1+eta*m**2)*(k_p*k1-k*k1_p)) B1_d=(1/k)*(-m/(1+eta*m**2)-B2_d*k_p) A1_d=B1_d*((1/np.pi*np.exp(-np.pi/np.sqrt(eta)))-(1/np.pi*np.exp(-2*np.pi/np.sqrt(eta))))+B2_d*((1/np.pi*np.exp(np.pi/np.sqrt(eta)))-(1/np.pi*np.exp(2*np.pi/np.sqrt(eta)))) A2_d=B1_d*np.exp(-2*np.pi/np.sqrt(eta))+B2_d*np.exp(2*np.pi/np.sqrt(eta)) if 0 < x and x < np.pi: return np.sin(m*x)+(A1_d*x)+A2_d if np.pi < x and x < 2*np.pi: return (m**2*eta/(1+eta*m**2))*np.sin(m*x)+B1_d*np.exp((-x)/np.sqrt(eta))+B2_d*np.exp((x)/np.sqrt(eta)) def ue_pen_neu(x,eta,m) : B1_n=(1-(-1)**m)/((1+eta)*np.pi) A1_n=eta*B1_n B2_n=(3*np.pi/2)*((((-1)**m)-1)/(1+eta))*((eta/2)+2)+1 A2_n=2*np.pi*B1_n+B2_n-1 if 0 < x and x < np.pi: return np.cos(m*x)+A1_n*x+A2_n if np.pi < x and x < 2*np.pi: return B1_n*x+B2_n ue_pen_dir(1,0.01,2)
1.1016051191333829
X=np.linspace(0,2*np.pi,40) plt.plot(X,ue_npen(X,1,2,0)) l=[] for x in X : l.append(ue_pen_dir(x,0.1,2)) plt.plot(X,l,'-*') plt.xlabel('valeurs de X sur l intervalle [0, 2pi]') plt.legend(loc = 'upper right') plt.title(r'tracer des courbes des solutions $u(x)$ et $u_{eta}(x)$ pour le cas dirichlet') plt.show()
No handles with labels found to put in legend.
Image in a Jupyter notebook
X=np.linspace(0,2*np.pi,40) plt.plot(X,ue_npen(X,2,2,0)) l=[] for x in X : l.append(ue_pen_neu(x,0.1,2)) plt.plot(X,l,'-*') plt.xlabel('valeurs de X sur l intervalle [0, 2pi]') plt.legend(loc = 'upper right') plt.title(r'tracer des courbes des solutions $u(x)$ et $u_{eta}(x)$ pour le cas neumann') plt.show()
No handles with labels found to put in legend.
Image in a Jupyter notebook
X=np.linspace(0,2*np.pi,40) l_eta=[0.000001,0.00001,0.0001,0.001,0.01,0.1] p=[] for eta in l_eta : p.append(ue_pen_dir(1,eta,2)) plt.plot(l_eta,p) plt.xlabel('valeurs de eta ') plt.ylabel('valeurs de $u_{eta}(x=1)$ ') plt.legend(loc = 'upper right') plt.title(r'tracer de la courbe de $u_{eta}(x=1)$ pour le cas dirichlet') plt.show()
/ext/anaconda2020.02/lib/python3.7/site-packages/ipykernel/__main__.py:21: RuntimeWarning: overflow encountered in exp /ext/anaconda2020.02/lib/python3.7/site-packages/ipykernel/__main__.py:21: RuntimeWarning: invalid value encountered in double_scalars /ext/anaconda2020.02/lib/python3.7/site-packages/ipykernel/__main__.py:23: RuntimeWarning: overflow encountered in exp /ext/anaconda2020.02/lib/python3.7/site-packages/ipykernel/__main__.py:23: RuntimeWarning: invalid value encountered in double_scalars /ext/anaconda2020.02/lib/python3.7/site-packages/ipykernel/__main__.py:25: RuntimeWarning: divide by zero encountered in double_scalars /ext/anaconda2020.02/lib/python3.7/site-packages/ipykernel/__main__.py:26: RuntimeWarning: overflow encountered in exp /ext/anaconda2020.02/lib/python3.7/site-packages/ipykernel/__main__.py:26: RuntimeWarning: invalid value encountered in double_scalars /ext/anaconda2020.02/lib/python3.7/site-packages/ipykernel/__main__.py:27: RuntimeWarning: overflow encountered in exp No handles with labels found to put in legend.
Image in a Jupyter notebook

On constate que plus la valeur de eta est grande, plus ueta(x=1)u_{eta}(x=1) l'est aussi.

X=np.linspace(0,2*np.pi,40) l_eta=[0.000001,0.00001,0.0001,0.001,0.01,0.1] p=[] for eta in l_eta : p.append(ue_pen_neu(1,eta,2)) plt.plot(l_eta,p) plt.xlabel('valeurs de eta ') plt.ylabel('valeurs de $u_{eta}(x=1)$ ') plt.legend(loc = 'upper right') plt.title(r'tracer de la courbe de $u_{eta}(x=1)$ pour le cas neumann') plt.show()
No handles with labels found to put in legend.
Image in a Jupyter notebook

On constate que pour différentes valeurs de eta, la solution ueta(x=1)u_{eta}(x=1) reste constante.

X=np.linspace(0.1,2*3.14,40) def difference_u_et_ueta(test,m,c,eta): U=(X,test,m,c) lv=[] for x in X : lv.append(ue_pen_dir(x,eta,m)) V=np.array(lv) return abs(list(U)[0] - V) difference_u_et_ueta(1,2,0,0.1)
array([0.55046708, 0.68754378, 0.77539625, 0.78949102, 0.71264108, 0.53671772, 0.26346017, 0.0956976 , 0.52076578, 0.98518972, 1.45849484, 1.90932198, 2.30855084, 2.63220041, 2.86381759, 2.9961159 , 3.03170126, 2.98281242, 2.87010197, 2.72057929, 2.89531353, 3.09011672, 3.25344255, 3.41044491, 3.57678943, 3.76107252, 3.96637059, 4.19138184, 4.43141827, 4.67937012, 4.92667439, 5.16425756, 5.38338174, 5.57629525, 5.73656631, 5.85895448, 5.9386351 , 5.96952162, 5.94129933, 5.83455001])
U, V = difference(1,2,0,0.1) plt.loglog(X,abs(list(U)[0] - V)) plt.xlabel('valeurs de X entre $[0,2pi]$ ') plt.ylabel('valeurs de $d_{eta}(x)$ ') plt.legend(loc = 'upper right') plt.title(r'tracer de la courbe de $d_{eta}(x)$ pour le cas dirichlet') plt.show()
No handles with labels found to put in legend.
Image in a Jupyter notebook
np.linalg.norm(list(U)[0] - V, np.infty)
5.969521624575377

On obtient donc la valeur de max∣deta(x)∣max|d_{eta}(x)| pour x dans [0,2pi][0,2pi]

V
array([ 0.65046708, 0.94600532, 1.19231933, 1.36487564, 1.44648723, 1.42902541, 1.3142294 , 1.11353317, 0.84692653, 0.54096413, 0.22612054, -0.06624506, -0.30701238, -0.47220041, -0.54535605, -0.51919282, -0.39631664, -0.18896627, 0.08220572, 0.39018994, 0.37391724, 0.33757559, 0.3327113 , 0.33417047, 0.32628749, 0.30046594, 0.25362941, 0.1870797 , 0.10550481, 0.0160145 , -0.07282824, -0.15194987, -0.21261251, -0.24706448, -0.24887401, -0.21280063, -0.13401972, -0.0064447 , 0.18023913, 0.44544999])
def pente(test,m,c,eta): x=np.log(X) y=np.log(difference_u_et_ueta(test,m,c,eta)) return stats.linregress(x,y)[0] pente(1,2,0,0.01)
1.0778788811872724
ue_pen_neu(1,0.01,2)
-0.4161468365471424
def A1(n): h=np.pi/(n+1) A=np.zeros((n,n)) for i in range(n): A[i,i]=2 for i in range(n-1): A[i,i+1]=-1 A[i+1,i]=-1 return A/(h**2) def A2(n): h=2*np.pi/(n+1) A=np.zeros((n,n)) for i in range(n): A[i,i]=2 for i in range(n-1): A[i,i+1]=-1 A[i+1,i]=-1 return A/(h**2) def A3(n): h=np.pi/(n+1) A3=np.zeros((n,n)) for i in range(1,n-1): A3[i,i]=2 for i in range(n-1): A3[i,i+1]=-1 A3[i+1,i]=-1 A3[0,0]=-1 A3[n-1,n-1]=-1 return (A3)/(h**2) def norm_npen_dir(N,test,m,c): h=np.pi/(N+1) X=np.linspace(0,np.pi,N) print(X) A=A1(N) b=f(X,test,m) Ubar=ue_npen(X,1,m,c) U=np.linalg.solve(A,b) e=np.linalg.norm(Ubar-U,np.infty) return X,A,U,Ubar,e norm_npen_dir(50,1,0.01,2) def norm_npen_neu(N,m,test,c): h=np.pi/(N+1) X=np.linspace(0,np.pi,N) print(X) A=A3(N) b=f(X,test,m) Ubar=ue_npen(X,2,m,c) U=np.linalg.solve(A,b) e=np.linalg.norm(Ubar-U,np.infty) return X,A,U,Ubar,e ue_npen(X,2,2,0)
[0. 0.06411414 0.12822827 0.19234241 0.25645654 0.32057068 0.38468481 0.44879895 0.51291309 0.57702722 0.64114136 0.70525549 0.76936963 0.83348377 0.8975979 0.96171204 1.02582617 1.08994031 1.15405444 1.21816858 1.28228272 1.34639685 1.41051099 1.47462512 1.53873926 1.60285339 1.66696753 1.73108167 1.7951958 1.85930994 1.92342407 1.98753821 2.05165235 2.11576648 2.17988062 2.24399475 2.30810889 2.37222302 2.43633716 2.5004513 2.56456543 2.62867957 2.6927937 2.75690784 2.82102197 2.88513611 2.94925025 3.01336438 3.07747852 3.14159265]
array([ 0.98006658, 0.86934393, 0.67203258, 0.40778519, 0.10292144, -0.21219353, -0.50617352, -0.74973744, -0.91862574, -0.99601675, -0.97420214, -0.85535469, -0.65131191, -0.38239692, -0.07539429, 0.23911778, 0.52981316, 0.7677379 , 0.92919413, 0.99810043, 0.96759358, 0.84071212, 0.63009375, 0.35671656, 0.04780956, -0.26585939, -0.55304812, -0.78515195, -0.93905279, -0.99942176, -0.96024596, -0.8254274 , -0.60839432, -0.33076374, -0.0201883 , 0.29239794, 0.57586065, 0.80196629, 0.94819419, 0.99997971])
def trace_npen_dir(N,test,m,c) : X,A,U,Ubar,e=norm_npen_dir(N,test,m,c) plt.plot(X,U,'-*') plt.plot(X,Ubar) plt.xlabel('valeurs de N') plt.legend(loc = 'upper right') plt.title(r'tracer des courbes de la solution exacte et approchée de $u(x)$ pour le cas dirichlet non pénalisé') plt.show() trace_npen_dir(50,1,4,0)
[0. 0.06411414 0.12822827 0.19234241 0.25645654 0.32057068 0.38468481 0.44879895 0.51291309 0.57702722 0.64114136 0.70525549 0.76936963 0.83348377 0.8975979 0.96171204 1.02582617 1.08994031 1.15405444 1.21816858 1.28228272 1.34639685 1.41051099 1.47462512 1.53873926 1.60285339 1.66696753 1.73108167 1.7951958 1.85930994 1.92342407 1.98753821 2.05165235 2.11576648 2.17988062 2.24399475 2.30810889 2.37222302 2.43633716 2.5004513 2.56456543 2.62867957 2.6927937 2.75690784 2.82102197 2.88513611 2.94925025 3.01336438 3.07747852 3.14159265]
No handles with labels found to put in legend.
Image in a Jupyter notebook
def erreurs_npen_dir(test,m,c,N): X,A,U,Ubar,e=norm_npen_dir(N,test,m,c) return e erreurs_npen_dir(1,2,2,20)
[0. 0.16534698 0.33069396 0.49604095 0.66138793 0.82673491 0.99208189 1.15742887 1.32277585 1.48812284 1.65346982 1.8188168 1.98416378 2.14951076 2.31485774 2.48020473 2.64555171 2.81089869 2.97624567 3.14159265]
0.2426866721574766
def erreurs_npen_neu(test,m,c,N): X,A,U,Ubar,e=norm_npen_neu(N,test,m,c) return e
erreurs_npen_neu(2,2,0,20)
[0. 0.16534698 0.33069396 0.49604095 0.66138793 0.82673491 0.99208189 1.15742887 1.32277585 1.48812284 1.65346982 1.8188168 1.98416378 2.14951076 2.31485774 2.48020473 2.64555171 2.81089869 2.97624567 3.14159265]
1.0223800553312685
def tracer_erreurs_npen_dir(lst_n): l=[] for n in lst_n : l.append(erreurs_npen_dir(1,2,0,n)) plt.xlabel('valeurs de n en échelle log') plt.legend(loc = 'upper right') plt.title(r'tracer de la courbe derreurs de $u(x)$ pour le cas dirichlet non pénalisé en échelle log') plt.loglog(lst_n,l) plt.show() tracer_erreurs_npen_dir([20,30,40,50,60,70,80,90,100])
[0. 0.16534698 0.33069396 0.49604095 0.66138793 0.82673491 0.99208189 1.15742887 1.32277585 1.48812284 1.65346982 1.8188168 1.98416378 2.14951076 2.31485774 2.48020473 2.64555171 2.81089869 2.97624567 3.14159265] [0. 0.10833078 0.21666156 0.32499234 0.43332312 0.54165391 0.64998469 0.75831547 0.86664625 0.97497703 1.08330781 1.19163859 1.29996937 1.40830016 1.51663094 1.62496172 1.7332925 1.84162328 1.94995406 2.05828484 2.16661562 2.2749464 2.38327719 2.49160797 2.59993875 2.70826953 2.81660031 2.92493109 3.03326187 3.14159265] [0. 0.08055366 0.16110732 0.24166097 0.32221463 0.40276829 0.48332195 0.5638756 0.64442926 0.72498292 0.80553658 0.88609024 0.96664389 1.04719755 1.12775121 1.20830487 1.28885852 1.36941218 1.44996584 1.5305195 1.61107316 1.69162681 1.77218047 1.85273413 1.93328779 2.01384144 2.0943951 2.17494876 2.25550242 2.33605608 2.41660973 2.49716339 2.57771705 2.65827071 2.73882436 2.81937802 2.89993168 2.98048534 3.061039 3.14159265] [0. 0.06411414 0.12822827 0.19234241 0.25645654 0.32057068 0.38468481 0.44879895 0.51291309 0.57702722 0.64114136 0.70525549 0.76936963 0.83348377 0.8975979 0.96171204 1.02582617 1.08994031 1.15405444 1.21816858 1.28228272 1.34639685 1.41051099 1.47462512 1.53873926 1.60285339 1.66696753 1.73108167 1.7951958 1.85930994 1.92342407 1.98753821 2.05165235 2.11576648 2.17988062 2.24399475 2.30810889 2.37222302 2.43633716 2.5004513 2.56456543 2.62867957 2.6927937 2.75690784 2.82102197 2.88513611 2.94925025 3.01336438 3.07747852 3.14159265] [0. 0.05324733 0.10649467 0.159742 0.21298933 0.26623667 0.319484 0.37273133 0.42597866 0.479226 0.53247333 0.58572066 0.638968 0.69221533 0.74546266 0.79871 0.85195733 0.90520466 0.958452 1.01169933 1.06494666 1.118194 1.17144133 1.22468866 1.27793599 1.33118333 1.38443066 1.43767799 1.49092533 1.54417266 1.59741999 1.65066733 1.70391466 1.75716199 1.81040933 1.86365666 1.91690399 1.97015133 2.02339866 2.07664599 2.12989332 2.18314066 2.23638799 2.28963532 2.34288266 2.39612999 2.44937732 2.50262466 2.55587199 2.60911932 2.66236666 2.71561399 2.76886132 2.82210865 2.87535599 2.92860332 2.98185065 3.03509799 3.08834532 3.14159265] [0. 0.04553033 0.09106066 0.13659098 0.18212131 0.22765164 0.27318197 0.3187123 0.36424263 0.40977295 0.45530328 0.50083361 0.54636394 0.59189427 0.6374246 0.68295492 0.72848525 0.77401558 0.81954591 0.86507624 0.91060657 0.95613689 1.00166722 1.04719755 1.09272788 1.13825821 1.18378854 1.22931886 1.27484919 1.32037952 1.36590985 1.41144018 1.45697051 1.50250083 1.54803116 1.59356149 1.63909182 1.68462215 1.73015248 1.7756828 1.82121313 1.86674346 1.91227379 1.95780412 2.00333445 2.04886477 2.0943951 2.13992543 2.18545576 2.23098609 2.27651642 2.32204674 2.36757707 2.4131074 2.45863773 2.50416806 2.54969839 2.59522871 2.64075904 2.68628937 2.7318197 2.77735003 2.82288036 2.86841068 2.91394101 2.95947134 3.00500167 3.050532 3.09606233 3.14159265] [0. 0.039767 0.07953399 0.11930099 0.15906798 0.19883498 0.23860197 0.27836897 0.31813596 0.35790296 0.39766996 0.43743695 0.47720395 0.51697094 0.55673794 0.59650493 0.63627193 0.67603893 0.71580592 0.75557292 0.79533991 0.83510691 0.8748739 0.9146409 0.95440789 0.99417489 1.03394189 1.07370888 1.11347588 1.15324287 1.19300987 1.23277686 1.27254386 1.31231086 1.35207785 1.39184485 1.43161184 1.47137884 1.51114583 1.55091283 1.59067982 1.63044682 1.67021382 1.70998081 1.74974781 1.7895148 1.8292818 1.86904879 1.90881579 1.94858279 1.98834978 2.02811678 2.06788377 2.10765077 2.14741776 2.18718476 2.22695175 2.26671875 2.30648575 2.34625274 2.38601974 2.42578673 2.46555373 2.50532072 2.54508772 2.58485471 2.62462171 2.66438871 2.7041557 2.7439227 2.78368969 2.82345669 2.86322368 2.90299068 2.94275768 2.98252467 3.02229167 3.06205866 3.10182566 3.14159265] [0. 0.03529879 0.07059759 0.10589638 0.14119518 0.17649397 0.21179276 0.24709156 0.28239035 0.31768914 0.35298794 0.38828673 0.42358553 0.45888432 0.49418311 0.52948191 0.5647807 0.6000795 0.63537829 0.67067708 0.70597588 0.74127467 0.77657346 0.81187226 0.84717105 0.88246985 0.91776864 0.95306743 0.98836623 1.02366502 1.05896382 1.09426261 1.1295614 1.1648602 1.20015899 1.23545779 1.27075658 1.30605537 1.34135417 1.37665296 1.41195175 1.44725055 1.48254934 1.51784814 1.55314693 1.58844572 1.62374452 1.65904331 1.69434211 1.7296409 1.76493969 1.80023849 1.83553728 1.87083607 1.90613487 1.94143366 1.97673246 2.01203125 2.04733004 2.08262884 2.11792763 2.15322643 2.18852522 2.22382401 2.25912281 2.2944216 2.32972039 2.36501919 2.40031798 2.43561678 2.47091557 2.50621436 2.54151316 2.57681195 2.61211075 2.64740954 2.68270833 2.71800713 2.75330592 2.78860471 2.82390351 2.8592023 2.8945011 2.92979989 2.96509868 3.00039748 3.03569627 3.07099507 3.10629386 3.14159265] [0. 0.03173326 0.06346652 0.09519978 0.12693304 0.1586663 0.19039955 0.22213281 0.25386607 0.28559933 0.31733259 0.34906585 0.38079911 0.41253237 0.44426563 0.47599889 0.50773215 0.53946541 0.57119866 0.60293192 0.63466518 0.66639844 0.6981317 0.72986496 0.76159822 0.79333148 0.82506474 0.856798 0.88853126 0.92026451 0.95199777 0.98373103 1.01546429 1.04719755 1.07893081 1.11066407 1.14239733 1.17413059 1.20586385 1.23759711 1.26933037 1.30106362 1.33279688 1.36453014 1.3962634 1.42799666 1.45972992 1.49146318 1.52319644 1.5549297 1.58666296 1.61839622 1.65012947 1.68186273 1.71359599 1.74532925 1.77706251 1.80879577 1.84052903 1.87226229 1.90399555 1.93572881 1.96746207 1.99919533 2.03092858 2.06266184 2.0943951 2.12612836 2.15786162 2.18959488 2.22132814 2.2530614 2.28479466 2.31652792 2.34826118 2.37999443 2.41172769 2.44346095 2.47519421 2.50692747 2.53866073 2.57039399 2.60212725 2.63386051 2.66559377 2.69732703 2.72906028 2.76079354 2.7925268 2.82426006 2.85599332 2.88772658 2.91945984 2.9511931 2.98292636 3.01465962 3.04639288 3.07812614 3.10985939 3.14159265]
No handles with labels found to put in legend.
Image in a Jupyter notebook
def tracer_erreurs_npen_neu(lst_n): l=[] for n in lst_n : l.append(erreurs_npen_neu(2,2,0,n)) plt.xlabel('valeurs de n en échelle log') plt.legend(loc = 'upper right') plt.title(r'tracer de la courbe derreurs de $u(x)$ pour le cas neumann non pénalisé en échelle log') plt.loglog(lst_n,l) plt.show() tracer_erreurs_npen_neu([20,30,40,50,60,70,80,90,100])
[0. 0.16534698 0.33069396 0.49604095 0.66138793 0.82673491 0.99208189 1.15742887 1.32277585 1.48812284 1.65346982 1.8188168 1.98416378 2.14951076 2.31485774 2.48020473 2.64555171 2.81089869 2.97624567 3.14159265] [0. 0.10833078 0.21666156 0.32499234 0.43332312 0.54165391 0.64998469 0.75831547 0.86664625 0.97497703 1.08330781 1.19163859 1.29996937 1.40830016 1.51663094 1.62496172 1.7332925 1.84162328 1.94995406 2.05828484 2.16661562 2.2749464 2.38327719 2.49160797 2.59993875 2.70826953 2.81660031 2.92493109 3.03326187 3.14159265] [0. 0.08055366 0.16110732 0.24166097 0.32221463 0.40276829 0.48332195 0.5638756 0.64442926 0.72498292 0.80553658 0.88609024 0.96664389 1.04719755 1.12775121 1.20830487 1.28885852 1.36941218 1.44996584 1.5305195 1.61107316 1.69162681 1.77218047 1.85273413 1.93328779 2.01384144 2.0943951 2.17494876 2.25550242 2.33605608 2.41660973 2.49716339 2.57771705 2.65827071 2.73882436 2.81937802 2.89993168 2.98048534 3.061039 3.14159265] [0. 0.06411414 0.12822827 0.19234241 0.25645654 0.32057068 0.38468481 0.44879895 0.51291309 0.57702722 0.64114136 0.70525549 0.76936963 0.83348377 0.8975979 0.96171204 1.02582617 1.08994031 1.15405444 1.21816858 1.28228272 1.34639685 1.41051099 1.47462512 1.53873926 1.60285339 1.66696753 1.73108167 1.7951958 1.85930994 1.92342407 1.98753821 2.05165235 2.11576648 2.17988062 2.24399475 2.30810889 2.37222302 2.43633716 2.5004513 2.56456543 2.62867957 2.6927937 2.75690784 2.82102197 2.88513611 2.94925025 3.01336438 3.07747852 3.14159265] [0. 0.05324733 0.10649467 0.159742 0.21298933 0.26623667 0.319484 0.37273133 0.42597866 0.479226 0.53247333 0.58572066 0.638968 0.69221533 0.74546266 0.79871 0.85195733 0.90520466 0.958452 1.01169933 1.06494666 1.118194 1.17144133 1.22468866 1.27793599 1.33118333 1.38443066 1.43767799 1.49092533 1.54417266 1.59741999 1.65066733 1.70391466 1.75716199 1.81040933 1.86365666 1.91690399 1.97015133 2.02339866 2.07664599 2.12989332 2.18314066 2.23638799 2.28963532 2.34288266 2.39612999 2.44937732 2.50262466 2.55587199 2.60911932 2.66236666 2.71561399 2.76886132 2.82210865 2.87535599 2.92860332 2.98185065 3.03509799 3.08834532 3.14159265] [0. 0.04553033 0.09106066 0.13659098 0.18212131 0.22765164 0.27318197 0.3187123 0.36424263 0.40977295 0.45530328 0.50083361 0.54636394 0.59189427 0.6374246 0.68295492 0.72848525 0.77401558 0.81954591 0.86507624 0.91060657 0.95613689 1.00166722 1.04719755 1.09272788 1.13825821 1.18378854 1.22931886 1.27484919 1.32037952 1.36590985 1.41144018 1.45697051 1.50250083 1.54803116 1.59356149 1.63909182 1.68462215 1.73015248 1.7756828 1.82121313 1.86674346 1.91227379 1.95780412 2.00333445 2.04886477 2.0943951 2.13992543 2.18545576 2.23098609 2.27651642 2.32204674 2.36757707 2.4131074 2.45863773 2.50416806 2.54969839 2.59522871 2.64075904 2.68628937 2.7318197 2.77735003 2.82288036 2.86841068 2.91394101 2.95947134 3.00500167 3.050532 3.09606233 3.14159265] [0. 0.039767 0.07953399 0.11930099 0.15906798 0.19883498 0.23860197 0.27836897 0.31813596 0.35790296 0.39766996 0.43743695 0.47720395 0.51697094 0.55673794 0.59650493 0.63627193 0.67603893 0.71580592 0.75557292 0.79533991 0.83510691 0.8748739 0.9146409 0.95440789 0.99417489 1.03394189 1.07370888 1.11347588 1.15324287 1.19300987 1.23277686 1.27254386 1.31231086 1.35207785 1.39184485 1.43161184 1.47137884 1.51114583 1.55091283 1.59067982 1.63044682 1.67021382 1.70998081 1.74974781 1.7895148 1.8292818 1.86904879 1.90881579 1.94858279 1.98834978 2.02811678 2.06788377 2.10765077 2.14741776 2.18718476 2.22695175 2.26671875 2.30648575 2.34625274 2.38601974 2.42578673 2.46555373 2.50532072 2.54508772 2.58485471 2.62462171 2.66438871 2.7041557 2.7439227 2.78368969 2.82345669 2.86322368 2.90299068 2.94275768 2.98252467 3.02229167 3.06205866 3.10182566 3.14159265] [0. 0.03529879 0.07059759 0.10589638 0.14119518 0.17649397 0.21179276 0.24709156 0.28239035 0.31768914 0.35298794 0.38828673 0.42358553 0.45888432 0.49418311 0.52948191 0.5647807 0.6000795 0.63537829 0.67067708 0.70597588 0.74127467 0.77657346 0.81187226 0.84717105 0.88246985 0.91776864 0.95306743 0.98836623 1.02366502 1.05896382 1.09426261 1.1295614 1.1648602 1.20015899 1.23545779 1.27075658 1.30605537 1.34135417 1.37665296 1.41195175 1.44725055 1.48254934 1.51784814 1.55314693 1.58844572 1.62374452 1.65904331 1.69434211 1.7296409 1.76493969 1.80023849 1.83553728 1.87083607 1.90613487 1.94143366 1.97673246 2.01203125 2.04733004 2.08262884 2.11792763 2.15322643 2.18852522 2.22382401 2.25912281 2.2944216 2.32972039 2.36501919 2.40031798 2.43561678 2.47091557 2.50621436 2.54151316 2.57681195 2.61211075 2.64740954 2.68270833 2.71800713 2.75330592 2.78860471 2.82390351 2.8592023 2.8945011 2.92979989 2.96509868 3.00039748 3.03569627 3.07099507 3.10629386 3.14159265] [0. 0.03173326 0.06346652 0.09519978 0.12693304 0.1586663 0.19039955 0.22213281 0.25386607 0.28559933 0.31733259 0.34906585 0.38079911 0.41253237 0.44426563 0.47599889 0.50773215 0.53946541 0.57119866 0.60293192 0.63466518 0.66639844 0.6981317 0.72986496 0.76159822 0.79333148 0.82506474 0.856798 0.88853126 0.92026451 0.95199777 0.98373103 1.01546429 1.04719755 1.07893081 1.11066407 1.14239733 1.17413059 1.20586385 1.23759711 1.26933037 1.30106362 1.33279688 1.36453014 1.3962634 1.42799666 1.45972992 1.49146318 1.52319644 1.5549297 1.58666296 1.61839622 1.65012947 1.68186273 1.71359599 1.74532925 1.77706251 1.80879577 1.84052903 1.87226229 1.90399555 1.93572881 1.96746207 1.99919533 2.03092858 2.06266184 2.0943951 2.12612836 2.15786162 2.18959488 2.22132814 2.2530614 2.28479466 2.31652792 2.34826118 2.37999443 2.41172769 2.44346095 2.47519421 2.50692747 2.53866073 2.57039399 2.60212725 2.63386051 2.66559377 2.69732703 2.72906028 2.76079354 2.7925268 2.82426006 2.85599332 2.88772658 2.91945984 2.9511931 2.98292636 3.01465962 3.04639288 3.07812614 3.10985939 3.14159265]
No handles with labels found to put in legend.
Image in a Jupyter notebook
def qui(x): result = [] for i in x: if 0<i and i<np.pi : result.append(0) else : result.append(1) return result
def Q(x): if 0 < x and x < np.pi: return 0 else: return 1
ue_pen_dir(0,0.01,2)
def norm_pen_dir(N,test,m,c,eta): h=2*np.pi/(N+1) Y=np.linspace(0.1,2*np.pi,N) A=A2(N) b=[] for i in range(len(Y)): b.append((f(Y[i], test, m) - (1/eta)*Q(Y[i]))) U_p=np.linalg.solve(A,b) return Y,A,U_p Y,A,U_p = norm_pen_dir(20,1,2,0,0.1) plt.plot(Y,U_p)
[<matplotlib.lines.Line2D at 0x7ff11b18ce50>]
Image in a Jupyter notebook
e_p
def trace_pen_dir(N,test,m,c,eta): Y,A,U_p,Ubar_p,e_p=norm_pen_dir(N,test,m,c,eta) plt.plot(Y,U_p,'-*') plt.plot(Y,Ubar_p) trace_pen_dir(50,1,2,1,1)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-120-fdaa63998d4d> in <module> 4 plt.plot(Y,Ubar_p) 5 ----> 6 trace_pen_dir(50,1,2,1,1) <ipython-input-120-fdaa63998d4d> in trace_pen_dir(N, test, m, c, eta) 1 def trace_pen_dir(N,test,m,c,eta): ----> 2 Y,A,U_p,Ubar_p,e_p=norm_pen_dir(N,test,m,c,eta) 3 plt.plot(Y,U_p,'-*') 4 plt.plot(Y,Ubar_p) 5 <ipython-input-119-db74452ca002> in norm_pen_dir(N, test, m, c, eta) 6 for i in range(len(Y)): 7 b.append((f(Y[i], test, m) - (1/eta)*Q(Y[i]))) ----> 8 Ubar_p=ue_pen_dir(Y,eta,m) 9 U_p=np.linalg.solve(A,b) 10 e_p=np.linalg.norm(Ubar_p-U_p,np.infty) <ipython-input-107-7c8a4a981002> in ue_pen_dir(x, eta, m) 27 28 ---> 29 if 0 < x and x < np.pi: 30 return np.sin(m*x)+A1_d*x+A2_d 31 elif np.pi < x and x < 2*np.pi: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
def tracer_sol_exac_pen_dir(lst_eta): l=[] for eta in lst_eta : l.append(ue_pen_dir(1,eta,2)) plt.plot(l,lst_eta) tracer_sol_exac_pen_dir([0.00001,0.0001,0.001,0.01,0.1])
l_eta=[0.0001,0.0001,0.001,0.1] for eta in l_eta : print(ue_pen_dir(1,eta,2))
def conv_dir(eta,m): k=((1/np.pi)*np.exp(-np.pi/np.sqrt(eta)))-((1/np.pi)*np.exp(-2*np.pi/np.sqrt(eta)))+((1/np.sqrt(eta))*np.exp(-2*np.pi/np.sqrt(eta))) k_p=((1/np.pi)*np.exp(np.pi/np.sqrt(eta)))-((1/np.pi)*np.exp(2*np.pi/np.sqrt(eta)))-((1/np.sqrt(eta))*np.exp(2*np.pi/np.sqrt(eta))) k1=((1/np.pi)*np.exp(-np.pi/np.sqrt(eta)))-((1/np.pi)*np.exp(-2*np.pi/np.sqrt(eta)))+((1/np.sqrt(eta))*np.exp(-np.pi/np.sqrt(eta))) k1_p=((1/np.pi)*np.exp(np.pi/np.sqrt(eta)))-((1/np.pi)*np.exp(2*np.pi/np.sqrt(eta)))-((1/np.sqrt(eta))*np.exp(np.pi/np.sqrt(eta))) B2_d=(-k*m*((-1)**m)-k1*m)/((1+eta*m**2)*(k_p*k1-k*k1_p)) B1_d=(1/k)*(-m/(1+eta*m**2)-B2_d*k_p) A1_d=B1_d*((1/np.pi*np.exp(-np.pi/np.sqrt(eta)))-(1/np.pi*np.exp(-2*np.pi/np.sqrt(eta))))+B2_d*((1/np.pi*np.exp(np.pi/np.sqrt(eta)))-(1/np.pi*np.exp(2*np.pi/np.sqrt(eta)))) A2_d=B1_d*np.exp(-2*np.pi/np.sqrt(eta))+B2_d*np.exp(2*np.pi/np.sqrt(eta)) return np.sin((m**2*eta)/(1+eta*m**2)-1)+B1_d*np.exp(-1/np.sqrt(eta))+B2_d*np.exp(1/np.sqrt(eta)) conv_dir(0.0001,2)
l=[0.0000001,0.000001,0.00001,0.0001,0.001,0.01,0.1] l_eta=[] for eta in l : l_eta.append(conv_dir(eta,1)) plt.loglog(l,l_eta) plt.loglog(l,ue_npen(l,1,2,0)) plt.xlabel('valeurs de eta') plt.legend(loc = 'upper right') plt.title(r'tracer de la courbe de convergence de u_eta vers u qaund eta tend vers 0 pour le cas dirichlet')
def conv_neu(eta,m,x,c): B1_n=(1-(-1)**m)/((1+eta)*np.pi) A1_n=eta*B1_n B2_n=(3*np.pi/2)*((((-1)**m)-1)/(1+eta))*((eta/2)+2)+1 A2_n=2*np.pi*B1_n+B2_n-1 return B1_n*x+B2_n-np.cos(m*x)-c
l=np.linspace(0,np.pi,20) plt.plot(l,ue_npen(l,2,2,0)) plt.plot(l,conv_neu(0.1,1,1,0)) plt.xlabel('valeurs de eta') plt.legend(loc = 'upper right') plt.title(r'tracer de la courbe de convergence de u_eta vers u qaund eta tend vers 0 pour le cas NEUMANN')
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-126-fbd33c67edd6> in <module> 4 5 plt.plot(l,ue_npen(l,2,2,0)) ----> 6 plt.plot(l,conv_neu(0.1,1,1,0)) 7 plt.xlabel('valeurs de eta') 8 plt.legend(loc = 'upper right') /ext/anaconda2020.02/lib/python3.7/site-packages/matplotlib/pyplot.py in plot(scalex, scaley, data, *args, **kwargs) 2840 return gca().plot( 2841 *args, scalex=scalex, scaley=scaley, -> 2842 **({"data": data} if data is not None else {}), **kwargs) 2843 2844 /ext/anaconda2020.02/lib/python3.7/site-packages/matplotlib/axes/_axes.py in plot(self, scalex, scaley, data, *args, **kwargs) 1741 """ 1742 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D) -> 1743 lines = [*self._get_lines(*args, data=data, **kwargs)] 1744 for line in lines: 1745 self.add_line(line) /ext/anaconda2020.02/lib/python3.7/site-packages/matplotlib/axes/_base.py in __call__(self, data, *args, **kwargs) 271 this += args[0], 272 args = args[1:] --> 273 yield from self._plot_args(this, kwargs) 274 275 def get_next_color(self): /ext/anaconda2020.02/lib/python3.7/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs) 397 398 if x.shape[0] != y.shape[0]: --> 399 raise ValueError(f"x and y must have same first dimension, but " 400 f"have shapes {x.shape} and {y.shape}") 401 if x.ndim > 2 or y.ndim > 2: ValueError: x and y must have same first dimension, but have shapes (20,) and (1,)
Image in a Jupyter notebook