Message Boards Message Boards

Backward Euler error estimation formula vs. DSolve and NDSolve

Posted 1 year ago

First, I use DSolve and NDSolve to solve the same differential equation group, and NDSolve specifies the reverse Euler method with a fixed step size of dt=0.00006, so as to find out the truncation error introduced by the reverse Euler method.

The following are the codes for DSolve and NDSolve:

(*DSolve and NDSolve,dt=0.00006*)
tstart = 0;
tend = 0.08;
dt = 0.00006;
n = (tend - tstart)/dt;
(*DSolve*)
sol1 = DSolve[{l il'[t] == vl[t], c vc'[t] == ic[t], 
    ir[t] == -ic[t] + il[t], vl[t] == 24 - vc[t], vr[t] == vc[t], 
    vr[t] == r ir[t], il[0] == 0, vc[0] == 0}, {ir[t], il[t], ic[t], 
    vr[t], vl[t], vc[t]}, t];
{il[t_], vc[t_]} = {il[t], vc[t]} /. sol1[[1]];
pars1 = {r -> 22, l -> 1/5, c -> 1/10000};
a = Evaluate[il[t] /. pars1];
b = Evaluate[vc[t] /. pars1];
Dil = Table[a, {t, 0, tend, dt}, 1];
Dvc = Table[b, {t, 0, tend, dt}, 1];
(*NDSolve*)
components1 = {vI == ll iL'[t] + vC[t], 
   vC'[t] == iL[t]/cc - vC[t]/(rr cc), vC[0] == 0, iL[0] == 0};
pars2 = {vI -> 24, rr -> 22, ll -> 1/5, cc -> 1/10000};
sol2 = NDSolve[{components1} /. pars2, {iL, vC}, {t, 0, tend}, 
   StartingStepSize -> dt, 
   Method -> {"FixedStep", Method -> {"LinearlyImplicitEuler"}}];
a = Evaluate[iL[t] /. sol2[[1]]];
b = Evaluate[vC[t] /. sol2[[1]]];
NDil = Table[a, {t, 0, tend, dt}, 1];
NDvc = Table[b, {t, 0, tend, dt}, 1];
(*Find truncation error*)
errort = Table[tstart + dt*i, {i, 0, n}];
ilerror = Table[0, {i, 0, n}];
vcerror = Table[0, {i, 0, n}];
For[k = 1, k < n + 1, k++,
  ilerror[[k]] = Abs[Dil[[k, 1]] - NDil[[k, 1]]];
  vcerror[[k]] = Abs[Dvc[[k, 1]] - NDvc[[k, 1]]];
  ];
p1 = Table[Transpose[{errort, ilerror}], 1];
p2 = Table[Transpose[{errort, vcerror}], 1];
ListLinePlot[p1, AxesLabel -> {"s", "il[t]/A"}, 
 PlotLegends -> {"LinearlyImplicitEuler"}, PlotStyle -> {Red}, 
 PlotRange -> All]
ListLinePlot[p2, AxesLabel -> {"s", "vc[t]/V"}, 
 PlotLegends -> {"LinearlyImplicitEuler"}, PlotStyle -> {Blue}, 
 PlotRange -> All]
Max[ilerror]
Max[vcerror]

Running results: enter image description here

From the operating results, it can be seen that the maximum truncation errors of il and vc are 0.00191949 and 0.0482568, respectively.

Then, I used the reverse Euler error estimation formula in the book (as shown in the picture below) to calculate the maximum truncation error (this formula is on page 130 of the attached book), and the calculation code is as follows: enter image description here

dt = 0.00006;
tend = 0.08;
sol1 = DSolve[{l il'[t] == vl[t], c vc'[t] == ic[t], 
    ir[t] == -ic[t] + il[t], vl[t] == 24 - vc[t], vr[t] == vc[t], 
    vr[t] == r ir[t], il[0] == 0, vc[0] == 0}, {ir[t], il[t], ic[t], 
    vr[t], vl[t], vc[t]}, t];
{il[t_], vc[t_]} = {il[t], vc[t]} /. sol1[[1]];
pars1 = {r -> 22, l -> 1/5, c -> 1/10000};
a = Evaluate[il[t] /. pars1];
b = Evaluate[vc[t] /. pars1];
dil = D[a, t];
dvc = D[b, t];
Subscript[dil, n + 1] = ReplaceAll[dil, t -> t + dt];
Subscript[dvc, n + 1] = ReplaceAll[dvc, t -> t + dt];
ilerror = -1/2*dt*(Subscript[dil, n + 1] - dil);
vcerror = -1/2*dt*(Subscript[dvc, n + 1] - dvc);
MaxValue[{ilerror, 0 <= t <= tend}, t]
MaxValue[{vcerror, 0 <= t <= tend}, t]

Using this formula, the maximum truncation errors for il and vc are 0.0000175759 and 0.000286032, respectively.

From the above, it can be seen that the maximum truncation errors of il and vc calculated using the reverse Euler error estimation formula in the book are not the same as those calculated by DSolve and NDSolve. What is the reason for this? I have carefully checked the code and there are no issues.

Attachments:
POSTED BY: James James
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract