Solución numérica al problema del primer valor límite elíptico de segundo orden (formato de diferencia de cinco puntos y método de volumen finito) con código matlab

Solución numérica al problema del primer valor límite elíptico de segundo orden (formato de diferencia de cinco puntos y método de volumen finito) con código matlab

Aquí presentamos el problema de encontrar el primer valor límite de una elipse usando el formato de diferencia de cinco puntos y el método de volumen finito. El
título:
Usando el formato de diferencia de cinco puntos y el método de volumen finito para encontrar el primer valor límite de una elipse elipse usando una cuadrícula rectangular respectivamente:
− ∂ 2 u ∂ x 2 − ∂ 2 u ∂ y 2 + a ∂ u ∂ x = 0 , a > 0 , -\frac{\partial^2u}{\partial x^2} -\frac{\partial^2u}{\partial y^2}+a\frac{\partial u}{\partial x}=0,a>0,x22 yy22 y+ax tu=0 ,a>0 ,
u ( 0 , y ) = sin ( π y ) , u ( 1 , y ) = 0 , 0 < y < 1 , u\left(0,y\right)=sin\left(\pi y\right ),u\izquierda(1,y\derecha)=0,0<y<1,tu( 0 ,y )=está en( π y ),tu( 1 ,y )=0 ,0<y<1 ,
u ( x , 0 ) = u ( x , 1 ) = 0 , 0 < x < 1. u\left(x,0\right)=u\left(x,1\right)=0,0< x<1.tu( x ,0 )=tu( x ,1 )=0 ,0<X<1.

Tomando el parámetro a = 40, se obtiene el error máximo y el orden de convergencia de diferentes grillas.

análisis del problema

(i) Método de diferencia de cinco puntos para una cuadrícula rectangular:
Paso 1: División de la cuadrícula. Las longitudes de los pasos a lo largo de los ejes x e y se determinan como: hx, hy h_x,h_yhx,hy, para facilitar el cálculo, tomamos hx = hy h_x=h_yhx=hy, h = hx 2 + hy 2 h =\sqrt{h_x^2+h_y^2}h=hX2+hy2 , dibuja dos familias de rectas paralelas a los ejes x e y x = xi, y = yix=x_i,y=y_iX=Xyo,y=yyo,其中xi = x 0 + ihx , i = 0 , 1 , 2 , ⋯ , N , yj = y 0 + jhy , j = 0 , 1 , 2 , ⋯ , N x_i=x_0+ih_x,i=0,1 ,2,\cdots,N,y_j=y_0+jh_y,j=0,1,2,\cdots,NXyo=X0+yo hx,i=0 ,1 ,2 ,,norte ,yj=y0+jh _y,j=0 ,1 ,2 ,,N , el punto de intersección de las dos familias de rectas(ihx, jhy) (ih_x,jh_y)( yo hx,jh _y) se denomina punto o nodo de la red y se registra como(xi, yj) (x_i, y_j)( xyo,yj)
Paso 2: Discretización del operador diferencialnodo
regular(xi, yj) (x_i, y_j)( xyo,yj) a lo largo de las direcciones x e y respectivamente, use la fórmula del cociente de diferencias centrales para calcularuxx u_{xx}tuxxuyy u_{yy}tuyyAproximación del trabajo, fórmula del caso diferencial de cinco puntos:
− ( ui + 1 , j − 2 ui , j + ui − 1 , jhx 2 + ui , j + 1 − 2 ui , j + ui , j − 1 hy 2 ) + aui + 1 , j − ui − 1 , j 2 hx = 0 -\left(\frac{u_{i+1,j}-2u_{i,j}+u_{i-1,j}}{ h_x^ 2}+\frac{u_{i,j+1}-2u_{i,j}+u_{i,j-1}}{h_y^2}\right)+a\frac{u_{i+ 1,j }-u_{i-1,j}}{2h_x}=0(hX2tuyo + 1 , j2 yyo , j+ tuyo 1 , j+hy2tuyo , j + 12 yyo , j+ tuyo , j 1)+a2 horasxtuyo + 1 , jyo 1 , j=0
⇒ \flecha derecha
( − 1 hx 2 − a 2 hx ) ui − 1 , j + ( 2 hx 2 + 2 hy 2 ) ui , j + ( − 1 hx 2 + a 2 hx ) ui + 1 , j + ( − 1 hy 2 ) ui , j − 1 + ( − 1 hy 2 ) ui , j + 1 = 0 , i , j = 1 , 2 , ⋯ , N − 1 \left(-\frac{1}{h_x^2}- \frac{a}{2h_x}\right)u_{i-1,j}+\left(\frac{2}{h_x^2}+\frac{2}{h_y^2}\right)u_{i ,j}+\left(-\frac{1}{h_x^2}+\frac{a}{2h_x}\right)u_{i+1,j}+\left(-\frac{1}{h_y ^2}\right)u_{i,j-1}+\left(-\frac{1}{h_y^2}\right)u_{i,j+1}=0,i,j=1,2 ,\cdots,N-1( -hX212 horasxun)tuyo 1 , j+(hX22+hy22)tuyo , j+( -hX21+2 horasxun)tuyo + 1 , j+( -hy21)tuyo , j 1+( -hy21)tuyo , j + 1=0 ,yo ,j=1 ,2 ,,norte1
Sea
A = [ 2 hx 2 + 2 hy 2 − 1 hx 2 + a 2 hx 0 ⋯ 0 0 − 1 hx 2 − a 2 hx 2 hx 2 + 2 hy 2 − 1 hx 2 + a 2 hx ⋯ 0 0 ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ 0 0 0 ⋯ − 1 hx 2 − a 2 hx 2 hx 2 + 2 hy 2 ] A=\left[\begin{matrix}\frac{2}{h_x^2}+\frac{ 2}{h_y^2}&-\frac{1}{h_x^2}+\frac{a}{2h_x}&0&\cdots&0&0\\-\frac{1}{h_x^2}-\frac{a} {2h_x}&\frac{2}{h_x^2}+\frac{2}{h_y^2}&-\frac{1}{h_x^2}+\frac{a}{2h_x}&\cdots&0&0\ \\cdots&\cdots&\cdots&\cdots&\cdots&\cdots\\0&0&0&\cdots&-\frac{1}{h_x^2}-\frac{a}{2h_x}&\frac{2}{h_x^2}+ \frac{2}{h_y^2}\\\end{matrix}\right]A= hX22+hy22hX212 horasxun0hX21+2 horasxunhX22+hy2200hX21+2 horasxun000hX212 horasxun00hX22+hy22
es un ( N − 1 ) × ( N − 1 ) \left(N-1\right)\times\left(N-1\right)( norte1 )×( norte1 ) Matriz,

B = [ − 1 hy 2 0 ⋯ 0 0 − 1 hy 2 ⋯ 0 ⋯ ⋯ ⋯ ⋯ 0 0 ⋯ − 1 hy 2 ] 是一个 ( N − 1 ) × ( N − 1 ) B=\left[\begin{ matriz}-\frac{1}{h_y^2}&0&\cdots&0\\0&-\frac{1}{h_y^2}&\cdots&0\\\cdots&\cdots&\cdots&\cdots\\0&0&\cdots&-\ frac{1}{h_y^2}\\\end{matrix}\right]是一个\left(N-1\right)\times\left(N-1\right)B= hy21000hy21000hy21 Es un( norte1 )×( norte1 )矩阵,
K = [ AB 0 ⋯ 0 0 0 BAB ⋯ 0 0 0 ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ 0 0 0 ⋯ 0 BA ] , K=\left[\begin{matrix}A&B&0&\cdots&0&0&0\\\ B&A&B& \cdots&0&0&0\\\cdots&\cdots&\cdots&\cdots&\cdots&\cdots&\cdots\\0&0&0&\cdots&0&B&A\\\end{matrix}\right],k= A B0BA00B000000B00un , es un( N − 1 ) 2 × ( N − 1 ) 2 \left(N-1\right)^2\times\left(N-1\right)^2( norte1 )2×( norte1 )2矩阵,
b 1 = ( ( 1 hx 2 + a 2 hx ) u 0 , 1 + 1 hy 2 u 1 , 0 , 1 hy 2 u 2 , 0 , ⋯ , 1 hy 2 u N − 2 , 0 , 1 hy 2 u N − 1 , 0 + ( 1 hx 2 − a 2 hx ) u N , 1 ) T b_1=\left(\left(\frac{1}{h_x^2}+\frac{a}{2h_x }\right)u_{0,1}+{\frac{1}{h_y^2}u}_{1,0},{\frac{1}{h_y^2}u}_{2,0} ,\cdots,{\frac{1}{h_y^2}u}_{N-2,0},{\frac{1}{h_y^2}u}_{N-1,0}+\left (\frac{1}{h_x^2}-\frac{a}{2h_x}\right)u_{N,1}\right)^Tb1=( (hX21+2 horasxun)tu0 , 1+hy21tu1 , 0,hy21tu2 , 0,,hy21tunorte 2 , 0,hy21tunorte 1 , 0+(hX212 horasxun)tunorte , 1)T ,
bi = ( ( 1 hx 2 + a 2 hx ) u 0 , i , 0 , ⋯ , 0 , ( 1 hx 2 − a 2 hx ) u N , i ) T , i = 2 , 3 , ⋯ , N − 2 , b norte − 1 = ( ( 1 hx 2 + a 2 hx ) u 0 , norte − 1 + 1 hy 2 u 1 , norte , 1 hy 2 u 2 , norte , ⋯ , 1 hy 2 u norte − 2 , N , 1 hy 2 u N − 1 , N + ( 1 hx 2 − a 2 hx ) u N , N − 1 ) T b_i=\left(\left(\frac{1}{h_x^2}+\ frac{a}{2h_x}\right)u_{0,i},0,\cdots,0,\left(\frac{1}{h_x^2}-\frac{a}{2h_x}\right)u_ {N,i}\right)^T,i=2,3,\cdots,N-2, b_{N-1}=\left(\left(\frac{1}{h_x^2}+\frac {a}{2h_x}\right)u_{0,N-1}+{\frac{1}{h_y^2}u}_{1,N}\ ,{\ \frac{1}{\ h_y^ 2}u}_{2,N}\ ,\ \cdots,\ {\frac{1}{h_y^2}u}_{N-2,N},{\frac{1}{h_y^2} u}_{N-1,N}+\left(\frac{1}{h_x^2}-\frac{a}{2h_x}\right)u_{N,N-1}\right)^Tbyo=( (hX21+2 horasxun)tu0 , yo,0 ,,0 ,(hX212 horasxun)tunorte , yo)t,i=2 ,3 ,,norte2 ,bnorte - 1=( (hX21+2 horasxun)tu0 , norte 1+hy21tu1 , norte ,  hy21tu2 , norte , , hy21tunorte 2 , norte,hy21tunorte 1 , norte+(hX212 horasxun)tunorte , norte - 1)T ,
segundo = ( segundo 1 , segundo 2 , ⋯ , segundo norte - 1 ) T , U = ( tu 1 , 1 , tu 2 , 1 , ⋯ tu norte - 1 , 1 , tu 1 , 2 , tu 2 , 2 , ⋯ , u N − 1 , 2 , ⋯ u 1 , N − 1 , u 2 , N − 1 , ⋯ u N − 1 , N − 1 ) T b=\left(b_1,b_2,\cdots,b_{ N-1}\right)^T, U =\left(u_{1,1},u_{2,1},\cdots u_{N-1,1,}u_{1,2},{u_{ 2,2},\cdots,u_{N-1,2},\cdots u_{1,N-1},u_{2,N-1},\cdots u_{N-1,N-1}} \derecha)^Tb=( segundo1,b2,,bnorte - 1)t,Ud.=( 1 , 1,tu2 , 1,tunorte 1 , 1 ,tu1 , 2,tu2 , 2,,tunorte 1 , 2,tu1 , norte 1,tu2 , norte 1,tunorte - 1 , norte - 1)T .
因此,KU=b,解出U即可。
在本题中,因为
u ( 0 , y ) = sin ( π y ) , u ( 1 , y ) = 0 , 0 < y < 1 , u ( x , 0 ) = u ( x , 1 ) = 0 , 0 < x < 1 u\left(0,y\right)=sin\left(\pi y\right),u\left(1,y\right) =0,0<y<1,\ u\left(x,0\right)=u\left(x,1\right)=0,0<x<1tu( 0 ,y )=está en( π y ),tu( 1 ,y )=0 ,0<y<1 , tu( x ,0 )=tu( x ,1 )=0 ,0<X<1 .
所以
b 1 = ( ( 1 hx 2 + a 2 hx ) sin ( π y 1 ) , 0 , ⋯ , 0 , 0 ) T , bi = ( ( 1 hx 2 + a 2 hx ) sin ( π yi ) , 0 , ⋯ , 0 , 0 ) T , i = 2 , 3 , ⋯ , N − 2 , b N − 1 = ( ( 1 hx 2 + a 2 hx ) sin ( π y N − 1 ) , 0 , ⋯ , 0 , 0 ) T b_1=\left(\left(\frac{1}{h_x^2}+\frac{a}{2h_x}\right)sin\left(\pi y_1\right),0,\ cdots,0,0\right)^T, b_i=\left(\left(\frac{1}{h_x^2}+\frac{a}{2h_x}\right)sin\left(\pi y_i\right ),0,\cdots,0,0\right)^T,i=2,3,\cdots,N-2, b_{N-1}=\left(\left(\frac{1}{h_x^ 2}+\frac{a}{2h_x}\right)sin\left(\pi y_{N-1}\right)\ ,0\ ,\ \cdots,0,0\right)^Tb1=( (hX21+2 horasxun)está en( π y1),0 ,,0 ,0 )t,byo=( (hX21+2 horasxun)está en( π yyo),0 ,,0 ,0 )t,i=2 ,3 ,,norte2 ,bnorte - 1=( (hX21+2 horasxun)está en( π ynorte - 1) ,0 ,  ,0 ,0 )T. _

(ii) Método de volúmenes finitos
Necesitamos hacer una descomposición dual. Denota xi − 1 2 = ( i − 1 2 ) hx , yj − 1 2 = ( j − 1 2 ) hy x_{i-\frac{1}{2}}=\left(i-\frac{1} {2}\right)h_x,y_{j-\frac{1}{2}}=\left(j-\frac{1}{2}\right)h_yXyo -21=( yo21)hx,yj- _21=( j21)hy
Para cualquier punto interior regular (xi, yj) (x_i, y_j)( xyo,yj) Considere los puntos de malla dual:A (xi − 1 2 , yj − 1 2 ) , B ( xi + 1 2 , yj − 1 2 ) , C ( xi + 1 2 , yj + 1 2 ) , D ( xi − 1 2 , yj + 1 2 ) A(x_{i-\frac{1}{2}},y_{j-\frac{1}{2}}),B(x_{i+\frac{1 } {2}},y_{j-\frac{1}{2}}),C(x_{i+\frac{1}{2}},y_{j+\frac{1}{2}}), D (x_{i-\frac{1}{2}},y_{j+\frac{1}{2}})un ( xyo -21,yj- _21) ,segundo ( xyo +21,yj- _21) ,C ( xyo +21,yj +21) ,re ( xyo -21,yj +21) ,用G ij G_{ij}GRAMOyoRepresenta un dominio rectangular con A, B, C y D como vértices, ∂ G ij \partial G_{ij}∂G _yoComo límite, usando la fórmula de Green, tenemos
− ∫ ∂ G ij ∂ u ∂ n + ∫ ∫ G ija ∂ u ∂ xdxdy = 0 -\int_{\partial G_{ij}}\frac{\partial u}{\ n parcial}+\int\int_{G_{ij}}{a\frac{\partial u}{\partial x}dxdy}=0∂G _yonorte tu+GRAMOyoax tud x d y=0
⇒ \flecha derecha
ui, j − ui, j − 1 hyhx + ui, j − ui + 1, jhxhy + ui, j − ui, j + 1 hyhx + ui, j − ui − 1, jhxhy + a 2 (ui + 1, j − ui − 1 , j ) hy = 0 \frac{u_{i,j}{-u}_{i,j-1}}{h_y}h_x+\frac{u_{i,j}-u_{i +1,j}}{h_x}h_y+\frac{u_{i,j}{-u}_{i,j+1}}{h_y}h_x+\frac{u_{i,j}{-u}_ {i-1,j}}{h_x}h_y+\frac{a}{2}{(u}_{i+1,j}-u_{i-1,j})h_y=0hytuyo , jyo , j 1hx+hxtuyo , jyo + 1 , jhy+hytuyo , jyo , j + 1hx+hxtuyo , jyo 1 , jhy+2un( yo + 1 , jtuyo 1 , j) hy=0
⇒ \flecha derecha
( − hyhx − a 2 hy ) ui − 1 , j + ( 2 hxhy + 2 hyhx ) ui , j + ( − hyhx + a 2 hy ) ui + 1 , j − hxhyui , j − 1 − hxhyui , j + 1 = 0 (-{\frac{h_y}{h_x}-\frac{a}{2}h_y)u}_{i-1,j}+{\left(\frac{2h_x}{h_y}+\ frac{2h_y}{h_x}\right)u}_{i,j}+(-{\frac{h_y}{h_x}+\frac{a}{2}h_y)u}_{i+1,j }-\frac{h_x}{h_y}u_{i,j-1}-\frac{h_x}{h_y}u_{i,j+1}=0( -hxhy2unhy) tuyo 1 , j+(hy2 horasx+hx2 horasy)tuyo , j+( -hxhy+2unhy) tuyo + 1 , jhyhxtuyo , j 1hyhxtuyo , j + 1=0
Sea
A = [ 2 hxhy + 2 hyhx − hyhx + a 2 hy 0 ⋯ 0 0 − hyhx − a 2 hy 2 hxhy + 2 hyhx − hyhx + a 2 hy ⋯ 0 0 ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ 0 0 0 ⋯ − hyhx − a 2 hy 2 hxhy + 2 hyhx ] A=\left[\begin{matrix}\frac{2h_x}{h_y}+\frac{2h_y}{h_x}&-\frac{h_y}{h_x}+ \frac{a}{2}h_y&0&\cdots&0&0\\-\frac{h_y}{h_x}-\frac{a}{2}h_y&\frac{2h_x}{h_y}+\frac{2h_y}{h_x}& -\frac{h_y}{h_x}+\frac{a}{2}h_y&\cdots&0&0\\\cdots&\cdots&\cdots&\cdots&\cdots&\cdots\\0&0&0&\cdots&-\frac{h_y}{h_x}- \frac{a}{2}h_y&\frac{2h_x}{h_y}+\frac{2h_y}{h_x}\\\end{matrix}\right]A= hy2 horasx+hx2 horasyhxhy2unhy0hxhy+2unhyhy2 horasx+hx2 horasy00hxhy+2unhy000hxhy2unhy00hy2 horasx+hx2 horasy
es un ( N − 1 ) × ( N − 1 ) \left(N-1\right)\times\left(N-1\right)( norte1 )×( norte1 )矩阵,
B = [ − hxhy 0 ⋯ 0 0 − hxhy ⋯ 0 ⋯ ⋯ ⋯ ⋯ 0 0 ⋯ − hxhy ] 为一个 ( N − 1 ) × ( N − 1 ) B=\left[\begin{matrix} -\frac{h_x}{h_y}&0&\cdots&0\\0&-\frac{h_x}{h_y}&\cdots&0\\\cdots&\cdots&\cdots&\cdots\\0&0&\cdots&-\frac{h_x}{h_y }\\\end{matrix}\right] 为一个\left(N-1\right)\times\left(N-1\right)B= hyhx000hyhx000hyhx para uno( norte1 )×( norte1 )矩阵,
K = [ AB 0 ⋯ 0 0 0 BAB ⋯ 0 0 0 ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ ⋯ 0 0 0 ⋯ 0 BA ] , K=\left[\begin{matrix}A&B&0&\cdots&0&0&0\\\ B&A&B& \cdots&0&0&0\\\cdots&\cdots&\cdots&\cdots&\cdots&\cdots&\cdots\\0&0&0&\cdots&0&B&A\\\end{matrix}\right],k= A B0BA00B000000B00un , es un( N − 1 ) 2 × ( N − 1 ) 2 \left(N-1\right)^2\times\left(N-1\right)^2( norte1 )2×( norte1 )2矩阵,
b 1 = ( ( a 2 hy + hyhx ) u 0 , 1 + hxhyu 1 , 0 , hxhyu 2 , 0 , ⋯ , hxhyu N − 2 , 0 , hxhyu N − 1 , 0 + ( hyhx − a 2 hy ) u N , 1 ) T , b_1=\left((\frac{a}{2}h_y+\frac{h_y}{h_x}{)u}_{0,1}+{\frac{h_x}{ h_y}u}_{1,0},\ {\frac{h_x}{h_y}u}_{2,0},\cdots,\ {\frac{h_x}{h_y}u}_{N-2 ,0},{\ \frac{h_x}{h_y}u}_{N-1,0}+(\frac{h_y}{h_x}-\frac{a}{2}h_y)u_{N,1 }\derecha)^T,b1=( (2unhy+hxhy) tu0 , 1+hyhxtu1 , 0, hyhxtu2 , 0,, hyhxtunorte 2 , 0, hyhxtunorte 1 , 0+(hxhy2unhy) tunorte , 1)t,
bi = ( ( a 2 hy + hyhx ) u 0 , i , 0 , ⋯ , 0 , ( hyhx − a 2 hy ) u N , i ) T , i = 2 , 3 , ⋯ , N − 2 , b N − 1 = ( ( a 2 hy + hyhx ) u 0 , N − 1 + hxhy u 1 , N , ⋯ , hxhyu N − 2 , N , hxhyu N − 1 , N + ( hyhx − a 2 hy ) u N , N − 1 ) T , b_i=\left((\frac{a}{2}h_y+\frac{h_y}{h_x}{)u}_{0,i},0,\cdots,0,(\frac {h_y}{h_x}-\frac{a}{2}h_y)u_{N,i}\right)^T,i=2,3,\cdots,N-2, b_{N-1}=\ izquierda((\frac{a}{2}h_y+\frac{h_y}{h_x}{)u}_{0,N-1}\ +\frac{h_x}{h_y}\ u_{1,N}, \ \cdots,\ {\frac{h_x}{h_y}u}_{N-2,N},{\frac{h_x}{h_y}u}_{N-1,N}+(\frac{h_y }{h_x}-\frac{a}{2}h_y)u_{N,N-1}\right)^T,byo=( (2unhy+hxhy) tu0 , yo,0 ,,0 ,(hxhy2unhy) tunorte , yo)t,i=2 ,3 ,,norte2 ,bnorte - 1=( (2unhy+hxhy) tu0 , norte 1 +hyhx tu1 , norte, , hyhxtunorte 2 , norte,hyhxtunorte 1 , norte+(hxhy2unhy) tunorte , norte - 1)t,
segundo = ( segundo 1 , segundo 2 , ⋯ , segundo norte - 1 ) T , U = ( tu 1 , 1 , tu 2 , 1 , ⋯ tu norte - 1 , 1 , tu 1 , 2 , tu 2 , 2 , ⋯ , tu norte - 1 , 2 , ⋯ tu 1 , norte - 1 , tu 2 , norte - 1 , ⋯ tu norte - 1 , norte - 1 ) T . b=\left(b_1,b_2,\cdots,b_{N-1}\right)^T, U =\left(u_{1,1},u_{2,1},\cdots u_{N-1 ,1,}u_{1,2},{u_{2,2},\cdots,u_{N-1,2},\cdots u_{1,N-1},u_{2,N-1} ,\cdots u_{N-1,N-1}}\right)^T.b=( segundo1,b2,,bnorte - 1)t,Ud.=( 1 , 1,tu2 , 1,tunorte 1 , 1 ,tu1 , 2,tu2 , 2,,tunorte 1 , 2,tu1 , norte 1,tu2 , norte 1,tunorte - 1 , norte - 1)t.

