Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
PDEPE boundary conditions ul equals ur

Subject: PDEPE boundary conditions ul equals ur

From: Tran Trung Luu

Date: 7 Feb, 2014 12:28:09

Message: 1 of 9

Hi all,

I am trying to solve a pdepe of the form:
du/dt = A*du/dx;

However, the boundary condition is: u(xl,t) = u(xr,t) for all t.

I tried to put
ql = -1/A;
qr = -1/A;
pl = ul;
pr = ur;

then the code some how works but this does not satisfy the boundary condition that I want.

I tried to put them all the 0 then the code show the error:
Error using daeic12 (line 77)
This DAE appears to be of index greater than 1.

Could you please advise me in this case, any help will be much appreciated.

Best regards,
Trung

Subject: PDEPE boundary conditions ul equals ur

From: Torsten

Date: 10 Feb, 2014 09:18:06

Message: 2 of 9

"Tran Trung Luu" wrote in message <ld2jgp$mc3$1@newscl01ah.mathworks.com>...
> Hi all,
>
> I am trying to solve a pdepe of the form:
> du/dt = A*du/dx;
>
> However, the boundary condition is: u(xl,t) = u(xr,t) for all t.
>
> I tried to put
> ql = -1/A;
> qr = -1/A;
> pl = ul;
> pr = ur;
>
> then the code some how works but this does not satisfy the boundary condition that I want.
>
> I tried to put them all the 0 then the code show the error:
> Error using daeic12 (line 77)
> This DAE appears to be of index greater than 1.
>
> Could you please advise me in this case, any help will be much appreciated.
>
> Best regards,
> Trung

Why do you want to solve the equation numerically ?
If A is constant, the analytical solution is pretty clear.

Best wishes
Torsten.
 

Subject: PDEPE boundary conditions ul equals ur

From: Tran Trung Luu

Date: 10 Feb, 2014 11:12:06

Message: 3 of 9

> Why do you want to solve the equation numerically ?
> If A is constant, the analytical solution is pretty clear.
>
> Best wishes
> Torsten.

Thank you Torsten for your message.

Yes, you are right. However, for simplicity I did not put it clearly. Actually A is A(t) but this A(t) is numerically defined along all t thus I would not call it a function, I call it a constant.

Since the boundary is not set right thus if there is no solution for this with pdepe, I am thinking of writing my own solver to solve this particular problem because I will have more control than pdepe. In that case, I am considering Crank Nilcoson's algorithm. Could you please comment on this or advise me what should be the best way?

Thanks a lot and have a nice day,
Trung

PS: I tried to use the ode45 for t plus finite difference method to do derivative in x. But the results seem to contain a lot of numerical errors so I am not satisfied.

Subject: PDEPE boundary conditions ul equals ur

From: Torsten

Date: 10 Feb, 2014 11:46:07

Message: 4 of 9

"Tran Trung Luu" wrote in message <ldac66$hmn$1@newscl01ah.mathworks.com>...
> > Why do you want to solve the equation numerically ?
> > If A is constant, the analytical solution is pretty clear.
> >
> > Best wishes
> > Torsten.
>
> Thank you Torsten for your message.
>
> Yes, you are right. However, for simplicity I did not put it clearly. Actually A is A(t) but this A(t) is numerically defined along all t thus I would not call it a function, I call it a constant.
>
> Since the boundary is not set right thus if there is no solution for this with pdepe, I am thinking of writing my own solver to solve this particular problem because I will have more control than pdepe. In that case, I am considering Crank Nilcoson's algorithm. Could you please comment on this or advise me what should be the best way?
>
> Thanks a lot and have a nice day,
> Trung
>
> PS: I tried to use the ode45 for t plus finite difference method to do derivative in x. But the results seem to contain a lot of numerical errors so I am not satisfied.

Even if A=A(t), I'd not solve the original PDE.
Make your initial condition u0(x) periodic over the real line with period (xr-xl).
Calculate the quantity
integral_{t'=0}^{t'=t} A(t') dt'.
If I'm not mistaken, the solution of your problem is then given by
u(x,t) = u0(x-integral_{t'=0}^{t'=t} A(t') dt')

Best wishes
Torsten.

Subject: PDEPE boundary conditions ul equals ur

From: Tran Trung Luu

Date: 10 Feb, 2014 16:15:08

Message: 5 of 9

"Torsten" wrote in message <ldae5v$n3l$1@newscl01ah.mathworks.com>...
> "Tran Trung Luu" wrote in message <ldac66$hmn$1@newscl01ah.mathworks.com>...
> > > Why do you want to solve the equation numerically ?
> > > If A is constant, the analytical solution is pretty clear.
> > >
> > > Best wishes
> > > Torsten.
> >
> > Thank you Torsten for your message.
> >
> > Yes, you are right. However, for simplicity I did not put it clearly. Actually A is A(t) but this A(t) is numerically defined along all t thus I would not call it a function, I call it a constant.
> >
> > Since the boundary is not set right thus if there is no solution for this with pdepe, I am thinking of writing my own solver to solve this particular problem because I will have more control than pdepe. In that case, I am considering Crank Nilcoson's algorithm. Could you please comment on this or advise me what should be the best way?
> >
> > Thanks a lot and have a nice day,
> > Trung
> >
> > PS: I tried to use the ode45 for t plus finite difference method to do derivative in x. But the results seem to contain a lot of numerical errors so I am not satisfied.
>
> Even if A=A(t), I'd not solve the original PDE.
> Make your initial condition u0(x) periodic over the real line with period (xr-xl).
> Calculate the quantity
> integral_{t'=0}^{t'=t} A(t') dt'.
> If I'm not mistaken, the solution of your problem is then given by
> u(x,t) = u0(x-integral_{t'=0}^{t'=t} A(t') dt')
>
> Best wishes
> Torsten.

Dear Torsten,
Actually our problem is more complicated than this thus I tried to simplify it just to get the main point of the boundary.
Nevertheless, I implemented your analytical solution and it works perfectly. I compared the solution from pdepe and this analytical one and they are almost identical. Many thanks for this. I should have look more carefully to see if we can get an analytical solution first, even for this particular case.
Regarding the boundary, I would like to see how the boudaries behave when u(x,t) reaching them with the conditions we have. What is clear in the analytical solution you suggested is that u(x,t) will just go out and be missing. This is also confirmed in the pdepe results.
I guess that this is what it is.
Thank you again Torsten, I will look further into details. At the moment, things are good.

Best wishes,
Trung

Subject: PDEPE boundary conditions ul equals ur

From: Torsten

Date: 11 Feb, 2014 07:24:08

Message: 6 of 9

"Tran Trung Luu" wrote in message <ldatuc$68u$1@newscl01ah.mathworks.com>...
> "Torsten" wrote in message <ldae5v$n3l$1@newscl01ah.mathworks.com>...
> > "Tran Trung Luu" wrote in message <ldac66$hmn$1@newscl01ah.mathworks.com>...
> > > > Why do you want to solve the equation numerically ?
> > > > If A is constant, the analytical solution is pretty clear.
> > > >
> > > > Best wishes
> > > > Torsten.
> > >
> > > Thank you Torsten for your message.
> > >
> > > Yes, you are right. However, for simplicity I did not put it clearly. Actually A is A(t) but this A(t) is numerically defined along all t thus I would not call it a function, I call it a constant.
> > >
> > > Since the boundary is not set right thus if there is no solution for this with pdepe, I am thinking of writing my own solver to solve this particular problem because I will have more control than pdepe. In that case, I am considering Crank Nilcoson's algorithm. Could you please comment on this or advise me what should be the best way?
> > >
> > > Thanks a lot and have a nice day,
> > > Trung
> > >
> > > PS: I tried to use the ode45 for t plus finite difference method to do derivative in x. But the results seem to contain a lot of numerical errors so I am not satisfied.
> >
> > Even if A=A(t), I'd not solve the original PDE.
> > Make your initial condition u0(x) periodic over the real line with period (xr-xl).
> > Calculate the quantity
> > integral_{t'=0}^{t'=t} A(t') dt'.
> > If I'm not mistaken, the solution of your problem is then given by
> > u(x,t) = u0(x-integral_{t'=0}^{t'=t} A(t') dt')
> >
> > Best wishes
> > Torsten.
>
> Dear Torsten,
> Actually our problem is more complicated than this thus I tried to simplify it just to get the main point of the boundary.
> Nevertheless, I implemented your analytical solution and it works perfectly. I compared the solution from pdepe and this analytical one and they are almost identical. Many thanks for this. I should have look more carefully to see if we can get an analytical solution first, even for this particular case.
> Regarding the boundary, I would like to see how the boudaries behave when u(x,t) reaching them with the conditions we have. What is clear in the analytical solution you suggested is that u(x,t) will just go out and be missing. This is also confirmed in the pdepe results.
> I guess that this is what it is.
> Thank you again Torsten, I will look further into details. At the moment, things are good.
>
> Best wishes,
> Trung

Your pde just moves the initial function u0 (periodically continued) to the left and to the right on the x-axis with "velocity" A(t). That's why the analytical solution is just a translation of the initial profile on the x-axis.

Best wishes
Torsten.

Subject: PDEPE boundary conditions ul equals ur

From: Tran Trung Luu

Date: 11 Feb, 2014 16:04:08

Message: 7 of 9

"Torsten" wrote in message <ldcj6o$8e$1@newscl01ah.mathworks.com>...
> "Tran Trung Luu" wrote in message <ldatuc$68u$1@newscl01ah.mathworks.com>...
> > "Torsten" wrote in message <ldae5v$n3l$1@newscl01ah.mathworks.com>...
> > > "Tran Trung Luu" wrote in message <ldac66$hmn$1@newscl01ah.mathworks.com>...
> > > > > Why do you want to solve the equation numerically ?
> > > > > If A is constant, the analytical solution is pretty clear.
> > > > >
> > > > > Best wishes
> > > > > Torsten.
> > > >
> > > > Thank you Torsten for your message.
> > > >
> > > > Yes, you are right. However, for simplicity I did not put it clearly. Actually A is A(t) but this A(t) is numerically defined along all t thus I would not call it a function, I call it a constant.
> > > >
> > > > Since the boundary is not set right thus if there is no solution for this with pdepe, I am thinking of writing my own solver to solve this particular problem because I will have more control than pdepe. In that case, I am considering Crank Nilcoson's algorithm. Could you please comment on this or advise me what should be the best way?
> > > >
> > > > Thanks a lot and have a nice day,
> > > > Trung
> > > >
> > > > PS: I tried to use the ode45 for t plus finite difference method to do derivative in x. But the results seem to contain a lot of numerical errors so I am not satisfied.
> > >
> > > Even if A=A(t), I'd not solve the original PDE.
> > > Make your initial condition u0(x) periodic over the real line with period (xr-xl).
> > > Calculate the quantity
> > > integral_{t'=0}^{t'=t} A(t') dt'.
> > > If I'm not mistaken, the solution of your problem is then given by
> > > u(x,t) = u0(x-integral_{t'=0}^{t'=t} A(t') dt')
> > >
> > > Best wishes
> > > Torsten.
> >
> > Dear Torsten,
> > Actually our problem is more complicated than this thus I tried to simplify it just to get the main point of the boundary.
> > Nevertheless, I implemented your analytical solution and it works perfectly. I compared the solution from pdepe and this analytical one and they are almost identical. Many thanks for this. I should have look more carefully to see if we can get an analytical solution first, even for this particular case.
> > Regarding the boundary, I would like to see how the boudaries behave when u(x,t) reaching them with the conditions we have. What is clear in the analytical solution you suggested is that u(x,t) will just go out and be missing. This is also confirmed in the pdepe results.
> > I guess that this is what it is.
> > Thank you again Torsten, I will look further into details. At the moment, things are good.
> >
> > Best wishes,
> > Trung
>
> Your pde just moves the initial function u0 (periodically continued) to the left and to the right on the x-axis with "velocity" A(t). That's why the analytical solution is just a translation of the initial profile on the x-axis.
>
> Best wishes
> Torsten.

Dear Torsten,

Thanks a lot for your great help.
However, I am still interested in implementing the boundary conditions here (to make ul == ur at all time t). If you could please suggest any idea so that I can give it a try, that would be nice.

Have a nice day,
Trung

Subject: PDEPE boundary conditions ul equals ur

From: Torsten

Date: 12 Feb, 2014 07:40:12

Message: 8 of 9

"Tran Trung Luu" wrote in message <lddhlo$ono$1@newscl01ah.mathworks.com>...
> "Torsten" wrote in message <ldcj6o$8e$1@newscl01ah.mathworks.com>...
> > "Tran Trung Luu" wrote in message <ldatuc$68u$1@newscl01ah.mathworks.com>...
> > > "Torsten" wrote in message <ldae5v$n3l$1@newscl01ah.mathworks.com>...
> > > > "Tran Trung Luu" wrote in message <ldac66$hmn$1@newscl01ah.mathworks.com>...
> > > > > > Why do you want to solve the equation numerically ?
> > > > > > If A is constant, the analytical solution is pretty clear.
> > > > > >
> > > > > > Best wishes
> > > > > > Torsten.
> > > > >
> > > > > Thank you Torsten for your message.
> > > > >
> > > > > Yes, you are right. However, for simplicity I did not put it clearly. Actually A is A(t) but this A(t) is numerically defined along all t thus I would not call it a function, I call it a constant.
> > > > >
> > > > > Since the boundary is not set right thus if there is no solution for this with pdepe, I am thinking of writing my own solver to solve this particular problem because I will have more control than pdepe. In that case, I am considering Crank Nilcoson's algorithm. Could you please comment on this or advise me what should be the best way?
> > > > >
> > > > > Thanks a lot and have a nice day,
> > > > > Trung
> > > > >
> > > > > PS: I tried to use the ode45 for t plus finite difference method to do derivative in x. But the results seem to contain a lot of numerical errors so I am not satisfied.
> > > >
> > > > Even if A=A(t), I'd not solve the original PDE.
> > > > Make your initial condition u0(x) periodic over the real line with period (xr-xl).
> > > > Calculate the quantity
> > > > integral_{t'=0}^{t'=t} A(t') dt'.
> > > > If I'm not mistaken, the solution of your problem is then given by
> > > > u(x,t) = u0(x-integral_{t'=0}^{t'=t} A(t') dt')
> > > >
> > > > Best wishes
> > > > Torsten.
> > >
> > > Dear Torsten,
> > > Actually our problem is more complicated than this thus I tried to simplify it just to get the main point of the boundary.
> > > Nevertheless, I implemented your analytical solution and it works perfectly. I compared the solution from pdepe and this analytical one and they are almost identical. Many thanks for this. I should have look more carefully to see if we can get an analytical solution first, even for this particular case.
> > > Regarding the boundary, I would like to see how the boudaries behave when u(x,t) reaching them with the conditions we have. What is clear in the analytical solution you suggested is that u(x,t) will just go out and be missing. This is also confirmed in the pdepe results.
> > > I guess that this is what it is.
> > > Thank you again Torsten, I will look further into details. At the moment, things are good.
> > >
> > > Best wishes,
> > > Trung
> >
> > Your pde just moves the initial function u0 (periodically continued) to the left and to the right on the x-axis with "velocity" A(t). That's why the analytical solution is just a translation of the initial profile on the x-axis.
> >
> > Best wishes
> > Torsten.
>
> Dear Torsten,
>
> Thanks a lot for your great help.
> However, I am still interested in implementing the boundary conditions here (to make ul == ur at all time t). If you could please suggest any idea so that I can give it a try, that would be nice.
>
> Have a nice day,
> Trung

pdepe is not suited to solve your partial differential equation (PDE) - not only because you want to impose periodic boundary condition. The main reason is that pdepe is suited to solve parabolic/elliptic PDEs (roughly speaking, PDEs with a second order derivative) - your PDE is hyperbolic in nature.
So you will have to discretize your PDE and solve the resulting system of ODEs by ODE45, e.g..
Start with a first-order discretization scheme. It introduces much artificial diffusion, but second-order schemes are quite compliciated.
So for the PDE
du/dt = A(t)*du/dx,
with periodic boundary condition, a discretization would be
for the case A(t) > 0:
du_(i)/dt = A(t)*(u_(i+1)-u_(i))/(x_(i+1)-x_(i)) (1<=i<=n-1)
du_(n)/dt =A(t)*(u_(2)-u_(n))/(x_(2)-x_(1))
and for the case A(t) < 0:
du_(1)/dt = A(t)*(u_(n-1)-u_(1))/(x_(n)-x_(n-1))
du_(i)/dt = A(t)*(u_(i)-u_(i-1))/(x_(i)-x_(i-1)) (2<=i<=n)
where xl=x1<x2<...<xn=xr is a grid on the interval [xl,xr].
But try to stick to the analytical solution (in which I found a little error, by the way:
the correct solution is given by
u(x,t) = u0(x + integral_{t'=0}^{t'=t} A(t') dt')
where u0 is the initial condition periodically continued over the real line).

Best wishes
Torsten.
  

Subject: PDEPE boundary conditions ul equals ur

From: Tran Trung Luu

Date: 12 Feb, 2014 16:22:09

Message: 9 of 9

> pdepe is not suited to solve your partial differential equation (PDE) - not only because you want to impose periodic boundary condition. The main reason is that pdepe is suited to solve parabolic/elliptic PDEs (roughly speaking, PDEs with a second order derivative) - your PDE is hyperbolic in nature.
> So you will have to discretize your PDE and solve the resulting system of ODEs by ODE45, e.g..
> Start with a first-order discretization scheme. It introduces much artificial diffusion, but second-order schemes are quite compliciated.
> So for the PDE
> du/dt = A(t)*du/dx,
> with periodic boundary condition, a discretization would be
> for the case A(t) > 0:
> du_(i)/dt = A(t)*(u_(i+1)-u_(i))/(x_(i+1)-x_(i)) (1<=i<=n-1)
> du_(n)/dt =A(t)*(u_(2)-u_(n))/(x_(2)-x_(1))
> and for the case A(t) < 0:
> du_(1)/dt = A(t)*(u_(n-1)-u_(1))/(x_(n)-x_(n-1))
> du_(i)/dt = A(t)*(u_(i)-u_(i-1))/(x_(i)-x_(i-1)) (2<=i<=n)
> where xl=x1<x2<...<xn=xr is a grid on the interval [xl,xr].
> But try to stick to the analytical solution (in which I found a little error, by the way:
> the correct solution is given by
> u(x,t) = u0(x + integral_{t'=0}^{t'=t} A(t') dt')
> where u0 is the initial condition periodically continued over the real line).
>
> Best wishes
> Torsten.

Dear Torsten,

If I am not mistaken then what you are suggesting here is what I reported in my second post: utilizing the ode45 for the time vector, then calculate the derivative in x using finite different method. Actually I tried to use the second order scheme but did not get satisfactory results. Furthermore, I also tried the Crank Nicolson scheme but unfortunately still got significant numerical errors. It could also be that the ways I implemented them are not good yet, but so far it worked well for the weak A(t). Numerical errors only appear when I increase A(t) to see effects. Only the pdepe works well in most cases so far.

Anyway, thank you so much for your great help. I appreciate it. I will come back to you in case I need some advice.

Best wishes and have a nice day,
Trung

Tags for this Thread

What are tags?

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.

Contact us