pdeCoefficientsToDouble
Description
converts the symbolic objects of the structure coeffs
= pdeCoefficientsToDouble(symCoeffs
)symCoeffs
to
double-precision numbers or function handles. The output is a structure
coeffs
that can then be used to define the coefficients of a PDE model
by calling specifyCoefficients
in Partial Differential Equation Toolbox™.
The structure coeffs
contains the coefficients
m
, d
, c
, a
,
and f
for the PDE system with the form
that can be solved in Partial Differential Equation Toolbox. For more information, see Equations You Can Solve Using Partial Differential Equation Toolbox (Partial Differential Equation Toolbox).
Examples
Extract Coefficients From a Symbolic PDE
Create a symbolic PDE that represents the Laplacian of the variable u(x,y)
.
syms u(x,y) f pdeeq = laplacian(u,[x y]) == f
pdeeq(x, y) =
Extract the coefficients of the PDE as symbolic expressions and display their values.
symCoeffs = pdeCoefficients(pdeeq,u,'Symbolic',true);
structfun(@disp,symCoeffs)
pdeCoefficients
converts the symbolic PDE into a scalar PDE equation of the form
,
and extract the coefficients a
, c
, m
, d
, and f
into the structure symCoeffs
.
Choose a value for f
. Since symCoeffs
are symbolic objects, use pdeCoefficientsToDouble
to convert the coefficients to double
data type. The coefficients with double
data type are valid inputs for the specifyCoefficients
function in the PDE Toolbox.
symCoeffs = subs(symCoeffs,f,-3); coeffs = pdeCoefficientsToDouble(symCoeffs)
coeffs = struct with fields:
a: 0
c: [4x1 double]
m: 0
d: 0
f: -3
System of Several PDEs
Solve a system of two second-order PDEs. You can solve the PDE system by extracting the PDE coefficients symbolically using pdeCoefficients
, converting the coefficients to double-precision numbers using pdeCoefficientsToDouble
, and specifying the coefficients in the PDE model using specifyCoefficients
.
The system of PDEs represents the deflection of a clamped structural plate under a uniform pressure load. The system of PDEs with the dependent variables and is given by
,
,
where is the bending stiffness of the plate given by
,
and is the modulus of elasticity, is Poisson's ratio, is the plate thickness, is the transverse deflection of the plate, and is the pressure load.
Create a PDE model for the system of two equations.
model = createpde(2);
Create a square geometry. Specify the side length of the square. Then include the geometry in the PDE model.
len = 10.0; gdm = [3 4 0 len len 0 0 0 len len]'; g = decsg(gdm,'S1',('S1')'); geometryFromEdges(model,g);
Specify the values of the physical parameters of the system. Let the external pressure be a symbolic variable pres
that can take any value.
E = 1.0e6;
h_thick = 0.1;
nu = 0.3;
D = E*h_thick^3/(12*(1 - nu^2));
syms pres
Declare the PDE system as a system symbolic equations. Extract the coefficients of the PDE and return them in symbolic form.
syms u1(x,y) u2(x,y) pdeeq = [-laplacian(u1) + u2; -D*laplacian(u2) - pres]; symCoeffs = pdeCoefficients(pdeeq,[u1 u2],'Symbolic',true)
symCoeffs = struct with fields:
m: 0
a: [2x2 sym]
c: [4x4 sym]
f: [2x1 sym]
d: 0
Display the coefficients m
, a
, c
, f
, and d
.
structfun(@disp,symCoeffs)
Substitute a value for pres
using the subs
function. Since the outputs of subs
are symbolic objects, use the pdeCoefficientsToDouble
function to convert the coefficients to the double
data type, which makes them valid inputs for the PDE Toolbox.
symCoeffs = subs(symCoeffs,pres,2); coeffs = pdeCoefficientsToDouble(symCoeffs)
coeffs = struct with fields:
a: [4x1 double]
c: [16x1 double]
m: 0
d: 0
f: [2x1 double]
Specify the PDE coefficients for the PDE model.
specifyCoefficients(model,'m',coeffs.m,'d',coeffs.d, ... 'c',coeffs.c,'a',coeffs.a,'f',coeffs.f);
Specify spring stiffness. Specify boundary conditions by defining distributed springs on all four edges.
k = 1e7; bOuter = applyBoundaryCondition(model,'neumann','Edge',(1:4), ... 'g',[0 0],'q',[0 0; k 0]);
Specify the mesh size of the geometry and generate a mesh for the PDE model.
hmax = len/20;
generateMesh(model,'Hmax',hmax);
Solve the model.
res = solvepde(model);
Access the solution at the nodal locations.
u = res.NodalSolution;
Plot the transverse deflection of the plate.
numNodes = size(model.Mesh.Nodes,2); figure; pdeplot(model,'XYData',u(1:numNodes),'contour','on') title 'Transverse Deflection'
Find the transverse deflection at the plate center.
wMax = min(u(1:numNodes,1))
wMax = -0.2763
Compare the result with the deflection at the plate center computed analytically.
pres = 2; wMax = -.0138*pres*len^4/(E*h_thick^3)
wMax = -0.2760
Specify Dependent Variables of PDE System
Since R2023a
Create a PDE system of four equations with four dependent variables, , , , and .
syms A(x,y,z,t) E(x,y,z,t) P(x,y,z,t) T(x,y,z,t) eqn1 = diff(A,t) == -A*E*(-exp(T)); eqn2 = diff(P,t) == -P*E*(-exp(T)); eqn3 = diff(E,t) == -A*E*(-exp(T)) - P*E*(-exp(T)); eqn4 = diff(T,t) == laplacian(T,[x y z]) + A*E*(-exp(T)) + P*E*(-exp(T)); pdeeq = [eqn1; eqn2; eqn3; eqn4]
pdeeq(x, y, z, t) =
Extract the coefficients of the PDE system as symbolic expressions. Specify the variable u
to represent the dependent variables.
u = [A E P T];
symCoeffs = pdeCoefficients(pdeeq,u,'Symbolic',true)
symCoeffs = struct with fields:
m: [4x4 sym]
a: [4x4 sym]
c: [12x12 sym]
f: [4x1 sym]
d: [4x4 sym]
Display the coefficients m
, a
, c
, f
, and d
.
structfun(@disp,symCoeffs)
Convert the coefficients to the double
data type so that they are valid inputs for the specifyCoefficients
function in Partial Differential Equation Toolbox. Because the a
coefficient in symCoeffs
contains the dependent variables and is not constant, calling pdeCoefficientsToDouble(symCoeffs)
without the second input argument can return an error. Instead, specify the second argument as the dependent variables u
when using pdeCoefficientsToDouble
.
coeffs = pdeCoefficientsToDouble(symCoeffs,u)
coeffs = struct with fields:
a: @makeCoefficient/coefficientFunction
c: [144x1 double]
m: 0
d: [16x1 double]
f: 0
Input Arguments
symCoeffs
— Coefficients of PDE in symbolic form
structure of symbolic expressions
Coefficients of PDE in symbolic form, specified as a structure of symbolic expressions.
u
— Dependent variables of PDE
symbolic function
Since R2023a
Dependent variables of PDE, specified as a symbolic function. The argument
u
must contain stationary or time-dependent variables in two or
three dimensions.
Example: syms E(x,y,z,t) B(x,y,z,t); u = [E B];
Output Arguments
coeffs
— Coefficients of PDE operating on doubles
structure of doubles and function handles
Coefficients of PDE operating on doubles, returned as a structure of
double-precision numbers and function handles as required by the
specifyCoefficients
function. The fields of the structure are
a
, c
, m
,
d
, and f
. For details on interpreting the
coefficients in the format required by Partial Differential Equation Toolbox, see:
c Coefficient for specifyCoefficients (Partial Differential Equation Toolbox)
m, d, or a Coefficient for specifyCoefficients (Partial Differential Equation Toolbox)
f Coefficient for specifyCoefficients (Partial Differential Equation Toolbox)
When pdeCoefficientsToDouble
returns a coefficient as a function
handle, the function handle takes two structures as input arguments,
location
and state
, and returns double-precision
output. The function handle is displayed as
@makeCoefficient/coefficientFunction
in the Command Window. To
display the formula of the function handle in coeffs.f
in symbolic
form, use coeffs.f('show')
.
In some cases, not all generated coefficients can be used by
specifyCoefficients
. For example, the d
coefficient must take a special matrix form when m
is nonzero. For
more details, see d Coefficient When m Is Nonzero (Partial Differential Equation Toolbox).
Version History
Introduced in R2021aR2023a: Specify dependent variables when converting PDE coefficients
You can specify the dependent variables u
of a PDE system as the
second input argument of pdeCoefficientsToDouble
when converting symbolic
coefficients of the PDE system to double-precision numbers or function handles. For example,
see Specify Dependent Variables of PDE System.
See Also
syms
| diff
| laplacian
| pdeCoefficients
| specifyCoefficients
(Partial Differential Equation Toolbox)
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)