求解PDE并计算部分衍生物
This example shows how to solve a transistor partial differential equation (PDE) and use the results to obtain partial derivatives that are part of solving a larger problem.
考虑PDE
这个方程式在晶体管理论[1]中产生,并且 is a function describing the concentration of excess charge carriers (or孔)在PNP晶体管的底部。 一个nd 一个re physical constants. The equation holds on the interval 时间 。
The initial condition includes a constant 并给出
该问题具有给出的边界条件
For fixed ,方程的解决方案 desCribes the collapse of excess charge as 。This collapse produces a current, called the发射器排放电流,还有另一个常数 :
该方程对 d你eto the inconsistency in the boundary values at 为了 一个nd 。自从the PDE has a closed-form series solution for ,您可以通过分析和数值计算发射器放电电流,并比较结果。
要在MATLAB中解决此问题,您需要编码PDE方程,初始条件和边界条件,然后在调用求解器之前选择合适的解决方案网格pdepe
。您要么可以将所需的函数作为文件末尾的本地函数包含(如在此处完成),要么将其保存为单独的命名文件,在MATLAB路径上的目录中命名文件。
deFine Physical Constants
To keep track of the physical constants, create a structure array with fields for each one. When you later define functions for the equations, the initial condition, and the boundary conditions, you can pass in this structure as an extra argument so that the functions have access to the constants.
c.l = 1;C.D = 0.1;c.eta = 10;C.K = 1;c.ip = 1;
Code Equation
在可以编码方程式之前,您需要确保其处于形式pdepe
solver expects:
以这种形式,PDE是
因此,方程中系数的值是
((C一个rtesian coordinates with no angular symmetry)
Now you can create a function to code the equation. The function should have the signature[[C,,,,F,,,,s这是给予的=transistorPDE(x,t,u,dudx,C)
:
X
is the independent spatial variable.t
是独立时间变量。你
is the dependent variable being differentiated with respect toX
一个ndt
。dudx
is the partial spatial derivative 。C
is an extra input containing the physical constants.输出
C
,,,,F
,,,,一个nds
对应于标准PDE方程式中的系数,预期pdepe
。
As a result, the equation in this example can be represented by the function:
F你nCtion[c,f,s] =晶体管(x,t,u,dudx,c)d = c.d;eta = c.eta;l = c.l;C = 1;f = d*dudx;s = - (d*eta/l)*dudx;结尾
(注意:在示例末尾,所有功能都包含为本地功能。)
代码初始条件
Next, write a function that returns the initial condition. The initial condition is applied at the first time value, and provides the value of
为了一个ny value of
。使用功能签名u0 =晶体管(x,c)
to write the function.
The initial condition is
相应的功能是
F你nCtionu0 =晶体管(x,c)k = c.k;l = c.l;d = c.d;eta = c.eta;u0 =(k*l/d)*(1- exp(-eta*(1- x/l)))/eta;结尾
Code Boundary Conditions
Now, write a function that evaluates the boundary conditions 。For problems posed on the interval ,,,,the boundary conditions apply for all 一个ndeither or 。求解器预期的边界条件的标准形式为
Written in this form, the boundary conditions for this problem are
- 为了 ,,,,the equation is 系数是:
-likewise for ,,,,the equation is 系数是:
边界功能应使用功能签名[PL,QL,PR,QR] =晶体管(XL,UL,XR,UR,T)
:
输入x
l
一个nd你l
Correspond to 一个nd 对于左边界。The inputs
xr
一个ndur
Correspond to 一个nd 对于正确的边界。t
是独立时间变量。输出
pl
一个ndQL
Correspond to 一个nd 为了the left boundary ( 对于这个问题)。输出
PR
一个ndQR
Correspond to 一个nd 为了the right boundary ( 对于这个问题)。
The boundary conditions in this example are represented by the function:
F你nCtion[PL,QL,PR,QR] =晶体管(XL,UL,XR,UR,T)pl=你l; ql = 0; pr = ur; qr = 0;结尾
SeleCtSolution Mesh
The solution mesh defines the values of 一个nd where the solution is evaluated by the solver. Since the solution to this problem changes rapidly, use a relatively fine mesh of 50 spatial points in the interval 一个nd50 time points in the interval 。
X=linspace(0,C.L,50); t = linspace(0,1,50);
求解方程
最后,使用对称性求解方程
,,,,the PDE equation, the initial condition, the boundary conditions, and the meshes for
一个nd
。自从pdepe
期望PDE函数使用四个输入,而初始条件函数将使用一个输入,创建函数句柄将物理常数的结构传递为额外的输入。
m=0; eqn = @(x,t,u,dudx) transistorPDE(x,t,u,dudx,C); ic = @(x) transistorIC(x,C); sol = pdepe(m,eqn,ic,@transistorBC,x,t);
pdepe
返回3-D阵列中的解决方案sol
,,,,whereSOL(I,J,K)
一个pPRoximates thek
溶液的分量
evaluated att(i)
一个ndX((j)
。对于这个问题你
has only one component, but in general you can extract thek
th solution component with the command你=sol(:,:,k)
。
u = sol(:,:,1);
图解决方案
Create a surface plot of the solution 在选定的网格点绘制 一个nd 。
s你rf(x,t,u) title(“数值解决方案(50个网格点)”)Xl一个bel(('距离x')ylabel('时间t')zlabel(“解决方案u(x,t)”)
现在,只是绘制 一个nd to get a side view of the contours in the surface plot.
plot(x,u) xlabel('距离x')ylabel(“解决方案u(x,t)”)title('Solution profiles at several times')
Compute Emitter Discharge Current
Using a series solution for ,发射器排放电流可以表示为无限序列[1]:
编写一个函数来计算分析解决方案 在本系列中使用40项。唯一的变量time, but specify a second input to the function for the structure of constants.
F你nCtion我t=serex3(t,C)% Approximate I(t) by series expansion.我p=C。我p; eta = C.eta; D = C.D; L = C.L; It = 0;为了n=1:40%使用40项m =(n*pi)^2 + 0.25*eta^2;it = it +((n*pi)^2 / m)*exp( - (d / l^2)*m*t);结尾我t=2*Ip*((1 - exp(-eta))/eta)*It;结尾
使用数字解决方案
一个sComputed bypdepe
,,,,you can also calculate the numeric approximation for
在
和
C一个lC你l在ethe analytic and numeric solutions for
一个ndplot the results. UsePdeval
计算价值
在
。
nt=length(t); I = zeros(1,nt); seriesI = zeros(1,nt); iok = 2:nt;为了j = iok%在时间t(j),计算x = 0时的du/dx。[[~,I(j)] = pdeval(m,x,u(j,:),0); seriesI(j) = serex3(t(j),C);结尾% Numeric solution has form I(t) = (I_p*D/K)*du(0,t)/dx我=((C。我p*C.D/C.K)*I; plot(t(iok),I(iok),'o',,,,t((iok),seriesI(iok)) legend('来自pdepe + pdeval',,,,“来自系列”)title(“发射器排放电流i(t)”)Xl一个bel(('时间t')
结果匹配得很好。您可以进一步改善数字结果pdepe
by using a finer solution mesh.
本地功能
这里列出的是PDE求解器的本地辅助功能pdepe
C一个llsto calculate the solution. Alternatively, you can save these functions as their own files in a directory on the MATLAB path.
F你nCtion[[C,,,,F,,,,s这是给予的=transistorPDE(x,t,u,dudx,C)% Equation to solved = c.d;eta = c.eta;l = c.l;C = 1;f = d*dudx;s = - (d*eta/l)*dudx;结尾%------------------------------------------------------------------------------F你nCtionu0 =晶体管(x,c)% Initial conditionk=C。k; L = C.L; D = C.D; eta = C.eta; u0 = (K*L/D)*(1 - exp(-eta*(1 - x/L)))/eta;结尾%------------------------------------------------------------------------------F你nCtion[PL,QL,PR,QR] =晶体管(XL,UL,XR,UR,T)% Boundary conditionspl=你l; ql = 0; pr = ur; qr = 0;结尾%------------------------------------------------------------------------------F你nCtion我t=serex3(t,C)% Approximate I(t) by series expansion.我p=C。我p; eta = C.eta; D = C.D; L = C.L; It = 0;为了n=1:40%使用40项m =(n*pi)^2 + 0.25*eta^2;it = it +((n*pi)^2 / m)*exp( - (d / l^2)*m*t);结尾我t=2*Ip*((1 - exp(-eta))/eta)*It;结尾%------------------------------------------------------------------------------
reFerences
[1] Zachmanoglou,E.C。和D.L.thoe。与应用程序的部分微分方程简介。纽约多佛,1986年。