Example #1
0
n_list = range(4, 50, 4)
linf, l2 = [], []

xall = random.random(size=n_list[-1])
dall = exp(-3.0 * random.random(size=n_list[-1])) * 0.05
eall = random.normal(size=n_list[-1]) * dall

for n in n_list:
  x = xall[:n]
  x = tan((x-0.5)*pi*0.8) / tan(0.4*pi) * 0.5 + 0.5
  fx = exp(-((x-0.5)*16)**2) + eall[:n]
  dfx = dall[:n]
  # fx[:] = 0; fx[x>0.5] = 1
  # fx = arctan(100*(x-0.5)) / 3.0 + 0.5
  fy, sig = interp_1d_adaptive(y, x, fx, dfx, compute_sigma=True)
  fy_l = lagrange_1d(y, x, fx)
  if abs(fy_l).max() > 1.0E3: fy_l[:] = 0.0
  sig[sig>1000] = 1000; sig[sig<-1000] = -1000
  pylab.figure()
  pylab.plot(y, fy, 'b')
  pylab.plot(y, fy + sig, ':b')
  pylab.plot(y, fy - sig, ':b')
  pylab.plot(y, fy_l, '-.g')
  pylab.plot(y, fye, '--r')
  pylab.bar(x, x*0, bottom=fx, yerr=dfx, width=0)
  pylab.ylim([-0.2, 1.2])
  linf.append(abs(fy-fye).max())
  l2.append(sqrt(((fy-fye)**2).sum()))
  print n, linf[-1], l2[-1]
Example #2
0
y = linspace(0, 1, 250)
fye = exp(-((y-0.5)*16)**2)

n_list = range(4, 50, 4)
randx = random.random(size=n_list[-1])
randx = numpy.tan((randx-0.5)*pi*0.6) / numpy.tan(0.3*pi) * 0.5 + 0.5

linf, l2 = [], []
linf_m, l2_m = [], []
for n in n_list:
  # x = linspace(0, 1, n)
  x = numpy.array(sorted(randx[:n]))
  fx = exp(-((x-0.5)*16)**2)
  fy = floater_hormann_adaptive(y, x, fx)
  fy_m = interp_1d_adaptive(y, x, fx)
  pylab.figure()
  pylab.plot(y, fye, '--r')
  pylab.plot(y, fy, 'g')
  pylab.plot(y, fy_m, 'b')
  pylab.plot(x, fx, '+k')
  pylab.ylim([-0.2, 1.2])
  linf.append(abs(fy-fye).max())
  l2.append(sqrt(((fy-fye)**2).sum()))
  linf_m.append(abs(fy_m-fye).max())
  l2_m.append(sqrt(((fy_m-fye)**2).sum()))
  print linf[-1], l2[-1], ' mine ', linf_m[-1], l2_m[-1]

pylab.figure()
pylab.semilogy(n_list, linf, '-+g')
pylab.semilogy(n_list, l2, '-+g')