Por lo tanto, KU=b, simplemente resuelve para U.

在本题中,因为
u ( 0 , y ) = sin ( π y ) , u ( 1 , y ) = 0 , 0 < y < 1 , u ( x , 0 ) = u ( x , 1 ) = 0 , 0 < x < 1. u\left(0,y\right)=sin\left(\pi y\right),u\left(1,y\right)=0,0<y<1,\ u\left (x,0\right)=u\left(x,1\right)=0,0<x<1.tu( 0 ,y )=está en( π y ),tu( 1 ,y )=0 ,0<y<1 , tu( x ,0 )=tu( x ,1 )=0 ,0<X<1.
所以
b 1 = ( ( a 2 hy + hyhx ) sin ( π y 1 ) , 0 , ⋯ , 0 , 0 ) T , bi = ( ( a 2 hy + hyhx ) sin ( π yi ) , 0 , ⋯ , 0 , 0 ) T , i = 2 , 3 , ⋯ , N − 2 , b N − 1 = ( ( a 2 hy + hyhx ) sin ( π y N − 1 ) , 0 , ⋯ , 0 , 0 ) T . b_1=\left(\left(\frac{a}{2}h_y+\frac{h_y}{h_x}\right)sin\left(\pi y_1\right),0,\cdots,0,0\right) ^T,\\ b_i=\left(\left(\frac{a}{2}h_y+\frac{h_y}{h_x}\right)sin\left(\pi y_i\right),0,\cdots,0 ,0\right)^T,i=2,3,\cdots,N-2,\\ b_{N-1}=\left(\left(\frac{a}{2}h_y+\frac{h_y} {h_x}\right)sin\left(\pi y_{N-1}\right)\ ,0\ ,\ \cdots,0,0\right)^T.b1=( (2unhy+hxhy)está en( π y1),0 ,,0 ,0 )t,byo=( (2unhy+hxhy)está en( π yyo),0 ,,0 ,0 )t,i=2 ,3 ,,norte2 ,bnorte - 1=( (2unhy+hxhy)está en( π ynorte - 1) ,0 ,  ,0 ,0 )t.

Para obtener los órdenes de convergencia de los dos formatos, tomamos N = 8,16,32,64 respectivamente y encontramos el error máximo correspondiente a diferentes N,
ϵ max N = max (∣ vi, j − ui, j∣ ), i, j = 1, 2, ⋯, N − 1. Entre ellos, ui, j son las soluciones numéricas en (xi, yj), vi, j son las soluciones analíticas en (xi, yj). El incremento del número de división N son todas relaciones dobles, es decir, la potencia de N aumenta con 2 como base. Según el conocimiento teórico del análisis numérico, la fórmula de cálculo del orden de convergencia es: s N = log 2 ( ϵ max N ϵ max 2 N ) \epsilon_{max}^ N=max\left(\left|v_{i,j}-u_{i,j}\right|\right), i,j=1,2,\ cdots,N-1. Entre ellos, u_{i, j} es la solución numérica en (x_i, y_j), y v_{i,j} es la solución analítica en (x_i, y_j). Dado que los incrementos de la división El número N es 2 veces, es decir, con 2 aumenta la potencia de la base N. Según el conocimiento teórico del análisis numérico, la fórmula de cálculo del orden de convergencia es: s_N=log_2\left(\frac{\epsilon_{max}^ N}{\epsilon_{max}^{2N}}\derecha)ϵmáximo _norte=máximo _( ∣v _yo , jtuyo , j ),yo ,j=1 ,2 ,,norte1. Entre ellos, yo , jpara ( xyo,yj) , vyo , jpara ( xyo,yj) , dado que los incrementos del número de división N son todos 2 veces, es decir, aumentan a la potencia N de base 2 , se puede saber a partir del conocimiento teórico del análisis numérico que la fórmula de cálculo del orden de convergencia es: snorte=iniciar sesión _2(ϵmáximo _2 norteϵmáximo _norte)

