import pyJvsip as pjv from math import pi as pi view = pjv.create L = 20 # A length a = view('vview_d', L).ramp(0.0, 2.0 * pi / float(L - 1)) b = a.empty ab_bl = view('vview_bl', L) pjv.cos(a, b) a.fill(0.0) pjv.lgt(b, a, ab_bl) assert ab_bl.anytrue, 'No true values in boolean vector' ab_vi = ab_bl.indexbool pjv.gather(b, ab_vi, a.putlength(ab_vi.length)) print(repr([(ab_vi[i], a[i]) for i in range(ab_vi.length)]))
#! 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
import pyJvsip as pjv from math import pi as pi view=pjv.create L = 20 # A length a = view('vview_d',L).ramp(0.0,2.0*pi/float(L-1)) b = a.empty ab_bl=view('vview_bl',L) pjv.cos(a,b) a.fill(0.0) pjv.lgt(b,a,ab_bl) assert ab_bl.anytrue, 'No true values in boolean vector' ab_vi = ab_bl.indexbool pjv.gather(b,ab_vi,a.putlength(ab_vi.length)) print(repr([(ab_vi[i], a[i]) for i in range(ab_vi.length)]))
import pyJvsip as pjv from math import pi as pi n = 1000 x = pjv.create('vview_d', n).ramp(0, 2 * pi / float(n)) c = pjv.cos(x, x.empty) cClip = pjv.clip(c, -.9, .9, -.8, .8, c.empty)
import pyJvsip as pjv from math import pi as pi n=1000 x=pjv.create('vview_d',n).ramp(0,2*pi/float(n)) c=pjv.cos(x,x.empty) cinvClip=pjv.invclip(c,-.6,0.0,.6,-.7,.7,c.empty)
# 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