Created
April 6, 2011 10:37
-
-
Save fabianp/905457 to your computer and use it in GitHub Desktop.
Print error distribution for norm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pylab as pl | |
import numpy as np | |
import scipy.linalg | |
nrm2, = scipy.linalg.get_blas_funcs(('nrm2',), np.empty(0, dtype=np.float32)) | |
x_min, x_max = -4., 0 | |
y_min, y_max = 0, 4. | |
h = 134567e-7 | |
xx, yy = np.meshgrid(np.arange(x_min, x_max, h, dtype=np.float32), | |
np.arange(y_min, y_max, h, dtype=np.float32)) | |
points = np.c_[xx.ravel(), yy.ravel()] | |
norm_delta = np.empty(points.shape[0], dtype=np.float32) | |
for i, p in enumerate(points): | |
norm_delta[i] = np.abs(nrm2(p) - np.sqrt(np.dot(p, p))) | |
#norm_delta[i] = np.abs(nrm2(p) - scipy.linalg.norm(p)) | |
Z = norm_delta.reshape(xx.shape) | |
pl.contourf(xx, yy, Z) | |
pl.colorbar() | |
pl.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment