PwLinearTest



In [29]:
import pylab
import numpy as np
from pylab import arange,pi,sin,cos,sqrt
fig_width_pt = 400  # Get this from LaTeX using \showthe\columnwidth
inches_per_pt = 1.0/72.27               # Convert pt to inch
golden_mean = (sqrt(5)-1.0)/2.0         # Aesthetic ratio
fig_width = fig_width_pt*inches_per_pt  # width in inches
fig_height = fig_width*golden_mean      # height in inches
fig_size =  [fig_width,fig_height]
params = {'backend': 'ps',
          'axes.labelsize': 10,
          'text.fontsize': 10,
          'legend.fontsize': 10,
          'xtick.labelsize': 8,
          'ytick.labelsize': 8,
          'text.usetex': True,
          'figure.figsize': fig_size}
pylab.rcParams.update(params)
# Generate data
# Plot data
pylab.figure(1)
pylab.rcParams.update(params)
pylab.clf()
pylab.axes([0.125,0.2,0.95-0.125,0.95-0.2])
pylab.axis([-1, 5,-.5,12.])

def f(x):
    return x**2 + 3*np.sin(x)*x
x = np.linspace(-1,5, 40)
y = f(x)
sampled = np.array([-1, 0, 1.5, 3.0, 4.5, 5])
ysampled = f(sampled)
ysampled[0] = ysampled[1]
ysampled[5] = ysampled[4]
plot(x, y, 'r-', label='Actual Function')
plot(sampled, ysampled, 'xb-', label='Sampled Function')

pylab.xlabel('Input range')
pylab.ylabel('Output range')
pylab.legend()
legend(loc=2)
pylab.savefig('piecewiselin.pdf')



In [30]:
import pylab
import numpy as np
from pylab import arange,pi,sin,cos,sqrt
fig_width_pt = 400  # Get this from LaTeX using \showthe\columnwidth
inches_per_pt = 1.0/72.27               # Convert pt to inch
golden_mean = (sqrt(5)-1.0)/2.0         # Aesthetic ratio
fig_width = fig_width_pt*inches_per_pt  # width in inches
fig_height = fig_width*golden_mean      # height in inches
fig_size =  [fig_width,fig_height]
params = {'backend': 'ps',
          'axes.labelsize': 10,
          'text.fontsize': 10,
          'legend.fontsize': 10,
          'xtick.labelsize': 8,
          'ytick.labelsize': 8,
          'text.usetex': True,
          'figure.figsize': fig_size}
pylab.rcParams.update(params)
# Generate data
# Plot data
pylab.figure(1)
pylab.rcParams.update(params)
pylab.clf()
pylab.axes([0.125,0.2,0.95-0.125,0.95-0.2])
pylab.axis([-1, 5,-.5,12.])

def f(x):
    return x**2 + 3*np.sin(x)*x
x = np.linspace(-1,5, 40)
y = f(x)
sampled = np.array([-1, 0, 1.5, 3.0, 4.5, 5])
ysampled = f(sampled)
ysampled[0] = ysampled[1]
ysampled[5] = ysampled[4]
plot(x, y, 'r-', label='Actual Function')
plot(sampled, ysampled, 'xb-', label='Sampled Function')

pylab.xlabel('Input range')
pylab.ylabel('Output range')
pylab.legend()
legend(loc=2)
pylab.savefig('piecewiselin2.pdf')



In [ ]: