this is a follow up question to Convergence rate vs convergence order
I guess the whole confusion about how rate vs. order of convergence also came from the implementations I saw.
For example, for fixpoint iteration, I saw this: [was part ofa fixpoint iteration]
#Function to calculate order of convergence
def konvord(x,e):
p = np.log(e[2:]/e[1:-1]) / np.log(e[1:-1]/e[:-2])
mw = p.sum()/len(p)
return mw #
#Function to calculate rate of convergence (for linear convergence)
def konvrate(x,e):
n = len(e)
k = np.arange(0,n) #array mit 0,1,2,3,...,n-1 (Iterationsschritte)
fit = np.polyfit(k,np.log(e),1)
L = np.exp(fit[0])
return L
But then I look at code which does some quadratur and there we calculate the order of convergence using this:
p = - polyfit(log(n), log(err), 1)[0]
These implementations are confusing me. I think, that the last one makes sense. But I can't really see, how konvord() gives us an order of convergence and how konvrate() gives us a rate of convergence. To me, konvord() rather looks like it gives the rate of convergence for $p=1$. The function konvrate() should probably be to get an exact value of the order of convergence, but it only works for $p$ very close to $1$ [hence only the error is in a log in the polyfit]
What don't I get? Can someone explain me all three implementations please? What's their idea?
Edit: I tred to play around with it using a fixpointiteration: https://hastebin.com/zevuhiqaya.py (with output) and all three give different results.
Edit: I also wanted to say, how I would do it, ignoring all the above:
For the order of convergence, I have $p\approx\frac{\log(e_{k+1})-\log(e_{k})}{\log(e_k)-\log(e_{k-1})}$ I'd implement this using polyfit. I'd get a linear graph and it's slope would be my $p$.(This is the last from the above implementations)
For getting the rate of convergence for $p=1$ I'd just do the ratio test. I think, that's what he tried at konvrate(). For an arbritary $p$ I'd first calculate p and then basically do the ratio test again.
Question 1: Aren't konvord() and the last implementation the same? If so, why do they result in different results?
Question 2: Is konvrate() correctly implemented?
Question 3: I'm sure, that the function konvord() and the last implementation should result in the same result. What exactly should n be there? I think I didn't quiet get the idea behind it.