Todos los códigos son los siguientes (matlab)

function [E,U,xx,yy]=Fivepoints(N)%五点差分法
fun=inline('sin(pi*y)');
x0=0;
x1=1
y0=0;
y1=1;
h=1/N;
x=zeros(1,N);
x(1)=x0+h;
for i=1:(N-1)
    x(i+1)=x(i)+h;
end
y=zeros(1,N);
y(1)=y0+h;
for i=1:(N-1)
    y(i+1)=y(i)+h;
end
A=zeros(N-1,N-1);
A(1,1)=4/(h*h);
A(1,2)=-1/(h*h)+20/h;
A(N-1,N-1)=4/(h*h);
A(N-1,N-2)=-1/(h*h)-20/h;
for i=2:(N-2)
        A(i,i)=4/(h*h);
        A(i,i+1)=-1/(h*h)+20/h;
        A(i,i-1)=-1/(h*h)-20/h;
end
B=zeros(N-1,N-1);
for i=1:(N-1)
    B(i,i)=-1/(h*h);
end
K=kron(diag(ones(1,N-2),1)+diag(ones(1,N-2),-1),B)+kron(diag(ones(1,N-1)),A);
b=zeros(1,(N-1)*(N-1));
for i=1:(N-1)
    b((i-1)*(N-1)+1)=(1/(h*h)+20/h)*feval(fun,y(i));
end
U=K\b';
for i=1:(N-1)
    for j=1:(N-1)
        yy(1,(i-1)*(N-1)+j)=y(i);
    end
end
for i=1:(N-1)
    for j=1:(N-1)
        xx(1,(i-1)*(N-1)+j)=x(j);
    end
end
fun1=inline('sin(pi.*y).*(-exp(20+sqrt(400+pi*pi))/(exp(20-sqrt(400+pi*pi))-exp(20+sqrt(400+pi*pi)))*(exp(20-sqrt(400+pi*pi))).^x+exp(20-sqrt(400+pi*pi))/(exp(20-sqrt(400+pi*pi))-exp(20+sqrt(400+pi)))*(exp(20+sqrt(400+pi))).^x)','x','y');
for i=1:(N-1)*(N-1)
    z(i)=feval(fun1,xx(i),yy(i));
    e(i)=abs(U(i)-z(i));
end
E=max(e);

function [E,U,xx,yy]=V2(N)%有限体积法
fun=inline('sin(pi*y)');
x0=0;
x1=1
y0=0;
y1=1;
h=1/N;
x=zeros(1,N);
x(1)=x0+h;
for i=1:(N-1)
    x(i+1)=x(i)+h;
end
y=zeros(1,N);
y(1)=y0+h;
for i=1:(N-1)
    y(i+1)=y(i)+h;
end
A=zeros(N-1,N-1);
A(1,1)=4;
A(1,2)=-1+20*h;
A(N-1,N-1)=4;
A(N-1,N-2)=-1-20*h;
for i=2:(N-2)
        A(i,i)=4;
        A(i,i+1)=-1+20*h;
        A(i,i-1)=-1-20*h;
end
B=zeros(N-1,N-1);
for i=1:(N-1)
    B(i,i)=-1;
end
K=kron(diag(ones(1,N-2),1)+diag(ones(1,N-2),-1),B)+kron(diag(ones(1,N-1)),A);
b=zeros(1,(N-1)*(N-1));
for i=1:(N-1)
    b((i-1)*(N-1)+1)=(20*h+1)*feval(fun,y(i));
end
U=K\b';
for i=1:(N-1)
    for j=1:(N-1)
        yy(1,(i-1)*(N-1)+j)=y(i);
    end
end
for i=1:(N-1)
    for j=1:(N-1)
        xx(1,(i-1)*(N-1)+j)=x(j);
    end
end
fun1=inline('sin(pi.*y).*(-exp(20+sqrt(400+pi*pi))/(exp(20-sqrt(400+pi*pi))-exp(20+sqrt(400+pi*pi)))*(exp(20-sqrt(400+pi*pi))).^x+exp(20-sqrt(400+pi*pi))/(exp(20-sqrt(400+pi*pi))-exp(20+sqrt(400+pi)))*(exp(20+sqrt(400+pi))).^x)','x','y');
for i=1:(N-1)*(N-1)
    z(i)=feval(fun1,xx(i),yy(i));
    e(i)=abs(U(i)-z(i));
end
E=max(e);

%调试
clear all;clc;close  all;
[E,U1,xx1,yy1]=Fivepoints(20);%五点差分法
[E,U2,xx2,yy2]=V2(20);%有限体积法
[X1,Y1,Z1]=griddata(xx1,yy1,U1,linspace(0,1,20)',linspace(0,1,20),'v4');%插值
[X2,Y2,Z2]=griddata(xx2,yy2,U2,linspace(0,1,20)',linspace(0,1,20),'v4');%插值
subplot(2,2,1);
surf(X1,Y1,Z1)%三维曲面
title('五点差分法');
hold on;
subplot(2,2,2);
surf(X2,Y2,Z2)%三维曲面
title('有限体积法');
[x,y]=meshgrid(0:1/20:1);
z=sin(pi.*y).*(-exp(20+sqrt(400+pi*pi))/(exp(20-sqrt(400+pi*pi))-exp(20+sqrt(400+pi*pi)))*(exp(20-sqrt(400+pi*pi))).^x+exp(20-sqrt(400+pi*pi))/(exp(20-sqrt(400+pi*pi))-exp(20+sqrt(400+pi)))*(exp(20+sqrt(400+pi))).^x);
subplot(2,2,3);
mesh(x,y,z);%画出精确解
title('解析解');
N=[8,16,32,64];
for i=1:4
    e1(i,1)=Fivepoints(N(i));
    e2(i,1)=V2(N(i));
end
for i=1:3
    s1(i,1)=log2(e1(i,1)/e1(i+1,1));
    s2(i,1)=log2(e2(i,1)/e2(i+1,1));
end

Resultado de la pregunta

(Cuando N=20, h=0,05, las imágenes de los dos métodos y la solución analítica son las siguientes)

Insertar descripción de la imagen aquí
De la figura, encontramos que la solución numérica es muy consistente con la imagen de la solución analítica. Para obtener el orden de convergencia de los dos métodos, encontramos el error máximo correspondiente a N = 8,16,32,64 y utilizamos la fórmula de cálculo del orden de convergencia: s N = log 2 ( ϵ max N ϵ max 2 N ) s_N=log_2\ izquierda(\frac{\epsilon_{max}^N}{\epsilon_{max}^{2N}}\right)snorte=iniciar sesión _2(ϵmáximo _2 norteϵmáximo _norte) para calcular el orden de convergencia.
Insertar descripción de la imagen aquí
Insertar descripción de la imagen aquí
En la primera tabla, podemos ver que los errores máximos de los dos métodos son muy similares e inicialmente se determina que los dos métodos tienen el mismo orden de convergencia. Luego se utiliza la fórmula de cálculo del orden de convergencia. De los resultados del cálculo, se puede ver que a medida que aumenta el valor N, los órdenes de convergencia de los dos métodos se acercan cada vez más a 2, lo que ilustra que el orden de convergencia de los cinco- El método de diferencia de puntos y el método de volumen finito es de 2 órdenes.

Supongo que te gusta

Origin blog.csdn.net/Sophiayinqianbao/article/details/128407019
Recomendado
Clasificación