In a previous post on the solution of an ODE with a boundary conditon at infinty I had some excelent help from xzczd and am now returning with a further problem along the same lines. I have used the code pdetoae which may be found in this link.
The problem is that the solution has oscillations. These oscillations are particularly clear on the first and second derivatives of the solution which I need.
The ODE, initial and final conditions and the variables are:
inf = 15;
nn = 2; eqns = {(-α +
2*α*Derivative[1][a[0]][y]^2 + α*
Derivative[1][a[1]][y]^2 + α*
Derivative[1][a[2]][y]^2 + α*
Derivative[1][b[1]][y]^2 + α*Derivative[1][b[2]][y]^2 -
2*α*a[0][y]*Derivative[2][a[0]][y] - α*a[1][y]*
Derivative[2][a[1]][y] - α*a[2][y]*
Derivative[2][a[2]][y] - α*b[1][y]*
Derivative[2][b[1]][y] - α*b[2][y]*
Derivative[2][b[2]][y] - 2*Derivative[3][a[0]][y])/2 ==
0, (4*α*Derivative[1][a[0]][y]*Derivative[1][a[1]][y] +
2*α*Derivative[1][a[1]][y]*Derivative[1][a[2]][y] +
2*Derivative[1][b[1]][y] +
2*α*Derivative[1][b[1]][y]*Derivative[1][b[2]][y] -
2*α*a[1][y]*Derivative[2][a[0]][y] -
2*α*a[0][y]*Derivative[2][a[1]][y] - α*a[2][y]*
Derivative[2][a[1]][y] - α*a[1][y]*
Derivative[2][a[2]][y] - α*b[2][y]*
Derivative[2][b[1]][y] - α*b[1][y]*
Derivative[2][b[2]][y] - 2*Derivative[3][a[1]][y])/2 ==
0, (2 - 2*Derivative[1][a[1]][y] +
4*α*Derivative[1][a[0]][y]*Derivative[1][b[1]][y] -
2*α*Derivative[1][a[2]][y]*Derivative[1][b[1]][y] +
2*α*Derivative[1][a[1]][y]*Derivative[1][b[2]][y] -
2*α*b[1][y]*Derivative[2][a[0]][y] - α*b[2][y]*
Derivative[2][a[1]][y] + α*b[1][y]*
Derivative[2][a[2]][y] -
2*α*a[0][y]*Derivative[2][b[1]][y] + α*a[2][y]*
Derivative[2][b[1]][y] - α*a[1][y]*
Derivative[2][b[2]][y] - 2*Derivative[3][b[1]][y])/2 ==
0, (-α + α*Derivative[1][a[1]][y]^2 +
4*α*Derivative[1][a[0]][y]*
Derivative[1][a[2]][y] - α*Derivative[1][b[1]][y]^2 +
4*Derivative[1][b[2]][y] -
2*α*a[2][y]*Derivative[2][a[0]][y] - α*a[1][y]*
Derivative[2][a[1]][y] -
2*α*a[0][y]*Derivative[2][a[2]][y] + α*b[1][y]*
Derivative[2][b[1]][y] - 2*Derivative[3][a[2]][y])/2 ==
0, (-4*Derivative[1][a[2]][y] +
2*α*Derivative[1][a[1]][y]*Derivative[1][b[1]][y] +
4*α*Derivative[1][a[0]][y]*Derivative[1][b[2]][y] -
2*α*b[2][y]*Derivative[2][a[0]][y] - α*b[1][y]*
Derivative[2][a[1]][y] - α*a[1][y]*
Derivative[2][b[1]][y] -
2*α*a[0][y]*Derivative[2][b[2]][y] -
2*Derivative[3][b[2]][y])/2 == 0};
ic0 = {a[0][0] == 0, Derivative[1][a[0]][0] == 0, a[1][0] == 0,
Derivative[1][a[1]][0] == 0, b[1][0] == 0,
Derivative[1][b[1]][0] == 0, a[2][0] == 0,
Derivative[1][a[2]][0] == 0, b[2][0] == 0,
Derivative[1][b[2]][0] == 0};
bc = {Derivative[2][a[0]][15] == 0, Derivative[1][a[1]][15] == 1,
Derivative[1][b[1]][15] == 0, Derivative[1][a[2]][15] == 0,
Derivative[1][b[2]][15] == 0};
var = {a[0], a[1], b[1], a[2], b[2]};
The code to make the grid, use pdetoae and solve is:
points = 200;
grid = Array[# &, points, {0, inf}];
difforder = 4;
ptoafunc = pdetoae[var[y], grid, difforder];
del = #[[3 ;; -2]] &;
ae = del /@ ptoafunc@eqns;
aebc = ptoafunc@{ic0, bc};
sol = Partition[
With[{guess = 1},
FindRoot[{ae, aebc} /. {α -> 0.5},
Flatten[Table[{var[[i]][y], guess}, {i, 2 nn + 1}, {y, grid}],
1],
MaxIterations -> 500]][[All, -1]], points];
I now look at the solutions and their first and second differences:
diffs = Differences[#] & /@ sol;
diffs2 = Differences[#, 2] & /@ sol;
sols = Transpose[{grid, #}] & /@ sol;
dsols = Transpose[{Most[grid], #}] & /@ diffs;
dsols2 = Transpose[{Drop[grid, -2], #}] & /@ diffs2;
ListLinePlot[sols, PlotRange -> All]
ListLinePlot[dsols, PlotRange -> All]
ListLinePlot[dsols2, PlotRange -> All]
As you can see the solution looks good but the first and second differences show an oscillation that is associated with the grid. Is this inevitable with a finite difference method?
I can smooth the solution using various methods but I am not sure if this is valid. How do I get rid of the oscillations?
Thanks