Commit 2b63a016 authored by Yuri Chornoivan's avatar Yuri Chornoivan

Keep cumulated error negligible for rapidly increasing functions

The current scheme violates Runge-Kutta condition on error O(h^4) when dy is too high. This leads to visible shifting and discontinuities on the plots of integrals for e^x^2, e^abs(x), etc.

BUG: 341256

Test Plan:
1. Compile and install KmPlot.
2. Create the Cartesian plot "f(x) = e^x^2".
3. Switch to the "Integral" tab and tick the "Show integral" item.
4. Try to change the scale (Ctrl+mouse wheel). The integral curve should be plotted as expected (no discontinuities, no extra lines on Ox).

f(x)=e^x^2 and its integral

Before the patch:
After the patch:

Reviewers: #kde_edu

Subscribers: aacid, cfeck, kde-edu

Tags: #kde_edu

Differential Revision:
parent 8852a986
......@@ -361,11 +361,12 @@ double XParser::differential( Equation * eq, DifferentialState * state, double x
m_y.addRK4( dx, m_k1, m_k2, m_k3, m_k4 );
if ( !std::isfinite(m_y[0]) )
// The condition on the total accumulated error (O(dx^5)) should not be violated for rapidly increasing functions, e.g. e^x^2
if ( !std::isfinite(m_y[0]) || qAbs((state->y[0]-m_y[0])*dx*dx) > 1)
differentialFinite = false;
return 0;
return 1e200*((m_y[0] > 0) - (m_y[0] < 0));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment