0
$\begingroup$

After ODE, plot within {t,0,50} and plot within {t,0,60} have quite different results at some time instants.

Clear["Global`*"];
F0 = 14160; FREF = 40; C0 = 40*10^-6; C1 = 360*10^-6; C2 = 20*10^-6; R1 = 14000; R2 = 1000; IP = 60*10^-6; IN = 60*10^-6; KVCO = 300; DELAY = 5; DN[t_, x_] := 360 + x/100;
sol = NDSolve[{R1*C1*VC1'[t] + VC1[t] == VC0[t], R2*C2*VC2'[t] + VC2[t] == VC0[t], C0*VC0'[t] + C1*VC1'[t] + C2*VC2'[t] == ICP[t], \[Phi]'[t] == 2 \[Pi]*(KVCO*VC2[t] + F0)/DN[t, n[t]], VC0[0] == 0, VC1[0] == 0,VC2[0] == 0, \[Phi][0] == 0, ICP[0] == 0, n[0] == 0, WhenEvent[Cos[\[Phi][t]] > 0 && ICP[t] == 0, {ICP[t] -> -IN, n[t] -> n[t] + 1}], WhenEvent[Cos[\[Phi][t]] > 0 && ICP[t] == IP, {ICP[t] -> 0, n[t] -> n[t] + 1}], WhenEvent[Cos[2 \[Pi]*FREF*(t - DELAY)] > 0 && ICP[t] == 0 && t >= DELAY, {ICP[t] -> IP}], WhenEvent[Cos[2 \[Pi]*FREF*(t - DELAY)] > 0 && ICP[t] == -IN && t >= DELAY, {ICP[t] -> 0}]}, {VC0, VC1, VC2, \[Phi]}, {t, 0, 60}, DiscreteVariables -> {n, ICP}];
Plot[VC2[t] /. sol, {t, 0, 50}]
Plot[VC2[t] /. sol, {t, 0, 60}]

You can see that at t=20 around, the curves are different(the second one is incorrect). I tried WorkingPrecision and PerformanceGoal, but neither works.

{t, 0, 50}{t, 0, 60}

$\endgroup$
4
  • $\begingroup$ PlotPoints -> 100. $\endgroup$
    – xzczd
    Commented Dec 7, 2023 at 2:39
  • $\begingroup$ If you want to check all the points inside the solution of NDSolve: VC2 /. sol // First // ListPlot. This is an undocumented feature mentioned here: mathematica.stackexchange.com/a/134223/1871 $\endgroup$
    – xzczd
    Commented Dec 7, 2023 at 2:42
  • $\begingroup$ Possible duplicate of mathematica.stackexchange.com/q/164382/1871 (Oh I shouldn't have voted so fast…) $\endgroup$
    – xzczd
    Commented Dec 7, 2023 at 2:47
  • $\begingroup$ @xzczd Thank you very much. $\endgroup$
    – metroidman
    Commented Dec 7, 2023 at 9:56

0

Browse other questions tagged or ask your own question.