Evalution la, B L(z)=? Problem:z∈[x,x if==x(n) - n else =sum(X<=z) end
Evalution z [, ] L(z) = ? Problem: [ , ], ? z xi xi+1 i = if z==x(n) i =n-1; else i=sum(x<=z); end
Binary search mid= floor((Left+ Right ) /2) linspace(1,100,10000),z=48.598 If z<x(mid) Right=mid Else Left =mid end N=10000一n=log2N≤13.3
Binary search mid = floor((Left+Right)/2); If z<x(mid) Right=mid; Else Left =mid; end N =10000 n = log2 N 13.3
function 1=Locate(x, z, g, %og(1-g<-=n-1)is an optional input parameter search for i begins, the value i-g is tried g·guss if nargin==3 if(x(g)<=z)&(z<x(g+1) return end: end n= length(x) ifz==x(n) else Left=1: Right=n while right Left+l Binary search end
function i = Locate(x,z,g) % g (1<=g<=n-1) is an optional input parameter % search for i begins, the value i=g is tried. if nargin==3 if (x(g)<=z) & (z<=x(g+1)) i = g; return end;end n = length(x); if z = = x(n) i = n-1; else Left = 1; Right = n; while Right > Left+1 Binary_search end g: guss
function LVals- pWLEval(a, b, x, Z Vals) o Evaluates the piecewise linear polynomial defined by the column /o(n-1)-vectors m= length( Vals) m-vector LVals= zeros(m, 1) for j=l: m i=Locate(x, z vals(, g) LVals(=a(1+ b(i)*(zVals(-x(i) g end
function LVals = pwLEval(a,b,x,zVals) % Evaluates the piecewise linear polynomial defined by the column %(n-1)-vectors m = length(zVals); LVals = zeros(m,1); g = 1; for j=1:m i = Locate(x,zVals(j),g); LVals(j) = a(i) + b(i)*(zVals(j)-x(i)); g = i; end m-vector
Interpolation of humps(x) with pwL, n= 5 (x-.3)2+.01(x-92+0~6
6 ( .9)^2 .04 1 ( .3) .01 1 2 − − + + x − + x