smbinterp/lib/baker/tools.py
2010-04-23 09:58:30 -06:00

48 lines
1.0 KiB
Python

import numpy as np
class smberror(Exception):
"""
this is a silly little exception subclass
"""
def __init__(self, val):
self.value = val
def __str__(self):
return repr(self.value)
def rms(errors):
"""
root mean square calculation
"""
r = 0.0
for i in errors:
r += np.power(i, 2)
r = np.sqrt(r / len(errors))
return r
def exact_func(X):
"""
the exact function used from baker's article (for testing)
"""
x = X[0]
y = X[0]
return np.power((np.sin(x * np.pi) * np.cos(y * np.pi)), 2)
def exact_func_3D(X):
"""
the exact function (3D) used from baker's article (for testing)
"""
x = X[0]
y = X[1]
z = X[2]
return np.power((np.sin(x * np.pi / 2.0) * np.sin(y * np.pi / 2.0) * np.sin(z * np.pi / 2.0)), 2)
def evaluate_answer(answer, exact):
print 'qlin' , answer['qlin']
print 'error', answer['error']
print 'final', answer['final']
if abs(answer['final'] - exact) <= abs(answer['qlin'] - exact):
print ":) improved result"
else:
print ":( damaged result"