Esempio n. 1
0
# out-of-place using method

# <codecell>

b=a.copy.asin
b.mprint(f)
a.mprint(f)

# <markdowncell>

# out-of-place using function call

# <codecell>

pv.sin(b,a)
b.mprint(f)
a.mprint(f)

# <markdowncell>

# in-place using function call

# <codecell>

pv.sin(b,b)
b.mprint(f)

# <markdowncell>

# All the elementary functions work the same except for atan2 which has three arguments (two input and an output). There is no view method in pyJvsip for atan2, only a function call.
Esempio n. 2
0
#! python
# Estimate two-norm (sigma0) and singular values (sigma0, sigma1) 
# of a two by two matrix by searching through a dense space of vectors.
# Check by reproducing estimate for A matrix using Aest=U Sigma V^t
# Motivating text Numerical Linear Algebra, Trefethen and Bau
import pyJvsip as pv
from numpy import pi,arccos
from matplotlib.pyplot import *
N=1000 #number of points to search through for estimates
# create a vector 'arg' of evenly spaced angles between [zero, 2 pi)
arg=pv.create('vview_d',N).ramp(0.0,2.0 * pi/float(N))
# Create a matrix 'X' of unit vectors representing Unit Ball in R2
X=pv.create('mview_d',2,N,'ROW').fill(0.0)
x0=X.rowview(0);x1=X.rowview(1)
pv.sin(arg,x0);pv.cos(arg,x1)
# create matrix 'A' to examine
A=pv.create('mview_d',2,2).fill(0.0)
A[0,0]=1.0;A[0,1]=2.0; A[1,1]=2.0;A[1,0]=0.0
# create matrix Y=AX
Y=A.prod(X)
y0=Y.rowview(0);y1=Y.rowview(1)
# create vector 'n' of 2-norms for Y col vectors (sqrt(y0_i^2+y1_i^2))
n=(y0.copy.sq+y1.copy.sq).sqrt 
# Find index of (first) maximum value and (first) minimum value
i=n.maxvalindx; j=n.minvalindx
sigma0=n[i];sigma1=n[j]
# create estimates for V, U, Sigma (S)
V=A.empty.fill(0)
U=V.copy
S=V.copy
S[0,0]=sigma0;S[1,1]=sigma1
Esempio n. 3
0
# out-of-place using method

# <codecell>

b = a.copy.asin
b.mprint(f)
a.mprint(f)

# <markdowncell>

# out-of-place using function call

# <codecell>

pv.sin(b, a)
b.mprint(f)
a.mprint(f)

# <markdowncell>

# in-place using function call

# <codecell>

pv.sin(b, b)
b.mprint(f)

# <markdowncell>

# All the elementary functions work the same except for atan2 which has three arguments (two input and an output). There is no view method in pyJvsip for atan2, only a function call.
Esempio n. 4
0
import pyJvsip as pjv
from math import pi as pi
from matplotlib.pyplot import *
#make up some data for vector interpolation
x0=pjv.ramp('vview_d',0.0,2*pi/10,11)
y0=pjv.sin(x0,x0.empty)
#make up an interpolation vector and output
x=pjv.ramp('vview_d',0.0,2*pi/250,251)
yEstimate=x.empty
#interploate
spln=pjv.Spline(x0.type,400)
spln.interpolate(x0,y0,x,yEstimate)
#calculate actual
yActual=pjv.sin(x,x.empty)
#plot the data and save as pdf
subplot(3,1,1)
plot(x0,y0);title('Sparse Sine')
tick_params(axis='x',labelbottom='off')
for i in range(x0.length):
    text(x0[i],y0[i],'|',verticalalignment='center',horizontalalignment='center')
subplot(3,1,2)
plot(x,yEstimate);title('Estimate of Dense Sine')
tick_params(axis='x',labelbottom='off')
subplot(3,1,3)
plot(x,yEstimate-yActual);title('Error in Dense Sine')
#plot zero line. There should be at least 11 zero errors
plot(x,yActual.fill(0.0))
xlabel('Radian Values')
for i in range(x0.length):
    text(x0[i],0,'|',verticalalignment='center',horizontalalignment='center')
tight_layout()
Esempio n. 5
0
#! python
# Estimate two-norm (sigma0) and singular values (sigma0, sigma1)
# of a two by two matrix by searching through a dense space of vectors.
# Check by reproducing estimate for A matrix using Aest=U Sigma V^t
# Motivating text Numerical Linear Algebra, Trefethen and Bau
import pyJvsip as pv
from numpy import pi, arccos
from matplotlib.pyplot import *
N = 1000  #number of points to search through for estimates
# create a vector 'arg' of evenly spaced angles between [zero, 2 pi)
arg = pv.create('vview_d', N).ramp(0.0, 2.0 * pi / float(N))
# Create a matrix 'X' of unit vectors representing Unit Ball in R2
X = pv.create('mview_d', 2, N, 'ROW').fill(0.0)
x0 = X.rowview(0)
x1 = X.rowview(1)
pv.sin(arg, x0)
pv.cos(arg, x1)
# create matrix 'A' to examine
A = pv.create('mview_d', 2, 2).fill(0.0)
A[0, 0] = 1.0
A[0, 1] = 2.0
A[1, 1] = 2.0
A[1, 0] = 0.0
# create matrix Y=AX
Y = A.prod(X)
y0 = Y.rowview(0)
y1 = Y.rowview(1)
# create vector 'n' of 2-norms for Y col vectors (sqrt(y0_i^2+y1_i^2))
n = (y0.copy.sq + y1.copy.sq).sqrt
# Find index of (first) maximum value and (first) minimum value
i = n.maxvalindx