Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain (and improve) accuracy #38

Open
jwuttke opened this issue Jun 16, 2021 · 0 comments
Open

Explain (and improve) accuracy #38

jwuttke opened this issue Jun 16, 2021 · 0 comments

Comments

@jwuttke
Copy link

jwuttke commented Jun 16, 2021

This code

#!/usr/bin/env python3

import numpy as np
import chebpy as ch

def g(x):
    return .3+.02*x+abs(x)**1.8

ch.core.settings.userPrefs.eps = 1e-18
R = ch.chebfun(g, [-1,1])

n = 17
for i in range(n):
    x = -1+2*i/(n-1)
    print(x, g(x), R(x), g(x)-R(x))

generates this output (on a x86_64 with Python 3.9.2, numpy 1.19.5-1 from Debian):

-1.0 1.28 1.280000000000984 -9.838796444228137e-13
-0.875 1.0688474729277848 1.0688474729268571 9.277023593767808e-13
-0.75 0.8808134105899568 0.8808134105891541 8.026912468039882e-13
-0.625 0.7166252122289523 0.716625212227441 1.511235581119763e-12
-0.5 0.5771745887492588 0.5771745887502417 -9.829914660031136e-13
-0.375 0.4636024711574641 0.4636024711595356 -2.0715096304968483e-12
-0.25 0.37746924442330587 0.37746924441954577 3.76010333980048e-12
-0.125 0.32118307135172497 0.32118307134976054 1.964428619771752e-12
0.0 0.3 0.3000000070720421 -7.072042118583255e-09
0.125 0.326183071351725 0.32618307134976054 1.964428619771752e-12
0.25 0.3874692444233059 0.3874692444195459 3.759992317498018e-12
0.375 0.4786024711574641 0.4786024711595357 -2.0715651416480796e-12
0.5 0.5971745887492588 0.5971745887502418 -9.829914660031136e-13
0.625 0.7416252122289522 0.7416252122274409 1.511235581119763e-12
0.75 0.9108134105899568 0.9108134105891542 8.025802245015257e-13
0.875 1.103847472927785 1.1038474729268573 9.277023593767808e-13
1.0 1.32 1.3200000000009837 -9.836575998178887e-13

Before setting eps to 1e-18, the output was

-1.0 1.28 1.279999999967151 3.2849056808004207e-11
-0.875 1.0688474729277848 1.0688474728987043 2.9080515773216575e-11
-0.75 0.8808134105899568 0.8808134106073755 -1.741873312255393e-11
-0.625 0.7166252122289523 0.71662521223807 -9.117706589734098e-12
-0.5 0.5771745887492588 0.5771745888149571 -6.569833566061334e-11
-0.375 0.4636024711574641 0.46360247122168646 -6.422234966052542e-11
-0.25 0.37746924442330587 0.37746924437881435 4.4491521578038373e-11
-0.125 0.32118307135172497 0.32118307153050574 -1.7878076796762343e-10
0.0 0.3 0.30000006714646454 -6.714646455519002e-08
0.125 0.326183071351725 0.32618307153050563 -1.7878065694532097e-10
0.25 0.3874692444233059 0.38746924437881436 4.4491521578038373e-11
0.375 0.4786024711574641 0.4786024712216866 -6.422246068282789e-11
0.5 0.5971745887492588 0.5971745888149573 -6.569855770521826e-11
0.625 0.7416252122289522 0.7416252122380699 -9.117706589734098e-12
0.75 0.9108134105899568 0.9108134106073754 -1.741862210025147e-11
0.875 1.103847472927785 1.1038474728987047 2.908029372861165e-11
1.0 1.32 1.3199999999671506 3.2849500897214057e-11

Suggestions for improvement:

  • Document userPrefs (in README or whereever), advise on settings for eps.
  • Why is accuracy lowest at x=0? I'd guess that this can be overcome by enforcing even (or odd?) order of the approximant.
  • For eps << 1e-18, we get a "UserWarning: The Chebtech2 constructor did not converge: using 65537 points." Upon this warning, the user does not know whether the resulting polynomial can be trusted.
  • The warning can be overcome by increasing core.settings.userPrefs.maxpow2. This needs documentation.
  • The actual accuracy is much lower than eps. Is there a way to inform the user about the maximum error?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants