MATLAB: How to set time-varying boundary conditions using the Partial Differential Equation Toolbox

Partial Differential Equation Toolbox

I want to solve a partial differential equation (PDE) that has a time-varying boundary condition using the Partial Differential Equation Toolbox.

Best Answer

You can use the Partial Differential Equation Toolbox to solve PDEs with time-varying boundary conditions. The following example describes how to define these boundary conditions :
1. Open the PDETOOL GUI by enetering
pdetool
at the MATLAB command prompt.
2. From the PDE menu, select PDE Specifications. In the dialog box, click Hyperbolic. Then click OK to close the dialog box.
3. From the Boundary menu, select Boundary Mode.
4. Double-click one of the boundaries in the figure.
5. In the Boundary Condition dialog box, enter values for the boundary condition parameters. The default values are constants. You can enter any function of time for these parameters, e.g. "sin(t)". You can also enter user-defined functions, e.g. "myBoundary(t)". Note that the function argument must be named "t". Any function you use must
a. Return a scalar for each value of "t" passed to it.
b. Return NaN for any "t" value of NaN.
An example of such a function is shown below:
function f = myFunc(t)
if isnan(t)
f=NaN;
else
f = t;
end
6. From the Solve menu, select Solve PDE.
7. You can visualize the time-varying boundary condition as follows:
a. From the Plot menu, select Parameters.
b. Select the Animation checkbox, and click Plot.
You can make the boundary condition a function of space as well as time by specifying a boundary condition such as "myFunc2(t,x,y)" in the Boundary Condition dialog box. The function "myFunc2" must
a. Return NaN for a "t" value of NaN.
b. Return a vector the same size as "x" or "y" for every numerical value of "t".
An example of such a function is shown below:
function f = myFunc2(t, x, y)
if isnan(t)
f=NaN;
else
f = (x+y) * t;
end