I solved the most basic low-pass filter using NDSolve in Mathematica and LTSpice. The solution provided by Mathematica seems to lack precision. I tried to deal with WorkingPrecision but I didn't manage to get it to improve the solution. Could you please help me with precision improvement?

Here is the electrical circuit in LTSpice:


The solution for potential difference across the capacitor C1 solved by LTSpice is below:


Here is my code in Mathematica:

freq = 10000;
vs[t_] = 20 + 30*Sin[2*Pi*freq*t];
r1 = 5;
c1 = 0.0001;
plotx = 1/freq*50;

sol = NDSolve[{vs[t] == r1*c1*vc1'[t] + vc1[t], vc1[0] == 0}, 
   vc1[t], {t, 0, 0.060}];
Plot[vc1[t] /. sol, {t, 0, plotx}]

which gives this Plot:


As you can see from the plots above, the solution by LTSpice provides better precision by default.

  • $\begingroup$ Try increasing the setting of PlotPoints in Plot[], e.g. Plot[vc1[t] /. sol, {t, 0, plotx}, PlotPoints -> 45]. $\endgroup$ Commented Nov 16, 2017 at 2:37
  • $\begingroup$ @J.M., that worked! And PlotPoints -> 15 worked as well. I added Mesh -> All to see each point on the plot. Could you explain the mechanism that Mathematica uses to choose a number of PlotPoints by default? I tried to find the value for PlotPoints that would correspond to the result without specifying PlotPoints, and I couldn't find it. $\endgroup$ Commented Nov 16, 2017 at 2:44
  • $\begingroup$ Unfortunately, the mechanism for automatically choosing PlotPoints does not seem to be publicly known. $\endgroup$ Commented Nov 16, 2017 at 2:46

1 Answer 1


This is just plotting issue. Try increasing number of plot points


Mathematica graphics

  • $\begingroup$ Thank you and J. M. very much for the fast answer! It is indeed a plotting issue. $\endgroup$ Commented Nov 16, 2017 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.