Message Boards Message Boards

DSolve has reached the maximum number of calculations

Posted 10 months ago

I reached the maximum number of calculations when using DSolve to calculate differential equations, which makes it impossible to fully solve. How can I expand the number of calculations of DSolve?

Here is my code:

system = {vi q[t] == l iL'[t] + vC[t], 
   vC'[t] == iL[t]/c - vC[t]/(r c), vC[0] == 0, iL[0] == 0};
control = {q[0] == 1, 
   WhenEvent[Mod[t, \[Tau]] == (2/3) \[Tau], q[t] -> 0], 
   WhenEvent[Mod[t, \[Tau]] == 0, q[t] -> 1]};
pars = {vi -> 24, r -> 22, l -> 2 10^-2, 
   c -> 1 10^-4, \[Tau] -> 2.5 10^-5};
sol = DSolve[{system, control} /. pars, {vC, iL, q}, {t, 0, .2}, 
   DiscreteVariables -> q];
a = Evaluate[iL[t] /. sol];
b = Evaluate[vC[t] /. sol];
Plot[a, {t, 0, 0.2}, AxesLabel -> {"s", "il[t]/A"}, 
 PlotLegends -> {"LinearlyImplicitEuler"}, PlotStyle -> {Red}, 
 PlotRange -> All]
Plot[b, {t, 0, 0.2}, AxesLabel -> {"s", "vc[t]/V"}, 
 PlotLegends -> {"LinearlyImplicitEuler"}, PlotStyle -> {Blue}, 
 PlotRange -> All]
POSTED BY: James James
7 Replies

In this case I would try Piecewise instead of WhenEvent:

\[Tau] = 1/9;
pwQ[t_] = PiecewiseExpand[Boole[0 <= Mod[t, \[Tau]] < (2/3)*\[Tau]],
   0 <= t <= 3 \[Tau]];
spSystem = {vi  pwQ[t] == l  iL'[t] + vC[t],
   vC'[t] == iL[t]/c - vC[t]/(r  c),
   vC[0] == 0, iL[0] == 0};
pwSol = DSolve[system2, {vC, iL},
    {t, 0, 2/10}] // Simplify;
Simplify[spSystem /. pwSol[[1]] /.
  {{t -> 1/100}, {t -> 1/9 - 1/27 + 1/30}, {t -> 1/9 + 1/27}}]
POSTED BY: Gianluca Gorni
Posted 10 months ago

When I expanded the t-value range of the function pwQ[t_] and ran the program, the system prompted "PienewiseExpand cannot convert Floor [4000. \ t] to Pienewise form because the required number of segmented cases to search exceeds the internal limit of $MaxPienewiseCases=100".

Can I try changing the size of the internal limit $MaxPierceCases?

program code:

\[Tau] = 2.5 10^-4;
pwQ[t_] = 
  PiecewiseExpand[Boole[0 <= Mod[t, \[Tau]] < (2/3)*\[Tau]], 
   0 <= t <= 3/100];
pars = {vi -> 24, r -> 22, l -> 2 10^-2, c -> 1 10^-4};
spSystem = {vi pwQ[t] == l iL'[t] + vC[t], 
   vC'[t] == iL[t]/c - vC[t]/(r c), vC[0] == 0, iL[0] == 0};
pwSol = DSolve[spSystem /. pars, {vC, iL}, {t, 0, 2/100}] // 
   Simplify;
a = Evaluate[iL[t] /. pwSol];
b = Evaluate[vC[t] /. pwSol];
Plot[a, {t, 0, 0.02}, AxesLabel -> {"s", "il[t]/A"}, 
 PlotLegends -> {"LinearlyImplicitEuler"}, PlotStyle -> {Red}, 
 PlotRange -> All]
Plot[b, {t, 0, 0.02}, AxesLabel -> {"s", "vc[t]/V"}, 
 PlotLegends -> {"LinearlyImplicitEuler"}, PlotStyle -> {Blue}, 
 PlotRange -> All]
POSTED BY: James James

I didn't know about $MaxPienewiseCases. You can try increasing it Do you know in advance how many intervals you need? For a full analytical solution I would use exact numbers:

\[Tau] = 25/10 10^-4;
POSTED BY: Gianluca Gorni
Posted 10 months ago

Yes, I found the help document for

$MaxPickewiseCases

and directly set $MaxPickewiseCases=(the range you want). The link to the help document isenter link description here

But my code doesn't produce any results...

\[Tau] = 25/10 10^-4;
pwQ[t_] = 
  PiecewiseExpand[Boole[0 <= Mod[t, \[Tau]] < (2/3)*\[Tau]], 
   0 <= t <= 3/100];
$MaxPiecewiseCases = 200;
pars = {vi -> 24, r -> 22, l -> 2 10^-2, c -> 1 10^-4};
spSystem = {vi pwQ[t] == l iL'[t] + vC[t], 
   vC'[t] == iL[t]/c - vC[t]/(r c), vC[0] == 0, iL[0] == 0};
pwSol = DSolve[spSystem /. pars, {vC, iL}, {t, 0, 2/100}] // 
   Simplify;
a = Evaluate[iL[t] /. pwSol];
b = Evaluate[vC[t] /. pwSol];
Plot[a, {t, 0, 0.02}, AxesLabel -> {"s", "il[t]/A"}, 
 PlotLegends -> {"LinearlyImplicitEuler"}, PlotStyle -> {Red}, 
 PlotRange -> All]
Plot[b, {t, 0, 0.02}, AxesLabel -> {"s", "vc[t]/V"}, 
 PlotLegends -> {"LinearlyImplicitEuler"}, PlotStyle -> {Blue}, 
 PlotRange -> All]
POSTED BY: James James

Have you tried NDSolve instead of Solve?

POSTED BY: Gianluca Gorni
Posted 10 months ago

Because I want to obtain an exact solution, I am using DSolve instead of NDSolve.

POSTED BY: James James

With this kind of thinking, we have many thousands of pages of analytical solutions. Do you really need an analytical solution?

After calculations by DSolve, conclusions can be drawn ,solution looks off than numeric one ,maybe a bug in DSolve.

Even for parameter:

\[Tau] -> 2.5 10^-5

DSolve probably give you not correct solution.See attached file.

Regards M.I

Attachments:
POSTED BY: Mariusz Iwaniuk
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