Skip to main content
deleted 2750 characters in body
Source Link
user55777
  • 643
  • 3
  • 17

Here is my thoughts based on MethodOfLines introduced here:

We first create $2M$ equidistant grid points $x_m=(m-M)h$ with $m=1,2,...,2M$. The x-position of grid points is stored in xtab:

M = 10; L = 10; h = L/M;
xtab = Table[(m - M) h, {m, 1, 2*M}]

Then we should discretize the solution of PDE along $x$ into $2M$ solutions of a set of coupled ODEs. u[m][t] denotes the solution of function $u(x,t)$ at point $x_m$. Here, I didn't include the left end-point, since it can be set to be u[0][t]=u[2*M][t] according to the periodicity.

U[t_] = Table[u[m][t], {m, 1, 2*M}];

The spatial derivatives are discretized using 2nd-order central differences, here the periodic condition should be applied:

1st-derivative wrt x:

internaldUdx = ListCorrelate[{-1, 0, 1}/(2 h), U[t]];
dUdx = Join[{(u[1][t] - u[2*M - 1][t])/(2 h)}, 
internaldUdx, {(u[1][t] - u[2*M - 1][t])/(2 h)}];

2nd-derivative wrt x:

internaldUdxx = ListCorrelate[{1, -2, 1}/h^2, U[t]];
dUdxx = Join[{(u[2*M - 1][t] - 2 u[2*M][t] + u[1][t])/h^2}, 
internaldUdxx, {(u[2*M - 1][t] - 2 u[2*M][t] + u[1][t])/h^2}];

3rd-derivative wrt x:

internaldUdxxx = ListCorrelate[{-1, 2, 0, -2, 1}/(2 h^3), U[t]];
dUdxxx = Join[{(-u[2*M - 2][t] + 2 u[2*M - 1][t] - 2 u[1][t] + 
u[2][t])/(2 h^3), (-u[2*M - 1][t] + 2 u[2*M][t] - 2 u[2][t] + u[3][t])/(
2 h^3)}, internaldUdxxx, {(-u[2*M - 3][t] + 2*u[2*M - 2][t] - 2 u[2*M][t] + 
u[1][t])/(2 h^3), (-u[2*M - 2][t] + 2 u[2*M - 1][t] - 2 u[1][t] + u[2][t])/(2 h^3)}];

4th-derivative wrt x:

internaldUdxxxx = ListCorrelate[{1, -4, 6, -4, 1}/h^4, U[t]];
dUdxxxx = Join[{(u[2*M - 2][t] - 4*u[2*M - 1][t] + 6*u[2*M][t] - 4*u[1][t] + 
u[2][t])/h^4, (u[2*M - 1][t] - 4*u[2*M][t] + 6*u[1][t] - 4*u[2][t] + u[3][t])/h^4},
internaldUdxxxx,
{(u[2*M - 3][t] - 4*u[2*M - 2][t] + 6*u[2*M - 1][t] - 4*u[2*M][t] + 
u[1][t])/h^4, (u[2*M - 2][t] - 4*u[2*M - 1][t] + 6*u[2*M][t] - 4 u[1][t] + 
u[2][t])/h^4}]

To discretize the integral, we may introduce the mid-points $x_{m+1/2}=(x_m+x_{m+1})/2$ for $m=1,2,...,2M-1$ with $x_{1/2}=(-L+x_1)/2$, which are saved in midxtab:

midxtab = Join[{(-L+(1-M) dx)/2}, Table[((m - M) dx + (m + 1 - M) dx)/2, {m, 1, 2*M-1}]];

I have trouble to discretized the integral.

usum = dUdxxx[t].Cot[...]*h;

After constructing the system of ODEs and the discrete initial condition:

eqns = Thread[D[U[t], t] == -U[t]*dUdx - dUdxx - dUdxxxx - 1/(2 L)*usum];

initc = Thread[U[0] == 0.1*Cos[\[Pi]/L*xtab]];

The original PDE should be solved numerically:

tmax = 2;

lines = NDSolveValue[{eqns, initc}, U[t], {t, 0, tmax}] // Flatten;

Here is my thoughts based on MethodOfLines introduced here:

We first create $2M$ equidistant grid points $x_m=(m-M)h$ with $m=1,2,...,2M$. The x-position of grid points is stored in xtab:

M = 10; L = 10; h = L/M;
xtab = Table[(m - M) h, {m, 1, 2*M}]

Then we should discretize the solution of PDE along $x$ into $2M$ solutions of a set of coupled ODEs. u[m][t] denotes the solution of function $u(x,t)$ at point $x_m$. Here, I didn't include the left end-point, since it can be set to be u[0][t]=u[2*M][t] according to the periodicity.

U[t_] = Table[u[m][t], {m, 1, 2*M}];

The spatial derivatives are discretized using 2nd-order central differences, here the periodic condition should be applied:

1st-derivative wrt x:

internaldUdx = ListCorrelate[{-1, 0, 1}/(2 h), U[t]];
dUdx = Join[{(u[1][t] - u[2*M - 1][t])/(2 h)}, 
internaldUdx, {(u[1][t] - u[2*M - 1][t])/(2 h)}];

2nd-derivative wrt x:

internaldUdxx = ListCorrelate[{1, -2, 1}/h^2, U[t]];
dUdxx = Join[{(u[2*M - 1][t] - 2 u[2*M][t] + u[1][t])/h^2}, 
internaldUdxx, {(u[2*M - 1][t] - 2 u[2*M][t] + u[1][t])/h^2}];

3rd-derivative wrt x:

internaldUdxxx = ListCorrelate[{-1, 2, 0, -2, 1}/(2 h^3), U[t]];
dUdxxx = Join[{(-u[2*M - 2][t] + 2 u[2*M - 1][t] - 2 u[1][t] + 
u[2][t])/(2 h^3), (-u[2*M - 1][t] + 2 u[2*M][t] - 2 u[2][t] + u[3][t])/(
2 h^3)}, internaldUdxxx, {(-u[2*M - 3][t] + 2*u[2*M - 2][t] - 2 u[2*M][t] + 
u[1][t])/(2 h^3), (-u[2*M - 2][t] + 2 u[2*M - 1][t] - 2 u[1][t] + u[2][t])/(2 h^3)}];

4th-derivative wrt x:

internaldUdxxxx = ListCorrelate[{1, -4, 6, -4, 1}/h^4, U[t]];
dUdxxxx = Join[{(u[2*M - 2][t] - 4*u[2*M - 1][t] + 6*u[2*M][t] - 4*u[1][t] + 
u[2][t])/h^4, (u[2*M - 1][t] - 4*u[2*M][t] + 6*u[1][t] - 4*u[2][t] + u[3][t])/h^4},
internaldUdxxxx,
{(u[2*M - 3][t] - 4*u[2*M - 2][t] + 6*u[2*M - 1][t] - 4*u[2*M][t] + 
u[1][t])/h^4, (u[2*M - 2][t] - 4*u[2*M - 1][t] + 6*u[2*M][t] - 4 u[1][t] + 
u[2][t])/h^4}]

To discretize the integral, we may introduce the mid-points $x_{m+1/2}=(x_m+x_{m+1})/2$ for $m=1,2,...,2M-1$ with $x_{1/2}=(-L+x_1)/2$, which are saved in midxtab:

midxtab = Join[{(-L+(1-M) dx)/2}, Table[((m - M) dx + (m + 1 - M) dx)/2, {m, 1, 2*M-1}]];

I have trouble to discretized the integral.

usum = dUdxxx[t].Cot[...]*h;

After constructing the system of ODEs and the discrete initial condition:

eqns = Thread[D[U[t], t] == -U[t]*dUdx - dUdxx - dUdxxxx - 1/(2 L)*usum];

initc = Thread[U[0] == 0.1*Cos[\[Pi]/L*xtab]];

The original PDE should be solved numerically:

tmax = 2;

lines = NDSolveValue[{eqns, initc}, U[t], {t, 0, tmax}] // Flatten;
Post Undeleted by user55777
Post Deleted by user55777
deleted 233 characters in body
Source Link
user55777
  • 643
  • 3
  • 17

Now, weI have trouble to discretized the integral at these mid-points:.

usum = dUdxxx[t].Cot[\[Pi](midxtab - xtab)/(2*L)Cot[...]*h;
eqns = Thread[D[U[t], t] == -U[t]*dUdx[t]U[t]*dUdx - dUdxx[t]dUdxx - dUdxxxx[t]dUdxxxx - 1/(2 L)*usum];

initc = Thread[U[0] == 0.1*Cos[\[Pi]/L*xtab]];

But, this time MMA reported this error:

NDSolveValue::ndnum: Encountered non-numerical value for a derivative at t == 0.`

I have examined this code many time. Please help with m.

Now, we discretized the integral at these mid-points:

usum = dUdxxx[t].Cot[\[Pi](midxtab - xtab)/(2*L)]*h;
eqns = Thread[D[U[t], t] == -U[t]*dUdx[t] - dUdxx[t] - dUdxxxx[t] - 1/(2 L)*usum];

initc = Thread[U[0] == 0.1*Cos[\[Pi]/L*xtab]];

But, this time MMA reported this error:

NDSolveValue::ndnum: Encountered non-numerical value for a derivative at t == 0.`

I have examined this code many time. Please help with m.

I have trouble to discretized the integral.

usum = dUdxxx[t].Cot[...]*h;
eqns = Thread[D[U[t], t] == -U[t]*dUdx - dUdxx - dUdxxxx - 1/(2 L)*usum];

initc = Thread[U[0] == 0.1*Cos[\[Pi]/L*xtab]];
Post Undeleted by user55777
Post Deleted by user55777
added 1217 characters in body
Source Link
user55777
  • 643
  • 3
  • 17

We first create $2M$ equidistant grid points $x_m=(m-M)dx$$x_m=(m-M)h$ with $m=1,2,...,2M$. The x-position of grid points is stored in xtab:

M = 50;10; dxL = 2*L/(2*M);10; h = L/M;
xtab = Table[(m - M) dxh, {m, 1, 2*M}];]

The spatial derivatives are discretized using 2nd-order central differences, for example here the periodic condition should be applied:

1st-derivative wrt x:

dUdxx=ListCorrelate[internaldUdx = ListCorrelate[{-1, 0, 1}/(2 h), U[t]];
dUdx = Join[{(u[1][t] - u[2*M - 1][t])/(2 h)}, 
internaldUdx, {(u[1][t] - u[2*M - 1][t])/(2 h)}];

2nd-derivative wrt x:

internaldUdxx = ListCorrelate[{1, -2, 1}/dx^2h^2, U[t]]U[t]];
dUdxx = Join[{(u[2*M - 1][t] - 2 u[2*M][t] + u[1][t])/h^2}, 
internaldUdxx, {(u[2*M - 1][t] - 2 u[2*M][t] + u[1][t])/h^2}];

3rd-derivative wrt x:

internaldUdxxx = ListCorrelate[{-1, 2, 0, -2, 1}/(2 h^3), U[t]];
dUdxxx = Join[{(-u[2*M - 2][t] + 2 u[2*M - 1][t] - 2 u[1][t] + 
u[2][t])/(2 h^3), (-u[2*M - 1][t] + 2 u[2*M][t] - 2 u[2][t] + u[3][t])/(
2 h^3)}, internaldUdxxx, {(-u[2*M - 3][t] + 2*u[2*M - 2][t] - 2 u[2*M][t] + 
u[1][t])/(2 h^3), (-u[2*M - 2][t] + 2 u[2*M - 1][t] - 2 u[1][t] + u[2][t])/(2 h^3)}];

4th-derivative wrt x:

internaldUdxxxx = ListCorrelate[{1, -4, 6, -4, 1}/h^4, U[t]];
dUdxxxx = Join[{(u[2*M - 2][t] - 4*u[2*M - 1][t] + 6*u[2*M][t] - 4*u[1][t] + 
u[2][t])/h^4, (u[2*M - 1][t] - 4*u[2*M][t] + 6*u[1][t] - 4*u[2][t] + u[3][t])/h^4},
internaldUdxxxx,
{(u[2*M - 3][t] - 4*u[2*M - 2][t] + 6*u[2*M - 1][t] - 4*u[2*M][t] + 
u[1][t])/h^4, (u[2*M - 2][t] - 4*u[2*M - 1][t] + 6*u[2*M][t] - 4 u[1][t] + 
u[2][t])/h^4}]

To discretize the integral, we may introduce the mid-points $x_{m+1/2}=(x_m+x_{m+1})/2$ for $m=1,2,...,2M-1$ with $x_{1/2}=(-L+x_1)/2$, which are saved in midxtab. Correspondingly, we define u[m+1/2][t]=(u[m][t]+u[m+1][t])/2.:

and the corresponding discreted solution at the midpoints

midU[t_] = Table[Subscript[u, i + 1/2][t], {i, 0, 2*M - 1}];

The value of the midpoint-solution midU[t_] can be evaluated to be (u[m][t]+u[m+1][t])/2.

Now, we discretized the integral at these mid-points, here dUdxxx[t] represents 3rd-derivative wrt x:

After Threadconstructing the system of ODEs (? problem here), and construct the discreteddiscrete initial condition:

eqns = Thread[D[U[t], t] == -U[t]*dUdx[t] - dUdxx[t] - dUdxxxx[t] - 1/(2 L)*usum];

initc = Thread[U[0] == 0.1*Cos[\[Pi]/L*xtab]];

The original PDE couldshould be solved numerically:

tmax = 2;

lines = NDSolveValue[{eqns, initc}, U[t], {t, 0, tmax}] // Flatten;

But, this time MMA reported this error:

NDSolveValue::ndnum: Encountered non-numerical value for a derivative at t == 0.`

I have examined this code many time. Please help with m.

We first create $2M$ equidistant grid points $x_m=(m-M)dx$ with $m=1,2,...,2M$. The x-position of grid points is stored in xtab:

M = 50; dx = 2*L/(2*M); xtab = Table[(m - M) dx, {m, 1, 2*M}];

The spatial derivatives are discretized using 2nd-order central differences, for example:

dUdxx=ListCorrelate[{1, -2, 1}/dx^2, U[t]]

To discretize the integral, we may introduce the mid-points $x_{m+1/2}=(x_m+x_{m+1})/2$ for $m=1,2,...,2M-1$ with $x_{1/2}=(-L+x_1)/2$, which are saved in midxtab. Correspondingly, we define u[m+1/2][t]=(u[m][t]+u[m+1][t])/2.

and the corresponding discreted solution at the midpoints

midU[t_] = Table[Subscript[u, i + 1/2][t], {i, 0, 2*M - 1}];

The value of the midpoint-solution midU[t_] can be evaluated to be (u[m][t]+u[m+1][t])/2.

Now, we discretized the integral at these mid-points, here dUdxxx[t] represents 3rd-derivative wrt x:

After Thread the system of ODEs (? problem here), and construct the discreted initial condition

initc = Thread[U[0] == 0.1*Cos[\[Pi]/L*xtab]];

The original PDE could be solved numerically

lines = NDSolveValue[{eqns, initc}, U[t], {t, 0, tmax}] // Flatten;

We first create $2M$ equidistant grid points $x_m=(m-M)h$ with $m=1,2,...,2M$. The x-position of grid points is stored in xtab:

M = 10; L = 10; h = L/M;
xtab = Table[(m - M) h, {m, 1, 2*M}]

The spatial derivatives are discretized using 2nd-order central differences, here the periodic condition should be applied:

1st-derivative wrt x:

internaldUdx = ListCorrelate[{-1, 0, 1}/(2 h), U[t]];
dUdx = Join[{(u[1][t] - u[2*M - 1][t])/(2 h)}, 
internaldUdx, {(u[1][t] - u[2*M - 1][t])/(2 h)}];

2nd-derivative wrt x:

internaldUdxx = ListCorrelate[{1, -2, 1}/h^2, U[t]];
dUdxx = Join[{(u[2*M - 1][t] - 2 u[2*M][t] + u[1][t])/h^2}, 
internaldUdxx, {(u[2*M - 1][t] - 2 u[2*M][t] + u[1][t])/h^2}];

3rd-derivative wrt x:

internaldUdxxx = ListCorrelate[{-1, 2, 0, -2, 1}/(2 h^3), U[t]];
dUdxxx = Join[{(-u[2*M - 2][t] + 2 u[2*M - 1][t] - 2 u[1][t] + 
u[2][t])/(2 h^3), (-u[2*M - 1][t] + 2 u[2*M][t] - 2 u[2][t] + u[3][t])/(
2 h^3)}, internaldUdxxx, {(-u[2*M - 3][t] + 2*u[2*M - 2][t] - 2 u[2*M][t] + 
u[1][t])/(2 h^3), (-u[2*M - 2][t] + 2 u[2*M - 1][t] - 2 u[1][t] + u[2][t])/(2 h^3)}];

4th-derivative wrt x:

internaldUdxxxx = ListCorrelate[{1, -4, 6, -4, 1}/h^4, U[t]];
dUdxxxx = Join[{(u[2*M - 2][t] - 4*u[2*M - 1][t] + 6*u[2*M][t] - 4*u[1][t] + 
u[2][t])/h^4, (u[2*M - 1][t] - 4*u[2*M][t] + 6*u[1][t] - 4*u[2][t] + u[3][t])/h^4},
internaldUdxxxx,
{(u[2*M - 3][t] - 4*u[2*M - 2][t] + 6*u[2*M - 1][t] - 4*u[2*M][t] + 
u[1][t])/h^4, (u[2*M - 2][t] - 4*u[2*M - 1][t] + 6*u[2*M][t] - 4 u[1][t] + 
u[2][t])/h^4}]

To discretize the integral, we may introduce the mid-points $x_{m+1/2}=(x_m+x_{m+1})/2$ for $m=1,2,...,2M-1$ with $x_{1/2}=(-L+x_1)/2$, which are saved in midxtab:

Now, we discretized the integral at these mid-points:

After constructing the system of ODEs and the discrete initial condition:

eqns = Thread[D[U[t], t] == -U[t]*dUdx[t] - dUdxx[t] - dUdxxxx[t] - 1/(2 L)*usum];

initc = Thread[U[0] == 0.1*Cos[\[Pi]/L*xtab]];

The original PDE should be solved numerically:

tmax = 2;

lines = NDSolveValue[{eqns, initc}, U[t], {t, 0, tmax}] // Flatten;

But, this time MMA reported this error:

NDSolveValue::ndnum: Encountered non-numerical value for a derivative at t == 0.`

I have examined this code many time. Please help with m.

deleted 53 characters in body
Source Link
user55777
  • 643
  • 3
  • 17
Loading
deleted 53 characters in body
Source Link
user55777
  • 643
  • 3
  • 17
Loading
deleted 53 characters in body
Source Link
user55777
  • 643
  • 3
  • 17
Loading
added 1 character in body
Source Link
user55777
  • 643
  • 3
  • 17
Loading
added 514 characters in body
Source Link
user55777
  • 643
  • 3
  • 17
Loading
Tweeted twitter.com/StackMma/status/1100682099126870019
added 1 character in body
Source Link
user55777
  • 643
  • 3
  • 17
Loading
added 655 characters in body
Source Link
user55777
  • 643
  • 3
  • 17
Loading
added 655 characters in body
Source Link
user55777
  • 643
  • 3
  • 17
Loading
deleted 1 character in body
Source Link
user55777
  • 643
  • 3
  • 17
Loading
added 419 characters in body
Source Link
user55777
  • 643
  • 3
  • 17
Loading
added 30 characters in body
Source Link
user55777
  • 643
  • 3
  • 17
Loading
added 618 characters in body
Source Link
user55777
  • 643
  • 3
  • 17
Loading
edited tags
Link
bbgodfrey
  • 62.1k
  • 18
  • 92
  • 160
Loading
Source Link
user55777
  • 643
  • 3
  • 17
Loading