Set Neumann Boundary Conditions to PDEModel

Hello, I want to solve the Laplace equation on a 2-D rectangular grid. I'm using the "applyBoundaryCondition" function to determine the boundaries.
On one side I have a constant Dirichlet boundary, applyBoundaryCondition(model,'Edge',3,'u',v);, and on the other two sides I have constant Neumann boundaries, applyBoundaryCondition(model,'Edge',[1,4],'q',0,'g',0);.
On the fourth side I want to use a Neumann boundary but instead of g=constant I have a vector that represents the value at each boundary point applyBoundaryCondition(model,'Edge',[1,4],'q',0,'g',[1:100]);. Is it possible to define 'g' as a vector like this and if not how can I do it?

 Accepted Answer

The documentation describes how to set boundary conditions. There is a worked example here.
For your case, you probably need to interpolate the g value as a function of x or y in order that the boundary condition is defined everywhere. You can use interp1 or any other interpolation method you like.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

5 Comments

Thanks for the quick response, if I understand correctly I should do something like this?:
define a function like this:
xj=1:100;
j=xj.^2;
myufun = @(region,state)interp1(xj,j,region.x);
and call the function like this:
bc=applyBoundaryCondition(pdemod,'Edge',2,'q',0,'g',myufun,'Vectorized','on');
is it valid to do it like this?
That looks correct to me. (Of course, if you really had such a simple formula for your g values, you wouldn't use interp1, you would just give the formula.)
Alan Weiss
MATLAB mathematical toolbox documentation
Is there a way to implement this directly to the PDE Toolbox? I attached a screenshot to clarify. (unfortunately j is not that simple and I cant express it as simple function)
Oh, I didn't realize that you were using the PDE app. I don't think that the PDE app uses functions in this syntax. Instead, I think that it uses functions in a syntax described here.
IMHO, it is much easier to use command-line functions with a PDEModel object.
Alan Weiss
MATLAB mathematical toolbox documentation
I tried them both and in every one of them I had another problem. With the PDEmodel object I can write the function but the mesh using "generate Mesh" was not good. In contrasts, by using the PDE app I was able to create a good mesh but I can't write a function in the way I want. (The mesh problem is described the second question of mine: refine mesh in PDEModel )

Sign in to comment.

More Answers (0)

Asked:

d
d
on 24 Aug 2015

Commented:

d
d
on 30 Aug 2015

Community Treasure Hunt

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

Start Hunting!