In [34]:
from __future__ import division

%matplotlib inline

import numpy as np
import assign1 as a
import math
import matplotlib.pyplot as plt

Initialization

Compute exact result with 128 points and create a fdm result array with iteration ranging from 0 to 1000 by step of 10.


In [2]:
x,y,exact = a.exact(128)

In [3]:
fdm = np.zeros([100,128])

In [73]:
for i in range(100):
    fdm[i] = a.get_border(a.fdm(32,32,i*10,False))

Plotting the data

Test the data by ploting them in the same graph. Blue indicates the exact result, red indicates the approximate result.


In [5]:
a.scatter_plot(x,y,exact,fdm[0])



In [6]:
a.scatter_plot(x,y,exact,fdm[1])



In [7]:
a.scatter_plot(x,y,exact,fdm[5])



In [8]:
a.scatter_plot(x,y,exact,fdm[10])



In [9]:
a.scatter_plot(x,y,exact,fdm[20])



In [10]:
a.scatter_plot(x,y,exact,fdm[50])



In [11]:
a.scatter_plot(x,y,exact,fdm[80])



In [12]:
a.scatter_plot(x,y,exact,fdm[99])


Experiencing error

Error function put in test: error with $10^{-6}$ torlerance.


In [13]:
a.error(exact, fdm[0])


Out[13]:
364.63519998606785

In [14]:
a.error(exact, fdm[1])


Out[14]:
138.35216937848864

In [15]:
a.error(exact, fdm[2])


Out[15]:
113.32119951761369

In [16]:
a.error(exact, fdm[4])


Out[16]:
83.28941465206103

In [17]:
a.error(exact, fdm[8])


Out[17]:
50.88016800286405

In [18]:
a.error(exact, fdm[16])


Out[18]:
14.86524516520828

In [19]:
a.error(exact, fdm[32])


Out[19]:
10.414553642579925

In [20]:
a.error(exact, fdm[64])


Out[20]:
10.409277174407087

In [21]:
a.error(exact, fdm[99])


Out[21]:
10.40497862562813

Error function put in test: error_rel.


In [22]:
a.error_rel(exact, fdm[0])


Out[22]:
0.8615030470056387

In [23]:
a.error_rel(exact, fdm[1])


Out[23]:
0.6886289687473851

In [24]:
a.error_rel(exact, fdm[2])


Out[24]:
0.6797471679427319

In [25]:
a.error_rel(exact, fdm[4])


Out[25]:
0.665907667319058

In [26]:
a.error_rel(exact, fdm[8])


Out[26]:
0.643887571348277

In [27]:
a.error_rel(exact, fdm[16])


Out[27]:
0.6074968068817607

In [28]:
a.error_rel(exact, fdm[32])


Out[28]:
0.5417153039151681

In [29]:
a.error_rel(exact, fdm[64])


Out[29]:
0.40465507190384675

In [30]:
a.error_rel(exact, fdm[99])


Out[30]:
0.2882128431039139

In [33]:
a.error_rel(exact, a.get_border(a.fdm(32,32,2000)))


Out[33]:
0.17722530972332215

In [36]:
error_rel = [a.error_rel(exact, fdm[i]) for i in range(100)]

In [37]:
len(error_rel)


Out[37]:
100

In [67]:
errors = [a.error(exact, fdm[i]) for i in range(100)]

In [75]:
fig = plt.figure(figsize=(13,4), dpi=100)
ax = fig.gca()
ax.plot(error_rel, '-o', ms=5, lw=2, alpha=1, mfc='orange')
ax.grid()
plt.ylabel('Modified Relative Error')
plt.xlabel('Iterations (x10)')

plt.show()



In [74]:
fig = plt.figure(figsize=(13,4), dpi=100)
ax = fig.gca()
ax.plot(errors, '-o', ms=5, lw=2, alpha=1, mfc='orange')
ax.grid()
plt.ylabel('Relative Error')
plt.xlabel('Iterations (x10)')

plt.show()



In [71]:
range(1,10,2)


Out[71]:
[1, 3, 5, 7, 9]

In [76]:
a.scatter_plot(x,y,exact,a.get_border(a.fdm(32,32,2000)))



In [77]:
fdm2000 = a.get_border(a.fdm(32,32,2000))

In [78]:
a.error(exact,fdm2000)


Out[78]:
10.400554663135578

In [79]:
a.error_rel(exact,fdm2000)


Out[79]:
0.17722530972332215

In [80]:
a.error(exact,fdm[20])


Out[80]:
10.504043780336685

In [81]:
a.error_rel(exact,fdm[20])


Out[81]:
0.5907914165360616

In [ ]: