Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from scipy import interpolate
- import numpy as np
- import matplotlib.pyplot as plt
- x = np.arange(0, 20)
- y = np.sin(x)
- print x
- f = interpolate.interp1d(x, y)
- g = interpolate.interp1d(x, y, kind = 'cubic')
- h = interpolate.interp1d(x, y, kind = 'nearest')
- i = interpolate.interp1d(x, y, kind = 'zero')
- # wyniki różnych metod przybliżeń:
- x1 = np.arange(0, 19, 0.1)
- yf = f(x1)
- yg = g(x1)
- yh = h(x1)
- yi = i(x1)
- def linear(x,y):
- def result(tab):
- mtab = np.copy(tab)
- for index in range(len(mtab)):
- mindex = sum(map(lambda x: x <= mtab[index], x))-1
- print "{} < {} < {}".format(x[mindex], mtab[index], x[mindex+1])
- a = (y[mindex+1]-y[mindex])/(x[mindex+1]-x[mindex])
- b = y[mindex] - a*x[mindex]
- mtab[index] = a*mtab[index] + b
- return mtab
- return result
- j = linear(x,y)
- yj = j(x1)
- a = plt.plot(x1, yj, label='linear', linestyle='-', linewidth=1.5, color='red')
- b = plt.plot(x1, yf, label='linear', linestyle='-', linewidth=1.5, color='blue')
- plt.legend((a[0], b[0]),
- ('$\Theta = 0.2$', '$\Theta = 0.7$'),
- loc = (0.01, 0.1), handlelength = -0.1)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement