MATLAB Newsgroup

Using the Matlab pde toolbox I obtain a solution to the Poisson equation for a given geometry using dirichlet boundary conditions. First, I want to determine the gradient at all the boundary nodes. Is this possible using the toolbox? Second, I want to use these gradient values as an input boundary condition for the same boundary to solve a different equation (same geometry). Is this possible to do using the toolbox? Thanks.

Hi,

"Sashankh Rao" wrote in message <khdu9o$j3c$1@newscl01ah.mathworks.com>...

> Using the Matlab pde toolbox I obtain a solution to the Poisson equation for a given geometry using dirichlet boundary conditions. First, I want to determine the gradient at all the boundary nodes. Is this possible using the toolbox? Second, I want to use these gradient values as an input boundary condition for the same boundary to solve a different equation (same geometry). Is this possible to do using the toolbox? Thanks.

Yes, this is definitely possible. I'll try to point you in the right direction.

The function pdegrad can be used to calculate the gradient of the solution at the

element centroids.

http://www.mathworks.com/help/pde/ug/pdegrad.html?searchHighlight=pdegrad

Then the function pdeprtni can be used to interpolate these centroid values back

to the nodes.

http://www.mathworks.com/help/pde/ug/pdeprtni.html

Using these gradient values in the boundary conditions will require you to write your

own boundary condition function, referred to as a "boundary file" in the PDE

Toolbox documentation.

http://www.mathworks.com/help/pde/ug/pdebound.html

This documentation page has some examples of how to write such a function.

http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

Bill

Hi Bill,

That was very helpful. Thank you very much.

Sai

"Bill Greene" wrote in message <khfgev$sgb$1@newscl01ah.mathworks.com>...

> Hi,

>

> "Sashankh Rao" wrote in message <khdu9o$j3c$1@newscl01ah.mathworks.com>...

> > Using the Matlab pde toolbox I obtain a solution to the Poisson equation for a given geometry using dirichlet boundary conditions. First, I want to determine the gradient at all the boundary nodes. Is this possible using the toolbox? Second, I want to use these gradient values as an input boundary condition for the same boundary to solve a different equation (same geometry). Is this possible to do using the toolbox? Thanks.

>

> Yes, this is definitely possible. I'll try to point you in the right direction.

>

> The function pdegrad can be used to calculate the gradient of the solution at the

> element centroids.

> http://www.mathworks.com/help/pde/ug/pdegrad.html?searchHighlight=pdegrad

> Then the function pdeprtni can be used to interpolate these centroid values back

> to the nodes.

> http://www.mathworks.com/help/pde/ug/pdeprtni.html

>

> Using these gradient values in the boundary conditions will require you to write your

> own boundary condition function, referred to as a "boundary file" in the PDE

> Toolbox documentation.

> http://www.mathworks.com/help/pde/ug/pdebound.html

>

> This documentation page has some examples of how to write such a function.

> http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

>

> Bill

Hi Bill,

There is a follow up question to the one listed below. I am using the following method to solve my elliptic problem:

I create a geometry 'g'.

I then mesh it: [p,e,t] = initmesh(g);

Then I create my boundary matrix using [Q,G,H,R] = pdebound(p2,e2);

I then assemble other matrices using [K,M,F] = assema(p,t,c,a,f);

Finally I solve the problem using u = assempde(K,M,F,Q,G,H,R);

I get the following error from assempde

------------------------------------------

??? Error using ==> plus

Matrix dimensions must agree.

Error in ==> assempde at 245

KK=K+M+Q;

------------------------------------------

As per the link below the size of the Q matrix in the boundary file is (N^2 ne) which for a one-dimensional system is (1 ne), where ne is the number of edges in the mesh.

http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

However the size for the K and M matrices is (Np Np) where Np is the number of nodes in the matrix.

So I see that the K matrix and Q matrix are not of the same dimensions and hence the error. I am not able to figure out how to fix this problem. Any help will be appreciated very much.

Thank you.

"Bill Greene" wrote in message <khfgev$sgb$1@newscl01ah.mathworks.com>...

> Hi,

>

> "Sashankh Rao" wrote in message <khdu9o$j3c$1@newscl01ah.mathworks.com>...

> > Using the Matlab pde toolbox I obtain a solution to the Poisson equation for a given geometry using dirichlet boundary conditions. First, I want to determine the gradient at all the boundary nodes. Is this possible using the toolbox? Second, I want to use these gradient values as an input boundary condition for the same boundary to solve a different equation (same geometry). Is this possible to do using the toolbox? Thanks.

>

> Yes, this is definitely possible. I'll try to point you in the right direction.

>

> The function pdegrad can be used to calculate the gradient of the solution at the

> element centroids.

> http://www.mathworks.com/help/pde/ug/pdegrad.html?searchHighlight=pdegrad

> Then the function pdeprtni can be used to interpolate these centroid values back

> to the nodes.

> http://www.mathworks.com/help/pde/ug/pdeprtni.html

>

> Using these gradient values in the boundary conditions will require you to write your

> own boundary condition function, referred to as a "boundary file" in the PDE

> Toolbox documentation.

> http://www.mathworks.com/help/pde/ug/pdebound.html

>

> This documentation page has some examples of how to write such a function.

> http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

>

> Bill

"Sashankh Rao" wrote in message <ki291f$56f$1@newscl01ah.mathworks.com>...

> I then mesh it: [p,e,t] = initmesh(g);

> Then I create my boundary matrix using [Q,G,H,R] = pdebound(p2,e2);

> I then assemble other matrices using [K,M,F] = assema(p,t,c,a,f);

> Finally I solve the problem using u = assempde(K,M,F,Q,G,H,R);

Ah, I see that the documentation page I pointed you to doesn't

show you what to do with the pdebound function once you've created it--

sorry.

That function is actually called by the PDE Toolbox routines-- not by you.

If you don't want to do anything fancy, but simply want a solution, do this:

b=@pdebound; % the "pdebound" function can have any name

% also define p,e,t,c,a,f

u=assempde(b,p,e,t,c,a,f);

Regards,

Bill

> ------------------------------------------

> As per the link below the size of the Q matrix in the boundary file is (N^2 ne) which for a one-dimensional system is (1 ne), where ne is the number of edges in the mesh.

>

> http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

>

> However the size for the K and M matrices is (Np Np) where Np is the number of nodes in the matrix.

>

> So I see that the K matrix and Q matrix are not of the same dimensions and hence the error. I am not able to figure out how to fix this problem. Any help will be appreciated very much.

>

> Thank you.

>

> "Bill Greene" wrote in message <khfgev$sgb$1@newscl01ah.mathworks.com>...

> > Hi,

> >

> > "Sashankh Rao" wrote in message <khdu9o$j3c$1@newscl01ah.mathworks.com>...

> > > Using the Matlab pde toolbox I obtain a solution to the Poisson equation for a given geometry using dirichlet boundary conditions. First, I want to determine the gradient at all the boundary nodes. Is this possible using the toolbox? Second, I want to use these gradient values as an input boundary condition for the same boundary to solve a different equation (same geometry). Is this possible to do using the toolbox? Thanks.

> >

> > Yes, this is definitely possible. I'll try to point you in the right direction.

> >

> > The function pdegrad can be used to calculate the gradient of the solution at the

> > element centroids.

> > http://www.mathworks.com/help/pde/ug/pdegrad.html?searchHighlight=pdegrad

> > Then the function pdeprtni can be used to interpolate these centroid values back

> > to the nodes.

> > http://www.mathworks.com/help/pde/ug/pdeprtni.html

> >

> > Using these gradient values in the boundary conditions will require you to write your

> > own boundary condition function, referred to as a "boundary file" in the PDE

> > Toolbox documentation.

> > http://www.mathworks.com/help/pde/ug/pdebound.html

> >

> > This documentation page has some examples of how to write such a function.

> > http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

> >

> > Bill

Hi Bill,

You suggestion worked out perfectly. Thank you very much.

Sai

"Bill Greene" wrote in message <ki2os3$gna$1@newscl01ah.mathworks.com>...

> "Sashankh Rao" wrote in message <ki291f$56f$1@newscl01ah.mathworks.com>...

>

> > I then mesh it: [p,e,t] = initmesh(g);

> > Then I create my boundary matrix using [Q,G,H,R] = pdebound(p2,e2);

> > I then assemble other matrices using [K,M,F] = assema(p,t,c,a,f);

> > Finally I solve the problem using u = assempde(K,M,F,Q,G,H,R);

>

>

> Ah, I see that the documentation page I pointed you to doesn't

> show you what to do with the pdebound function once you've created it--

> sorry.

>

> That function is actually called by the PDE Toolbox routines-- not by you.

> If you don't want to do anything fancy, but simply want a solution, do this:

>

> b=@pdebound; % the "pdebound" function can have any name

> % also define p,e,t,c,a,f

> u=assempde(b,p,e,t,c,a,f);

>

> Regards,

>

> Bill

> > ------------------------------------------

> > As per the link below the size of the Q matrix in the boundary file is (N^2 ne) which for a one-dimensional system is (1 ne), where ne is the number of edges in the mesh.

> >

> > http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

> >

> > However the size for the K and M matrices is (Np Np) where Np is the number of nodes in the matrix.

> >

> > So I see that the K matrix and Q matrix are not of the same dimensions and hence the error. I am not able to figure out how to fix this problem. Any help will be appreciated very much.

> >

> > Thank you.

> >

> > "Bill Greene" wrote in message <khfgev$sgb$1@newscl01ah.mathworks.com>...

> > > Hi,

> > >

> > > "Sashankh Rao" wrote in message <khdu9o$j3c$1@newscl01ah.mathworks.com>...

> > > > Using the Matlab pde toolbox I obtain a solution to the Poisson equation for a given geometry using dirichlet boundary conditions. First, I want to determine the gradient at all the boundary nodes. Is this possible using the toolbox? Second, I want to use these gradient values as an input boundary condition for the same boundary to solve a different equation (same geometry). Is this possible to do using the toolbox? Thanks.

> > >

> > > Yes, this is definitely possible. I'll try to point you in the right direction.

> > >

> > > The function pdegrad can be used to calculate the gradient of the solution at the

> > > element centroids.

> > > http://www.mathworks.com/help/pde/ug/pdegrad.html?searchHighlight=pdegrad

> > > Then the function pdeprtni can be used to interpolate these centroid values back

> > > to the nodes.

> > > http://www.mathworks.com/help/pde/ug/pdeprtni.html

> > >

> > > Using these gradient values in the boundary conditions will require you to write your

> > > own boundary condition function, referred to as a "boundary file" in the PDE

> > > Toolbox documentation.

> > > http://www.mathworks.com/help/pde/ug/pdebound.html

> > >

> > > This documentation page has some examples of how to write such a function.

> > > http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

> > >

> > > Bill

"Bill Greene" wrote in message <ki2os3$gna$1@newscl01ah.mathworks.com>...

> "Sashankh Rao" wrote in message <ki291f$56f$1@newscl01ah.mathworks.com>...

>

> > I then mesh it: [p,e,t] = initmesh(g);

> > Then I create my boundary matrix using [Q,G,H,R] = pdebound(p2,e2);

> > I then assemble other matrices using [K,M,F] = assema(p,t,c,a,f);

> > Finally I solve the problem using u = assempde(K,M,F,Q,G,H,R);

>

>

> Ah, I see that the documentation page I pointed you to doesn't

> show you what to do with the pdebound function once you've created it--

> sorry.

>

> That function is actually called by the PDE Toolbox routines-- not by you.

> If you don't want to do anything fancy, but simply want a solution, do this:

>

> b=@pdebound; % the "pdebound" function can have any name

> % also define p,e,t,c,a,f

> u=assempde(b,p,e,t,c,a,f);

>

> Regards,

>

> Bill

> > ------------------------------------------

> > As per the link below the size of the Q matrix in the boundary file is (N^2 ne) which for a one-dimensional system is (1 ne), where ne is the number of edges in the mesh.

> >

> > http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

> >

> > However the size for the K and M matrices is (Np Np) where Np is the number of nodes in the matrix.

> >

> > So I see that the K matrix and Q matrix are not of the same dimensions and hence the error. I am not able to figure out how to fix this problem. Any help will be appreciated very much.

> >

> > Thank you.

> >

> > "Bill Greene" wrote in message <khfgev$sgb$1@newscl01ah.mathworks.com>...

> > > Hi,

> > >

> > > "Sashankh Rao" wrote in message <khdu9o$j3c$1@newscl01ah.mathworks.com>...

> > > > Using the Matlab pde toolbox I obtain a solution to the Poisson equation for a given geometry using dirichlet boundary conditions. First, I want to determine the gradient at all the boundary nodes. Is this possible using the toolbox? Second, I want to use these gradient values as an input boundary condition for the same boundary to solve a different equation (same geometry). Is this possible to do using the toolbox? Thanks.

> > >

> > > Yes, this is definitely possible. I'll try to point you in the right direction.

> > >

> > > The function pdegrad can be used to calculate the gradient of the solution at the

> > > element centroids.

> > > http://www.mathworks.com/help/pde/ug/pdegrad.html?searchHighlight=pdegrad

> > > Then the function pdeprtni can be used to interpolate these centroid values back

> > > to the nodes.

> > > http://www.mathworks.com/help/pde/ug/pdeprtni.html

> > >

> > > Using these gradient values in the boundary conditions will require you to write your

> > > own boundary condition function, referred to as a "boundary file" in the PDE

> > > Toolbox documentation.

> > > http://www.mathworks.com/help/pde/ug/pdebound.html

> > >

> > > This documentation page has some examples of how to write such a function.

> > > http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

> > >

> > > Bill

Hi Bill,

I have another question related to the above thread.

I am trying to impose the Neumann condition at nodes on the boundary. To do this I need to pass additional information to pdebound as shown below.

function [qmatrix,gmatrix,hmatrix,rmatrix] = pdebound2(p,e,u,time,u2bn,loc)

where u2bn and loc are the additional data. However, I get the following error in trying to do so:

Input argument "u2bn" is undefined.

Error in ==> pdebound2 at 13

Looks like pdebound will not accept additional data. I am using

b = @pdebound;

to assemble my boundary matrix.

Thanks for taking time to help me. Really appreciate it.

Sashankh

"Sashankh Rao" wrote in message <kiq3me$m50$1@newscl01ah.mathworks.com>...

> "Bill Greene" wrote in message <ki2os3$gna$1@newscl01ah.mathworks.com>...

> > "Sashankh Rao" wrote in message <ki291f$56f$1@newscl01ah.mathworks.com>...

> >

> > > I then mesh it: [p,e,t] = initmesh(g);

> > > Then I create my boundary matrix using [Q,G,H,R] = pdebound(p2,e2);

> > > I then assemble other matrices using [K,M,F] = assema(p,t,c,a,f);

> > > Finally I solve the problem using u = assempde(K,M,F,Q,G,H,R);

> >

> >

> > Ah, I see that the documentation page I pointed you to doesn't

> > show you what to do with the pdebound function once you've created it--

> > sorry.

> >

> > That function is actually called by the PDE Toolbox routines-- not by you.

> > If you don't want to do anything fancy, but simply want a solution, do this:

> >

> > b=@pdebound; % the "pdebound" function can have any name

> > % also define p,e,t,c,a,f

> > u=assempde(b,p,e,t,c,a,f);

> >

> > Regards,

> >

> > Bill

> > > ------------------------------------------

> > > As per the link below the size of the Q matrix in the boundary file is (N^2 ne) which for a one-dimensional system is (1 ne), where ne is the number of edges in the mesh.

> > >

> > > http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

> > >

> > > However the size for the K and M matrices is (Np Np) where Np is the number of nodes in the matrix.

> > >

> > > So I see that the K matrix and Q matrix are not of the same dimensions and hence the error. I am not able to figure out how to fix this problem. Any help will be appreciated very much.

> > >

> > > Thank you.

> > >

> > > "Bill Greene" wrote in message <khfgev$sgb$1@newscl01ah.mathworks.com>...

> > > > Hi,

> > > >

> > > > "Sashankh Rao" wrote in message <khdu9o$j3c$1@newscl01ah.mathworks.com>...

> > > > > Using the Matlab pde toolbox I obtain a solution to the Poisson equation for a given geometry using dirichlet boundary conditions. First, I want to determine the gradient at all the boundary nodes. Is this possible using the toolbox? Second, I want to use these gradient values as an input boundary condition for the same boundary to solve a different equation (same geometry). Is this possible to do using the toolbox? Thanks.

> > > >

> > > > Yes, this is definitely possible. I'll try to point you in the right direction.

> > > >

> > > > The function pdegrad can be used to calculate the gradient of the solution at the

> > > > element centroids.

> > > > http://www.mathworks.com/help/pde/ug/pdegrad.html?searchHighlight=pdegrad

> > > > Then the function pdeprtni can be used to interpolate these centroid values back

> > > > to the nodes.

> > > > http://www.mathworks.com/help/pde/ug/pdeprtni.html

> > > >

> > > > Using these gradient values in the boundary conditions will require you to write your

> > > > own boundary condition function, referred to as a "boundary file" in the PDE

> > > > Toolbox documentation.

> > > > http://www.mathworks.com/help/pde/ug/pdebound.html

> > > >

> > > > This documentation page has some examples of how to write such a function.

> > > > http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

> > > >

> > > > Bill

>

> Hi Bill,

>

> I have another question related to the above thread.

>

> I am trying to impose the Neumann condition at nodes on the boundary. To do this I need to pass additional information to pdebound as shown below.

>

> function [qmatrix,gmatrix,hmatrix,rmatrix] = pdebound2(p,e,u,time,u2bn,loc)

>

> where u2bn and loc are the additional data. However, I get the following error in trying to do so:

>

> Input argument "u2bn" is undefined.

> Error in ==> pdebound2 at 13

>

> Looks like pdebound will not accept additional data. I am using

>

> b = @pdebound;

>

> to assemble my boundary matrix.

>

> Thanks for taking time to help me. Really appreciate it.

>

> Sashankh

Hi Bill,

I think I figured this out. I declared my additional data as global variables. Thanks.

Sashankh

On 3/25/2013 2:41 PM, Sashankh Rao wrote:

> "Sashankh Rao" wrote in message

> <kiq3me$m50$1@newscl01ah.mathworks.com>...

>> "Bill Greene" wrote in message

>> <ki2os3$gna$1@newscl01ah.mathworks.com>...

>> > "Sashankh Rao" wrote in message

>> <ki291f$56f$1@newscl01ah.mathworks.com>...

>> > > > I then mesh it: [p,e,t] = initmesh(g);

>> > > Then I create my boundary matrix using [Q,G,H,R] = pdebound(p2,e2);

>> > > I then assemble other matrices using [K,M,F] = assema(p,t,c,a,f);

>> > > Finally I solve the problem using u = assempde(K,M,F,Q,G,H,R);

>> > > > Ah, I see that the documentation page I pointed you to doesn't

>> > show you what to do with the pdebound function once you've created

>> it--

>> > sorry.

>> > > That function is actually called by the PDE Toolbox routines--

>> not by you.

>> > If you don't want to do anything fancy, but simply want a solution,

>> do this:

>> > > b=@pdebound; % the "pdebound" function can have any name

>> > % also define p,e,t,c,a,f

>> > u=assempde(b,p,e,t,c,a,f);

>> > > Regards,

>> > > Bill

>> > > ------------------------------------------

>> > > As per the link below the size of the Q matrix in the boundary

>> file is (N^2 ne) which for a one-dimensional system is (1 ne), where

>> ne is the number of edges in the mesh. > > > >

>> http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

>> > > > > However the size for the K and M matrices is (Np Np) where Np

>> is the number of nodes in the matrix.

>> > > > > So I see that the K matrix and Q matrix are not of the same

>> dimensions and hence the error. I am not able to figure out how to

>> fix this problem. Any help will be appreciated very much.

>> > > > > Thank you.

>> > > > > "Bill Greene" wrote in message

>> <khfgev$sgb$1@newscl01ah.mathworks.com>...

>> > > > Hi,

>> > > > > > > "Sashankh Rao" wrote in message

>> <khdu9o$j3c$1@newscl01ah.mathworks.com>...

>> > > > > Using the Matlab pde toolbox I obtain a solution to the

>> Poisson equation for a given geometry using dirichlet boundary

>> conditions. First, I want to determine the gradient at all the

>> boundary nodes. Is this possible using the toolbox? Second, I want to

>> use these gradient values as an input boundary condition for the same

>> boundary to solve a different equation (same geometry). Is this

>> possible to do using the toolbox? Thanks.

>> > > > > > > Yes, this is definitely possible. I'll try to point you

>> in the right direction.

>> > > > > > > The function pdegrad can be used to calculate the

>> gradient of the solution at the

>> > > > element centroids.

>> > > >

>> http://www.mathworks.com/help/pde/ug/pdegrad.html?searchHighlight=pdegrad

>> > > > Then the function pdeprtni can be used to interpolate these

>> centroid values back

>> > > > to the nodes.

>> > > > http://www.mathworks.com/help/pde/ug/pdeprtni.html

>> > > > > > > Using these gradient values in the boundary conditions

>> will require you to write your

>> > > > own boundary condition function, referred to as a "boundary

>> file" in the PDE

>> > > > Toolbox documentation.

>> > > > http://www.mathworks.com/help/pde/ug/pdebound.html

>> > > > > > > This documentation page has some examples of how to write

>> such a function.

>> > > >

>> http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

>> > > > > > > Bill

>>

>> Hi Bill,

>>

>> I have another question related to the above thread.

>> I am trying to impose the Neumann condition at nodes on the boundary.

>> To do this I need to pass additional information to pdebound as shown

>> below.

>>

>> function [qmatrix,gmatrix,hmatrix,rmatrix] =

>> pdebound2(p,e,u,time,u2bn,loc)

>>

>> where u2bn and loc are the additional data. However, I get the

>> following error in trying to do so:

>>

>> Input argument "u2bn" is undefined.

>> Error in ==> pdebound2 at 13

>>

>> Looks like pdebound will not accept additional data. I am using

>> b = @pdebound;

>>

>> to assemble my boundary matrix.

>>

>> Thanks for taking time to help me. Really appreciate it.

>>

>> Sashankh

>

> Hi Bill,

>

> I think I figured this out. I declared my additional data as global

> variables. Thanks.

>

> Sashankh

I'm glad that global variables work for you. But there are other ways of

passing parameters that are less rigid. See, for example,

http://www.mathworks.com/help/optim/ug/passing-extra-parameters.html#bskkr4z

Alan Weiss

MATLAB mathematical toolbox documentation

Alan_Weiss <aweiss@mathworks.com> wrote in message <kj1cvc$fop$1@newscl01ah.mathworks.com>...

> On 3/25/2013 2:41 PM, Sashankh Rao wrote:

> > "Sashankh Rao" wrote in message

> > <kiq3me$m50$1@newscl01ah.mathworks.com>...

> >> "Bill Greene" wrote in message

> >> <ki2os3$gna$1@newscl01ah.mathworks.com>...

> >> > "Sashankh Rao" wrote in message

> >> <ki291f$56f$1@newscl01ah.mathworks.com>...

> >> > > > I then mesh it: [p,e,t] = initmesh(g);

> >> > > Then I create my boundary matrix using [Q,G,H,R] = pdebound(p2,e2);

> >> > > I then assemble other matrices using [K,M,F] = assema(p,t,c,a,f);

> >> > > Finally I solve the problem using u = assempde(K,M,F,Q,G,H,R);

> >> > > > Ah, I see that the documentation page I pointed you to doesn't

> >> > show you what to do with the pdebound function once you've created

> >> it--

> >> > sorry.

> >> > > That function is actually called by the PDE Toolbox routines--

> >> not by you.

> >> > If you don't want to do anything fancy, but simply want a solution,

> >> do this:

> >> > > b=@pdebound; % the "pdebound" function can have any name

> >> > % also define p,e,t,c,a,f

> >> > u=assempde(b,p,e,t,c,a,f);

> >> > > Regards,

> >> > > Bill

> >> > > ------------------------------------------

> >> > > As per the link below the size of the Q matrix in the boundary

> >> file is (N^2 ne) which for a one-dimensional system is (1 ne), where

> >> ne is the number of edges in the mesh. > > > >

> >> http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

> >> > > > > However the size for the K and M matrices is (Np Np) where Np

> >> is the number of nodes in the matrix.

> >> > > > > So I see that the K matrix and Q matrix are not of the same

> >> dimensions and hence the error. I am not able to figure out how to

> >> fix this problem. Any help will be appreciated very much.

> >> > > > > Thank you.

> >> > > > > "Bill Greene" wrote in message

> >> <khfgev$sgb$1@newscl01ah.mathworks.com>...

> >> > > > Hi,

> >> > > > > > > "Sashankh Rao" wrote in message

> >> <khdu9o$j3c$1@newscl01ah.mathworks.com>...

> >> > > > > Using the Matlab pde toolbox I obtain a solution to the

> >> Poisson equation for a given geometry using dirichlet boundary

> >> conditions. First, I want to determine the gradient at all the

> >> boundary nodes. Is this possible using the toolbox? Second, I want to

> >> use these gradient values as an input boundary condition for the same

> >> boundary to solve a different equation (same geometry). Is this

> >> possible to do using the toolbox? Thanks.

> >> > > > > > > Yes, this is definitely possible. I'll try to point you

> >> in the right direction.

> >> > > > > > > The function pdegrad can be used to calculate the

> >> gradient of the solution at the

> >> > > > element centroids.

> >> > > >

> >> http://www.mathworks.com/help/pde/ug/pdegrad.html?searchHighlight=pdegrad

> >> > > > Then the function pdeprtni can be used to interpolate these

> >> centroid values back

> >> > > > to the nodes.

> >> > > > http://www.mathworks.com/help/pde/ug/pdeprtni.html

> >> > > > > > > Using these gradient values in the boundary conditions

> >> will require you to write your

> >> > > > own boundary condition function, referred to as a "boundary

> >> file" in the PDE

> >> > > > Toolbox documentation.

> >> > > > http://www.mathworks.com/help/pde/ug/pdebound.html

> >> > > > > > > This documentation page has some examples of how to write

> >> such a function.

> >> > > >

> >> http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

> >> > > > > > > Bill

> >>

> >> Hi Bill,

> >>

> >> I have another question related to the above thread.

> >> I am trying to impose the Neumann condition at nodes on the boundary.

> >> To do this I need to pass additional information to pdebound as shown

> >> below.

> >>

> >> function [qmatrix,gmatrix,hmatrix,rmatrix] =

> >> pdebound2(p,e,u,time,u2bn,loc)

> >>

> >> where u2bn and loc are the additional data. However, I get the

> >> following error in trying to do so:

> >>

> >> Input argument "u2bn" is undefined.

> >> Error in ==> pdebound2 at 13

> >>

> >> Looks like pdebound will not accept additional data. I am using

> >> b = @pdebound;

> >>

> >> to assemble my boundary matrix.

> >>

> >> Thanks for taking time to help me. Really appreciate it.

> >>

> >> Sashankh

> >

> > Hi Bill,

> >

> > I think I figured this out. I declared my additional data as global

> > variables. Thanks.

> >

> > Sashankh

>

> I'm glad that global variables work for you. But there are other ways of

> passing parameters that are less rigid. See, for example,

> http://www.mathworks.com/help/optim/ug/passing-extra-parameters.html#bskkr4z

>

> Alan Weiss

> MATLAB mathematical toolbox documentation

Hi Alan,

I just saw your message. Thanks for the tip. I have another question for you and Bill.

I have got my program to run correctly. However, I seem to require a highly refined mesh to arrive at the desired accuracy. Now I am looking to optimize it. Is it possible to use quadratic finite elements (triangular) in the pde toolbox instead of the linear elements (triangular) which it uses by default?

Thanks for your help,

Sashankh

On 4/22/2013 6:13 PM, Sashankh Rao wrote:

> Alan_Weiss <aweiss@mathworks.com> wrote in message

> <kj1cvc$fop$1@newscl01ah.mathworks.com>...

>> On 3/25/2013 2:41 PM, Sashankh Rao wrote:

>> > "Sashankh Rao" wrote in message >

>> <kiq3me$m50$1@newscl01ah.mathworks.com>...

>> >> "Bill Greene" wrote in message >>

>> <ki2os3$gna$1@newscl01ah.mathworks.com>...

>> >> > "Sashankh Rao" wrote in message >>

>> <ki291f$56f$1@newscl01ah.mathworks.com>...

>> >> > > > I then mesh it: [p,e,t] = initmesh(g);

>> >> > > Then I create my boundary matrix using [Q,G,H,R] =

>> pdebound(p2,e2);

>> >> > > I then assemble other matrices using [K,M,F] = assema(p,t,c,a,f);

>> >> > > Finally I solve the problem using u = assempde(K,M,F,Q,G,H,R);

>> >> > > > Ah, I see that the documentation page I pointed you to

>> doesn't >> > show you what to do with the pdebound function once

>> you've created >> it--

>> >> > sorry.

>> >> > > That function is actually called by the PDE Toolbox routines--

>> >> not by you.

>> >> > If you don't want to do anything fancy, but simply want a

>> solution, >> do this:

>> >> > > b=@pdebound; % the "pdebound" function can have any name

>> >> > % also define p,e,t,c,a,f

>> >> > u=assempde(b,p,e,t,c,a,f);

>> >> > > Regards,

>> >> > > Bill

>> >> > > ------------------------------------------

>> >> > > As per the link below the size of the Q matrix in the boundary

>> >> file is (N^2 ne) which for a one-dimensional system is (1 ne),

>> where >> ne is the number of edges in the mesh. > > > > >>

>> http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

>> >> > > > > However the size for the K and M matrices is (Np Np) where

>> Np >> is the number of nodes in the matrix.

>> >> > > > > So I see that the K matrix and Q matrix are not of the

>> same >> dimensions and hence the error. I am not able to figure out

>> how to >> fix this problem. Any help will be appreciated very much.

>> >> > > > > Thank you.

>> >> > > > > "Bill Greene" wrote in message >>

>> <khfgev$sgb$1@newscl01ah.mathworks.com>...

>> >> > > > Hi,

>> >> > > > > > > "Sashankh Rao" wrote in message >>

>> <khdu9o$j3c$1@newscl01ah.mathworks.com>...

>> >> > > > > Using the Matlab pde toolbox I obtain a solution to the >>

>> Poisson equation for a given geometry using dirichlet boundary >>

>> conditions. First, I want to determine the gradient at all the >>

>> boundary nodes. Is this possible using the toolbox? Second, I want to

>> >> use these gradient values as an input boundary condition for the

>> same >> boundary to solve a different equation (same geometry). Is

>> this >> possible to do using the toolbox? Thanks.

>> >> > > > > > > Yes, this is definitely possible. I'll try to point

>> you >> in the right direction.

>> >> > > > > > > The function pdegrad can be used to calculate the >>

>> gradient of the solution at the

>> >> > > > element centroids.

>> >> > > > >>

>> http://www.mathworks.com/help/pde/ug/pdegrad.html?searchHighlight=pdegrad

>> >> > > > Then the function pdeprtni can be used to interpolate these

>> >> centroid values back

>> >> > > > to the nodes.

>> >> > > > http://www.mathworks.com/help/pde/ug/pdeprtni.html

>> >> > > > > > > Using these gradient values in the boundary conditions

>> >> will require you to write your

>> >> > > > own boundary condition function, referred to as a "boundary

>> >> file" in the PDE

>> >> > > > Toolbox documentation.

>> >> > > > http://www.mathworks.com/help/pde/ug/pdebound.html

>> >> > > > > > > This documentation page has some examples of how to

>> write >> such a function.

>> >> > > > >>

>> http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

>> >> > > > > > > Bill

>> >>

>> >> Hi Bill,

>> >>

>> >> I have another question related to the above thread.

>> >> I am trying to impose the Neumann condition at nodes on the

>> boundary. >> To do this I need to pass additional information to

>> pdebound as shown >> below.

>> >>

>> >> function [qmatrix,gmatrix,hmatrix,rmatrix] = >>

>> pdebound2(p,e,u,time,u2bn,loc)

>> >>

>> >> where u2bn and loc are the additional data. However, I get the >>

>> following error in trying to do so:

>> >>

>> >> Input argument "u2bn" is undefined.

>> >> Error in ==> pdebound2 at 13

>> >>

>> >> Looks like pdebound will not accept additional data. I am using

>> >> b = @pdebound;

>> >>

>> >> to assemble my boundary matrix.

>> >>

>> >> Thanks for taking time to help me. Really appreciate it.

>> >>

>> >> Sashankh

>> >

>> > Hi Bill,

>> >

>> > I think I figured this out. I declared my additional data as global

>> > variables. Thanks.

>> >

>> > Sashankh

>>

>> I'm glad that global variables work for you. But there are other ways

>> of passing parameters that are less rigid. See, for example,

>> http://www.mathworks.com/help/optim/ug/passing-extra-parameters.html#bskkr4z

>>

>>

>> Alan Weiss

>> MATLAB mathematical toolbox documentation

>

> Hi Alan,

>

> I just saw your message. Thanks for the tip. I have another question

> for you and Bill.

>

> I have got my program to run correctly. However, I seem to require a

> highly refined mesh to arrive at the desired accuracy. Now I am

> looking to optimize it. Is it possible to use quadratic finite

> elements (triangular) in the pde toolbox instead of the linear

> elements (triangular) which it uses by default?

> Thanks for your help,

> Sashankh

As far as I know, you cannot use quadratic finite elements.

Have you tried jiggling the mesh a few times? That often helps give

better accuracy. And, if you have MATLAB R2013a, you can try the new

meshing algorithm, though I have no idea whether that will help.

Good luck,

Alan Weiss

MATLAB mathematical toolbox documentation

Alan_Weiss <aweiss@mathworks.com> wrote in message <kl5tsl$7hn$1@newscl01ah.mathworks.com>...

> On 4/22/2013 6:13 PM, Sashankh Rao wrote:

> > Alan_Weiss <aweiss@mathworks.com> wrote in message

> > <kj1cvc$fop$1@newscl01ah.mathworks.com>...

> >> On 3/25/2013 2:41 PM, Sashankh Rao wrote:

> >> > "Sashankh Rao" wrote in message >

> >> <kiq3me$m50$1@newscl01ah.mathworks.com>...

> >> >> "Bill Greene" wrote in message >>

> >> <ki2os3$gna$1@newscl01ah.mathworks.com>...

> >> >> > "Sashankh Rao" wrote in message >>

> >> <ki291f$56f$1@newscl01ah.mathworks.com>...

> >> >> > > > I then mesh it: [p,e,t] = initmesh(g);

> >> >> > > Then I create my boundary matrix using [Q,G,H,R] =

> >> pdebound(p2,e2);

> >> >> > > I then assemble other matrices using [K,M,F] = assema(p,t,c,a,f);

> >> >> > > Finally I solve the problem using u = assempde(K,M,F,Q,G,H,R);

> >> >> > > > Ah, I see that the documentation page I pointed you to

> >> doesn't >> > show you what to do with the pdebound function once

> >> you've created >> it--

> >> >> > sorry.

> >> >> > > That function is actually called by the PDE Toolbox routines--

> >> >> not by you.

> >> >> > If you don't want to do anything fancy, but simply want a

> >> solution, >> do this:

> >> >> > > b=@pdebound; % the "pdebound" function can have any name

> >> >> > % also define p,e,t,c,a,f

> >> >> > u=assempde(b,p,e,t,c,a,f);

> >> >> > > Regards,

> >> >> > > Bill

> >> >> > > ------------------------------------------

> >> >> > > As per the link below the size of the Q matrix in the boundary

> >> >> file is (N^2 ne) which for a one-dimensional system is (1 ne),

> >> where >> ne is the number of edges in the mesh. > > > > >>

> >> http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

> >> >> > > > > However the size for the K and M matrices is (Np Np) where

> >> Np >> is the number of nodes in the matrix.

> >> >> > > > > So I see that the K matrix and Q matrix are not of the

> >> same >> dimensions and hence the error. I am not able to figure out

> >> how to >> fix this problem. Any help will be appreciated very much.

> >> >> > > > > Thank you.

> >> >> > > > > "Bill Greene" wrote in message >>

> >> <khfgev$sgb$1@newscl01ah.mathworks.com>...

> >> >> > > > Hi,

> >> >> > > > > > > "Sashankh Rao" wrote in message >>

> >> <khdu9o$j3c$1@newscl01ah.mathworks.com>...

> >> >> > > > > Using the Matlab pde toolbox I obtain a solution to the >>

> >> Poisson equation for a given geometry using dirichlet boundary >>

> >> conditions. First, I want to determine the gradient at all the >>

> >> boundary nodes. Is this possible using the toolbox? Second, I want to

> >> >> use these gradient values as an input boundary condition for the

> >> same >> boundary to solve a different equation (same geometry). Is

> >> this >> possible to do using the toolbox? Thanks.

> >> >> > > > > > > Yes, this is definitely possible. I'll try to point

> >> you >> in the right direction.

> >> >> > > > > > > The function pdegrad can be used to calculate the >>

> >> gradient of the solution at the

> >> >> > > > element centroids.

> >> >> > > > >>

> >> http://www.mathworks.com/help/pde/ug/pdegrad.html?searchHighlight=pdegrad

> >> >> > > > Then the function pdeprtni can be used to interpolate these

> >> >> centroid values back

> >> >> > > > to the nodes.

> >> >> > > > http://www.mathworks.com/help/pde/ug/pdeprtni.html

> >> >> > > > > > > Using these gradient values in the boundary conditions

> >> >> will require you to write your

> >> >> > > > own boundary condition function, referred to as a "boundary

> >> >> file" in the PDE

> >> >> > > > Toolbox documentation.

> >> >> > > > http://www.mathworks.com/help/pde/ug/pdebound.html

> >> >> > > > > > > This documentation page has some examples of how to

> >> write >> such a function.

> >> >> > > > >>

> >> http://www.mathworks.com/help/pde/ug/boundary-conditions-for-scalar-pde.html

> >> >> > > > > > > Bill

> >> >>

> >> >> Hi Bill,

> >> >>

> >> >> I have another question related to the above thread.

> >> >> I am trying to impose the Neumann condition at nodes on the

> >> boundary. >> To do this I need to pass additional information to

> >> pdebound as shown >> below.

> >> >>

> >> >> function [qmatrix,gmatrix,hmatrix,rmatrix] = >>

> >> pdebound2(p,e,u,time,u2bn,loc)

> >> >>

> >> >> where u2bn and loc are the additional data. However, I get the >>

> >> following error in trying to do so:

> >> >>

> >> >> Input argument "u2bn" is undefined.

> >> >> Error in ==> pdebound2 at 13

> >> >>

> >> >> Looks like pdebound will not accept additional data. I am using

> >> >> b = @pdebound;

> >> >>

> >> >> to assemble my boundary matrix.

> >> >>

> >> >> Thanks for taking time to help me. Really appreciate it.

> >> >>

> >> >> Sashankh

> >> >

> >> > Hi Bill,

> >> >

> >> > I think I figured this out. I declared my additional data as global

> >> > variables. Thanks.

> >> >

> >> > Sashankh

> >>

> >> I'm glad that global variables work for you. But there are other ways

> >> of passing parameters that are less rigid. See, for example,

> >> http://www.mathworks.com/help/optim/ug/passing-extra-parameters.html#bskkr4z

> >>

> >>

> >> Alan Weiss

> >> MATLAB mathematical toolbox documentation

> >

> > Hi Alan,

> >

> > I just saw your message. Thanks for the tip. I have another question

> > for you and Bill.

> >

> > I have got my program to run correctly. However, I seem to require a

> > highly refined mesh to arrive at the desired accuracy. Now I am

> > looking to optimize it. Is it possible to use quadratic finite

> > elements (triangular) in the pde toolbox instead of the linear

> > elements (triangular) which it uses by default?

> > Thanks for your help,

> > Sashankh

>

> As far as I know, you cannot use quadratic finite elements.

>

> Have you tried jiggling the mesh a few times? That often helps give

> better accuracy. And, if you have MATLAB R2013a, you can try the new

> meshing algorithm, though I have no idea whether that will help.

>

> Good luck,

>

> Alan Weiss

> MATLAB mathematical toolbox documentation

Hi Alan,

I did try to jiggle the mesh a few times. Currently, the global convergence rate of my solution is first order. Hence, I need to refine my mesh a number of times before I can arrive at the desired accuracy. I would like to have second order convergence. Any suggestion as to how I can do this using the pde toolbox? Thanks.

>I need to refine my mesh a number of times before I can arrive at the desired accuracy.

I suggest taking a look at the adaptmesh function. It does automatic

h-refinement of the mesh and often yields more accurate solutions with

fewer elements than the assempde function. Its input arguments are very

similar to assempde.

Bill

"Bill Greene" wrote in message <kl6dqn$1n5$1@newscl01ah.mathworks.com>...

> >I need to refine my mesh a number of times before I can arrive at the desired accuracy.

>

> I suggest taking a look at the adaptmesh function. It does automatic

> h-refinement of the mesh and often yields more accurate solutions with

> fewer elements than the assempde function. Its input arguments are very

> similar to assempde.

>

> Bill

Hi Bill,

Thanks for the input. I realized that the real reason for the loss in accuracy comes from the 'pdegrad' function. It reduces the convergence of my program from second order to first order since it is a part of the iterative scheme that my program uses. Is there a more accurate method to find the gradient? Thanks for your help.

Sashankh

You can think of your watch list as threads that you have bookmarked.

You can add tags, authors, threads, and even search results to your watch list. This way you can easily keep track of topics that you're interested in. To view your watch list, click on the "My Newsreader" link.

To add items to your watch list, click the "add to watch list" link at the bottom of any page.

To add search criteria to your watch list, search for the desired term in the search box. Click on the "Add this search to my watch list" link on the search results page.

You can also add a tag to your watch list by searching for the tag with the directive "tag:tag_name" where tag_name is the name of the tag you would like to watch.

To add an author to your watch list, go to the author's profile page and click on the "Add this author to my watch list" link at the top of the page. You can also add an author to your watch list by going to a thread that the author has posted to and clicking on the "Add this author to my watch list" link. You will be notified whenever the author makes a post.

To add a thread to your watch list, go to the thread page and click the "Add this thread to my watch list" link at the top of the page.

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Got questions?

Get answers.

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreDiscover what MATLAB ^{®} can do for your career.

Opportunities for recent engineering grads.

Apply TodayThe newsgroups are a worldwide forum that is open to everyone. Newsgroups are used to discuss a huge range of topics, make announcements, and trade files.

Discussions are threaded, or grouped in a way that allows you to read a posted message and all of its replies in chronological order. This makes it easy to follow the thread of the conversation, and to see what’s already been said before you post your own reply or make a new posting.

Newsgroup content is distributed by servers hosted by various organizations on the Internet. Messages are exchanged and managed using open-standard protocols. No single entity “owns” the newsgroups.

There are thousands of newsgroups, each addressing a single topic or area of interest. The MATLAB Central Newsreader posts and displays messages in the comp.soft-sys.matlab newsgroup.

**MATLAB Central**

You can use the integrated newsreader at the MATLAB Central website to read and post messages in this newsgroup. MATLAB Central is hosted by MathWorks.

Messages posted through the MATLAB Central Newsreader are seen by everyone using the newsgroups, regardless of how they access the newsgroups. There are several advantages to using MATLAB Central.

**One Account**

Your MATLAB Central account is tied to your MathWorks Account for easy access.

**Use the Email Address of Your Choice**

The MATLAB Central Newsreader allows you to define an alternative email address as your posting address, avoiding clutter in your primary mailbox and reducing spam.

**Spam Control**

Most newsgroup spam is filtered out by the MATLAB Central Newsreader.

**Tagging**

Messages can be tagged with a relevant label by any signed-in user. Tags can be used as keywords to find particular files of interest, or as a way to categorize your bookmarked postings. You may choose to allow others to view your tags, and you can view or search others’ tags as well as those of the community at large. Tagging provides a way to see both the big trends and the smaller, more obscure ideas and applications.

**Watch lists**

Setting up watch lists allows you to be notified of updates made to postings selected by author, thread, or any search variable. Your watch list notifications can be sent by email (daily digest or immediate), displayed in My Newsreader, or sent via RSS feed.

- Use a newsreader through your school, employer, or internet service provider
- Pay for newsgroup access from a commercial provider
- Use Google Groups
- Mathforum.org provides a newsreader with access to the comp.soft sys.matlab newsgroup
- Run your own server. For typical instructions, see: http://www.slyck.com/ng.php?page=2