How can one read the order of convergence from a loglog-graph?

1.5k Views Asked by At

I am making a task which includes running a Monte Carlo simulation and calculating the order of convergence experimentally. I have to calculate (or approximate) the order of convergence using different methods.

One method is reading it from the loglog-graph. I know that the rate of convergence can be read by retrieving the slope of this graph. The problem is that I can't seem to find a way to read the order of convergence from the graph.

So my question is: how can the order of convergence be read from the loglog-graph?

1

There are 1 best solutions below

0
On

Consider that the real value of output variable is $\alpha$. Following relation provides you the value of output variable for $n$ iterations.
$$\alpha_{MC}=\frac{1}{n}\sum_{i=1}^na_i$$ Where $i\in[1,n]$ are the iterations and $a_i$ is the value of output variable for $i^{th}$ iteration. Hence the error in the final output of MC is: $$\xi=\alpha-\alpha_{MC}$$ How to draw the convergence:
Calculate the average of MC's output after each iteration using aforemetioned relation. You will have $[\alpha_{MC_1}, \alpha_{MC_2}....\alpha_{MC_n}]$. Plot this list versus the number of iteration and another constant line representing the real value. The plot will look like this:Convergence MC

Here is a python code to do this:

import csv
import matplotlib.pyplot as plt
import os

# Declare output vectors
V=[]
V2=[]
V_ref=[]
# Change directory to fetch input csv files

os.chdir(r"C:") #result file

# open the input file to read data

with open('xx.csv',newline='') as csvFile:
    reader=csv.reader(csvFile, delimiter=';')
    for row in reader:
        V1=float(row[1])
        V2.append(V1)

V3=V2[0]
V.append(V3)
V3=(V2[1]+V[0])/2
V.append(V3)
for i in range(len(V2)-2):
   V3=(V2[i+2]+V[i+1]*(i+1))/(i+2)
   V.append(V3)

X=range(len(V))
plt.plot(X,V,'r')
plt.grid(True)
plt.show()