Note: THIS PAGE DESCRIBES THE LEGACY WORKFLOW. New features might not be compatible with the legacy workflow. For the corresponding step in the recommended workflow, see the recommended examples on the PDE Coefficients page. |
Write a text expression using these conventions:
'x'
— x-coordinate
'y'
— y-coordinate
'z'
— z-coordinate
(3-D geometry)
'u'
— Solution of equation
'ux'
— Derivative of u in
the x-direction
'uy'
— Derivative of u in
the y-direction
'uz'
— Derivative of u in
the z-direction (3-D geometry)
't'
— Time (parabolic and
hyperbolic equations)
'sd'
— Subdomain number
(not used in 3-D geometry)
For example, you could use this string to represent a coefficient:
'(x + y)./(x.^2 + y.^2 + 1) + 3 + sin(t)./(1 + u.^4)'
Note:
Use |
You can write MATLAB^{®} functions for coefficients as well
as plain text expressions. For example, suppose your coefficient f
is
given by the file fcoeff.m
:
function f = fcoeff(x,y,t,sd) f = (x.*y)./(1 + x.^2 + y.^2); % f on subdomain 1 f = f + log(1 + t); % include time r = (sd == 2); % subdomain 2 f2 = cos(x + y); % coefficient on subdomain 2 f(r) = f2(r); % f on subdomain 2
Represent this function in the parabolic
solver,
for example:
u1 = parabolic(u0,tlist,b,p,e,t,c,a,'fcoeff(x,y,t,sd)',d)
Caution
In function form, |
There is a simple way to write a text expression for multiple
subdomains without using 'sd'
or a function. Separate
the formulas for the different subdomains with the '!'
character.
Generally use the same number of expressions as subdomains. However,
if an expression does not depend on the subdomain number, you can
give just one expression.
For example, an expression for an input (a
, c
, f
,
or d
) with three subdomains:
'2 + tanh(x.*y)!cosh(x)./(1 + x.^2 + y.^2)!x.^2
+ y.^2'
The coefficient c is a 2-by-2 matrix. You can give c in any of the following forms:
Scalar or single string — The software interprets c as a diagonal matrix:
$$\left(\begin{array}{cc}c& 0\\ 0& c\end{array}\right)$$
Two-element column vector or two-row text array — The software interprets c as a diagonal matrix:
$$\left(\begin{array}{cc}c(1)& 0\\ 0& c(2)\end{array}\right)$$
Three-element column vector or three-row text array — The software interprets c as a symmetric matrix:
$$\left(\begin{array}{cc}c(1)& c(2)\\ c(2)& c(3)\end{array}\right)$$
Four-element column vector or four-row text array — The software interprets c as a full matrix:
$$\left(\begin{array}{cc}c(1)& c(3)\\ c(2)& c(4)\end{array}\right)$$
For example, c as a symmetric matrix with cos(xy)
on
the off-diagonal terms:
c = char('x.^2+y.^2',... 'cos(x.*y)',... 'u./(1+x.^2+y.^2)')
To include subdomains separated by '!'
, include
the '!'
in each row. For example,
c = char('1 + x.^2 + y.^2!x.^2 + y.^2',... 'cos(x.*y)!sin(x.*y)',... 'u./(1 + x.^2 + y.^2)!u.*(x.^2 + y.^2)')
Caution Do not include spaces in your coefficient strings in the PDE app. The string parser can misinterpret a space as a vector separator, as when a MATLAB vector uses a space to separate elements of a vector. |