Skip to main content
deleted 48 characters in body
Source Link
xzczd
  • 71.6k
  • 10
  • 184
  • 524

Your problem can be solved with the method mentioned here, here and here. The idea is simple: NDSolve don't know how to disretize your system, so we do it ourselves. I'll use pdetoode for the disretization of the derivative term and Gaussian quadrature formula for the discretization of integral:

total = 200; L = 10; tend = 100; points = 25; difforder = 4; domain = {-L/2, L/2}; {nodes, weights} = Most[NIntegrate`GaussRuleData[points, MachinePrecision]]; midgrid = Rescale[nodes, {0, 1}, domain]; intrule = int -> -Subtract @@ domain weights.Map[Function[x, A[x][t]], midgrid]; grid = Flatten[{First@domain, midgrid, Last@domain}]; (*Definition of pdetoode isn't included in this post, please find it in the link above.*) ptoofunc = pdetoode[A[x, t], t, grid, difforder, True]; eq = {D[A[x, t], {t, 1}] == Plus[0.005 D[A[x, t], {x, 2}], D[0.1 Exp[-0.5 (x - 0.5)^2] A[x, t], {x, 1}], 0.1 B[t] - 0.2 A[x, t]], B[t] == (total - int)/L }; ic = A[x, 0] == 10; odeic = ptoofunc@ic; ode = {ptoofunc@First@eq, Last@eq /. intrule}; sollst = NDSolveValue[{ode, odeic}, {A /@ grid, B}, {t, 0, tend}]; solA = rebuild[sollst[[1]], grid]grid, 2] solB = sollst[[2]] ListLinePlot@solB (* Notice time is the 1st argument of solA *)  Plot3D[solA[tPlot3D[solA[x, x]t], {x, ##}, {t, 0, tend}, PlotRange -> All] & @@ domain 

The results look the same as those in Akku14's answer so I'd like to omit them here.

Well, I admit this solution is a bit advanced, but it avoids iteration so it's quite fast.

Your problem can be solved with the method mentioned here, here and here. The idea is simple: NDSolve don't know how to disretize your system, so we do it ourselves. I'll use pdetoode for the disretization of the derivative term and Gaussian quadrature formula for the discretization of integral:

total = 200; L = 10; tend = 100; points = 25; difforder = 4; domain = {-L/2, L/2}; {nodes, weights} = Most[NIntegrate`GaussRuleData[points, MachinePrecision]]; midgrid = Rescale[nodes, {0, 1}, domain]; intrule = int -> -Subtract @@ domain weights.Map[Function[x, A[x][t]], midgrid]; grid = Flatten[{First@domain, midgrid, Last@domain}]; (*Definition of pdetoode isn't included in this post, please find it in the link above.*) ptoofunc = pdetoode[A[x, t], t, grid, difforder, True]; eq = {D[A[x, t], {t, 1}] == Plus[0.005 D[A[x, t], {x, 2}], D[0.1 Exp[-0.5 (x - 0.5)^2] A[x, t], {x, 1}], 0.1 B[t] - 0.2 A[x, t]], B[t] == (total - int)/L }; ic = A[x, 0] == 10; odeic = ptoofunc@ic; ode = {ptoofunc@First@eq, Last@eq /. intrule}; sollst = NDSolveValue[{ode, odeic}, {A /@ grid, B}, {t, 0, tend}]; solA = rebuild[sollst[[1]], grid] solB = sollst[[2]] ListLinePlot@solB (* Notice time is the 1st argument of solA *)  Plot3D[solA[t, x], {x, ##}, {t, 0, tend}, PlotRange -> All] & @@ domain 

The results look the same as those in Akku14's answer so I'd like to omit them here.

Well, I admit this solution is a bit advanced, but it avoids iteration so it's quite fast.

Your problem can be solved with the method mentioned here, here and here. The idea is simple: NDSolve don't know how to disretize your system, so we do it ourselves. I'll use pdetoode for the disretization of the derivative term and Gaussian quadrature formula for the discretization of integral:

total = 200; L = 10; tend = 100; points = 25; difforder = 4; domain = {-L/2, L/2}; {nodes, weights} = Most[NIntegrate`GaussRuleData[points, MachinePrecision]]; midgrid = Rescale[nodes, {0, 1}, domain]; intrule = int -> -Subtract @@ domain weights.Map[Function[x, A[x][t]], midgrid]; grid = Flatten[{First@domain, midgrid, Last@domain}]; (*Definition of pdetoode isn't included in this post, please find it in the link above.*) ptoofunc = pdetoode[A[x, t], t, grid, difforder, True]; eq = {D[A[x, t], {t, 1}] == Plus[0.005 D[A[x, t], {x, 2}], D[0.1 Exp[-0.5 (x - 0.5)^2] A[x, t], {x, 1}], 0.1 B[t] - 0.2 A[x, t]], B[t] == (total - int)/L }; ic = A[x, 0] == 10; odeic = ptoofunc@ic; ode = {ptoofunc@First@eq, Last@eq /. intrule}; sollst = NDSolveValue[{ode, odeic}, {A /@ grid, B}, {t, 0, tend}]; solA = rebuild[sollst[[1]], grid, 2] solB = sollst[[2]] ListLinePlot@solB Plot3D[solA[x, t], {x, ##}, {t, 0, tend}, PlotRange -> All] & @@ domain 

The results look the same as those in Akku14's answer so I'd like to omit them here.

Well, I admit this solution is a bit advanced, but it avoids iteration so it's quite fast.

deleted 63 characters in body
Source Link
xzczd
  • 71.6k
  • 10
  • 184
  • 524

Your problem can be solved with the method mentioned here, here and here. The idea is simple: NDSolve don't know how to disretize your system, so we do it ourselves. I'll use pdetoode for the disretization of the derivative term and Gaussian quadrature formula for the discretization of integral:

total = 200; L = 10; tend = 100; points = 25; difforder = 4; domain = {-L/2, L/2}; {nodes, weights} = Most[NIntegrate`GaussRuleData[points, MachinePrecision]]; midgrid = Rescale[nodes, {0, 1}, domain]; intrule = int -> -Subtract @@ domain weights.Map[Function[x, A[x][t]], midgrid]; grid = Flatten[{First@domain, midgrid, Last@domain}]; (*Definition of pdetoode isn't included in this post, please find it in the link above.*) ptoofunc = pdetoode[A[x, t], t, grid, difforder, True]; eq = {D[A[x, t], {t, 1}] == Plus[0.005 D[A[x, t], {x, 2}], D[0.1 Exp[-0.5 (x - 0.5)^2] A[x, t], {x, 1}], 0.1 B[t] - 0.2 A[x, t]], B[t] == (total - int)/L }; ic = A[x, 0] == 10; odeic = ptoofunc@ic; ode = {ptoofunc@First@eq, Last@eq /. intrule}; sollst = NDSolveValue[{ode, odeic}, {A /@ grid, B}, {t, 0, tend}]; solA = ListInterpolation[ Developer`ToPackedArray@#["ValuesOnGrid"] & /@ #, {gridrebuild[sollst[[1]], #[[1]][grid] solB = sollst[[2]] ListLinePlot@solB (* Notice time is the 1st "Coordinates"][[1]]}]argument &@sollst[[1]] solBof =solA sollst[[2]] ListLinePlot@solB*) Plot3D[solA[xPlot3D[solA[t, t]x], {x, ##}, {t, 0, tend}, PlotRange -> All] & @@ domain 

The results look the same as those in Akku14's answer so I'd like to omit them here.

Well, I admit this solution is a bit advanced, but it avoids iteration so it's quite fast.

Your problem can be solved with the method mentioned here, here and here. The idea is simple: NDSolve don't know how to disretize your system, so we do it ourselves. I'll use pdetoode for the disretization of the derivative term and Gaussian quadrature formula for the discretization of integral:

total = 200; L = 10; tend = 100; points = 25; difforder = 4; domain = {-L/2, L/2}; {nodes, weights} = Most[NIntegrate`GaussRuleData[points, MachinePrecision]]; midgrid = Rescale[nodes, {0, 1}, domain]; intrule = int -> -Subtract @@ domain weights.Map[Function[x, A[x][t]], midgrid]; grid = Flatten[{First@domain, midgrid, Last@domain}]; (*Definition of pdetoode isn't included in this post, please find it in the link above.*) ptoofunc = pdetoode[A[x, t], t, grid, difforder, True]; eq = {D[A[x, t], {t, 1}] == Plus[0.005 D[A[x, t], {x, 2}], D[0.1 Exp[-0.5 (x - 0.5)^2] A[x, t], {x, 1}], 0.1 B[t] - 0.2 A[x, t]], B[t] == (total - int)/L }; ic = A[x, 0] == 10; odeic = ptoofunc@ic; ode = {ptoofunc@First@eq, Last@eq /. intrule}; sollst = NDSolveValue[{ode, odeic}, {A /@ grid, B}, {t, 0, tend}]; solA = ListInterpolation[ Developer`ToPackedArray@#["ValuesOnGrid"] & /@ #, {grid, #[[1]][ "Coordinates"][[1]]}] &@sollst[[1]] solB = sollst[[2]] ListLinePlot@solB Plot3D[solA[x, t], {x, ##}, {t, 0, tend}, PlotRange -> All] & @@ domain 

The results look the same as those in Akku14's answer so I'd like to omit them here.

Well, I admit this solution is a bit advanced, but it avoids iteration so it's quite fast.

Your problem can be solved with the method mentioned here, here and here. The idea is simple: NDSolve don't know how to disretize your system, so we do it ourselves. I'll use pdetoode for the disretization of the derivative term and Gaussian quadrature formula for the discretization of integral:

total = 200; L = 10; tend = 100; points = 25; difforder = 4; domain = {-L/2, L/2}; {nodes, weights} = Most[NIntegrate`GaussRuleData[points, MachinePrecision]]; midgrid = Rescale[nodes, {0, 1}, domain]; intrule = int -> -Subtract @@ domain weights.Map[Function[x, A[x][t]], midgrid]; grid = Flatten[{First@domain, midgrid, Last@domain}]; (*Definition of pdetoode isn't included in this post, please find it in the link above.*) ptoofunc = pdetoode[A[x, t], t, grid, difforder, True]; eq = {D[A[x, t], {t, 1}] == Plus[0.005 D[A[x, t], {x, 2}], D[0.1 Exp[-0.5 (x - 0.5)^2] A[x, t], {x, 1}], 0.1 B[t] - 0.2 A[x, t]], B[t] == (total - int)/L }; ic = A[x, 0] == 10; odeic = ptoofunc@ic; ode = {ptoofunc@First@eq, Last@eq /. intrule}; sollst = NDSolveValue[{ode, odeic}, {A /@ grid, B}, {t, 0, tend}]; solA = rebuild[sollst[[1]], grid] solB = sollst[[2]] ListLinePlot@solB (* Notice time is the 1st argument of solA *) Plot3D[solA[t, x], {x, ##}, {t, 0, tend}, PlotRange -> All] & @@ domain 

The results look the same as those in Akku14's answer so I'd like to omit them here.

Well, I admit this solution is a bit advanced, but it avoids iteration so it's quite fast.

pdetoode now supports periodic b.c.
Source Link
xzczd
  • 71.6k
  • 10
  • 184
  • 524

Your problem can be solved with the method mentioned here, here and here. The idea is simple: NDSolve don't know how to disretize your system, so we do it ourselves. I'll use pdetoode for the disretization of the derivative term and Gaussian quadrature formula for the discretization of integral:

total = 200; L = 10; tend = 100; points = 25; difforder = 4; domain = {-L/2, L/2}; {nodes, weights} = Most[NIntegrate`GaussRuleData[points, MachinePrecision]]; midgrid = Rescale[nodes, {0, 1}, domain]; intrule = int -> -Subtract @@ domain weights.Map[Function[x, A[x][t]], midgrid]; grid = Flatten[{First@domain, midgrid, Last@domain}]; (*Definition of pdetoode isn't included in this post, please find it in the link above.*) fdd[a__] := NDSolve`FiniteDifferenceDerivative[a, PeriodicInterpolation -> True]; ptoofunc = pdetoode[A[x, t], t, grid, difforder];difforder, True]; eq = {D[A[x, t], {t, 1}] == Plus[0.005 D[A[x, t], {x, 2}], D[0.1 Exp[-0.5 (x - 0.5)^2] A[x, t], {x, 1}], 0.1 B[t] - 0.2 A[x, t]], B[t] == (total - int)/L }; ic = A[x, 0] == 10; odeic = ptoofunc@ic; ode = {ptoofunc@First@eq, Last@eq /. intrule}; sollst = NDSolveValue[{ode, odeic}, {A /@ grid, B}, {t, 0, tend}]; solA = ListInterpolation[ Developer`ToPackedArray@#["ValuesOnGrid"] & /@ #, {grid, #[[1]][ "Coordinates"][[1]]}] &@sollst[[1]] solB = sollst[[2]] fdd[a__] := NDSolve`FiniteDifferenceDerivative@a; ListLinePlot@solB Plot3D[solA[x, t], {x, ##}, {t, 0, tend}, PlotRange -> All] & @@ domain 

The results look the same as those in Akku14's answer so I'd like to omit them here.

Well, I admit this solution is a bit advanced, but it avoids iteration so it's quite fast.

Your problem can be solved with the method mentioned here, here and here. The idea is simple: NDSolve don't know how to disretize your system, so we do it ourselves. I'll use pdetoode for the disretization of the derivative term and Gaussian quadrature formula for the discretization of integral:

total = 200; L = 10; tend = 100; points = 25; difforder = 4; domain = {-L/2, L/2}; {nodes, weights} = Most[NIntegrate`GaussRuleData[points, MachinePrecision]]; midgrid = Rescale[nodes, {0, 1}, domain]; intrule = int -> -Subtract @@ domain weights.Map[Function[x, A[x][t]], midgrid]; grid = Flatten[{First@domain, midgrid, Last@domain}]; (*Definition of pdetoode isn't included in this post, please find it in the link above.*) fdd[a__] := NDSolve`FiniteDifferenceDerivative[a, PeriodicInterpolation -> True]; ptoofunc = pdetoode[A[x, t], t, grid, difforder]; eq = {D[A[x, t], {t, 1}] == Plus[0.005 D[A[x, t], {x, 2}], D[0.1 Exp[-0.5 (x - 0.5)^2] A[x, t], {x, 1}], 0.1 B[t] - 0.2 A[x, t]], B[t] == (total - int)/L }; ic = A[x, 0] == 10; odeic = ptoofunc@ic; ode = {ptoofunc@First@eq, Last@eq /. intrule}; sollst = NDSolveValue[{ode, odeic}, {A /@ grid, B}, {t, 0, tend}]; solA = ListInterpolation[ Developer`ToPackedArray@#["ValuesOnGrid"] & /@ #, {grid, #[[1]][ "Coordinates"][[1]]}] &@sollst[[1]] solB = sollst[[2]] fdd[a__] := NDSolve`FiniteDifferenceDerivative@a; ListLinePlot@solB Plot3D[solA[x, t], {x, ##}, {t, 0, tend}, PlotRange -> All] & @@ domain 

The results look the same as those in Akku14's answer so I'd like to omit them here.

Well, I admit this solution is a bit advanced, but it avoids iteration so it's quite fast.

Your problem can be solved with the method mentioned here, here and here. The idea is simple: NDSolve don't know how to disretize your system, so we do it ourselves. I'll use pdetoode for the disretization of the derivative term and Gaussian quadrature formula for the discretization of integral:

total = 200; L = 10; tend = 100; points = 25; difforder = 4; domain = {-L/2, L/2}; {nodes, weights} = Most[NIntegrate`GaussRuleData[points, MachinePrecision]]; midgrid = Rescale[nodes, {0, 1}, domain]; intrule = int -> -Subtract @@ domain weights.Map[Function[x, A[x][t]], midgrid]; grid = Flatten[{First@domain, midgrid, Last@domain}]; (*Definition of pdetoode isn't included in this post, please find it in the link above.*) ptoofunc = pdetoode[A[x, t], t, grid, difforder, True]; eq = {D[A[x, t], {t, 1}] == Plus[0.005 D[A[x, t], {x, 2}], D[0.1 Exp[-0.5 (x - 0.5)^2] A[x, t], {x, 1}], 0.1 B[t] - 0.2 A[x, t]], B[t] == (total - int)/L }; ic = A[x, 0] == 10; odeic = ptoofunc@ic; ode = {ptoofunc@First@eq, Last@eq /. intrule}; sollst = NDSolveValue[{ode, odeic}, {A /@ grid, B}, {t, 0, tend}]; solA = ListInterpolation[ Developer`ToPackedArray@#["ValuesOnGrid"] & /@ #, {grid, #[[1]][ "Coordinates"][[1]]}] &@sollst[[1]] solB = sollst[[2]] ListLinePlot@solB Plot3D[solA[x, t], {x, ##}, {t, 0, tend}, PlotRange -> All] & @@ domain 

The results look the same as those in Akku14's answer so I'd like to omit them here.

Well, I admit this solution is a bit advanced, but it avoids iteration so it's quite fast.

added 60 characters in body
Source Link
xzczd
  • 71.6k
  • 10
  • 184
  • 524
Loading
deleted 79 characters in body
Source Link
xzczd
  • 71.6k
  • 10
  • 184
  • 524
Loading
Source Link
xzczd
  • 71.6k
  • 10
  • 184
  • 524
Loading