How do I define the right side of Poisson's equation when I have a vector of data and I want to use the POISOLV function in the Partial Differential Equation Toolbox?

4 views (last 30 days)
I want to solve the following equation:
-div grad v = sin(u)
where "u" is the solution to this partial differential equation (PDE)
-div grad u = sin(x*y);
on the unit rectangle with Dirichlet boundary conditions and u = 0 on the boundary of the rectangle.
I want to use the MATLAB function POISOLV to find the fast solution of Poisson's equation on a rectangular grid. The syntax for POISOLV is as follows:
u=poisolv(b,p,e,t,f)
The variable "f", in the above syntax, must be a string. The following code gives the solution to:
-div grad u = sin(x*y)
% Results not tested for analytical accuracy
%
% Solving for u
global u p
g = 'squareg';
b = 'squareb1';
c=1;
a=0;
[p,e,t] =poimesh(g,32,32);
f = 'sin(x.*y)';
u=poisolv(b,p,e,t,f);
figure
pdesurf(p,t,u);
title('Plot u');
However, when I solve
-div grad u = sin(x*y)
the data type for "u" is double-precision floating point. Because it is not a string, I cannot use it to solve
-div grad v = sin(u)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Jan 2010
To pass a string to the POISOLV function, you must create a new function. The function below uses the GRIDDATA function to evaluate "u" at the points on the mesh specified by the partial differential equation solver:
% func.m to be used with pdeofpde.m
% This function is written strictly for the script file pdeofpde.m
%
% Make sure both the func.m and script files are in the same directory
% This implementation uses global varibles. Take
% care that these variables do not overwrite any existing viaribles.
%
% Results not tested for analytical accuaracy
function f = func(x,y)
global u p
temp = griddata(p(1,:),p(2,:),u,x,y);
f = sin(temp);
Then evaluate this code to solve for "v"
% Solving for v
figure
v=poisolv(b,p,e,t,'func(x,y)');
pdesurf(p,t,v);
title('Plot v');
Global variables are used because the Partial Differential Equations Toolbox does not allow you to pass additional variables to user-defined functions. Take care that these variables do not overwrite any existing variables.
The files pdeofpde.m and func.m are attached. These functions were written for MATLAB R14SP2.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!