Question: Piecewise function is not making a function

I have two list, x1 and d, I want to make a piecewise function out of them and plot it, but I may have some other stuffs like this so I decided to write this procedure in a proc, the proc makes the input of the piecewise right, but when I want to make a function out of this and pass it to plot this does not works properly, I tried something else; first assigned a seri to a variable and passed it to the piecewise to make a function out of it this does not works either, but when I write the seri directly into the piecewise it makes a function, what am I missing here? my worksheet is attached and the code is presented here

 

Vec2Pw.mw

restart

x1 := [seq(i-.5, i = 1 .. 10)]

[.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5]

(1)

d := [8.640000000, -.476000000, -.200000000, -.552000000, -4.248000000, -.192000000, -0.76000000e-1, .160000000, -3.056000000, 0.]

[8.640000000, -.476000000, -.200000000, -.552000000, -4.248000000, -.192000000, -0.76000000e-1, .160000000, -3.056000000, 0.]

(2)

vec2pw := proc (L1::list, L2::list) local xn, yn, i, pw, x; xn := nops(L1); yn := nops(L2); pw := [`$`(0, 2*xn+2)]; if xn <> yn then print("Vectors dimensions are not consistent"); return pw end if; pw := x < (3/2)*L1[1]-(1/2)*L1[2], 0.; for i to xn-1 do pw := pw, x < (1/2)*L1[i]+(1/2)*L1[i+1], L2[i] end do; pw := pw, x < (3/2)*L1[xn]-(1/2)*L1[xn-1], L2[xn], 0.; return evalf(pw) end proc:
``

pwl := x < 0, -1, x < 1, 0, 1

x < 0, -1, x < 1, 0, 1

(3)

k := proc (x) options operator, arrow; piecewise(pwl) end proc

proc (x) options operator, arrow; piecewise(pwl) end proc

(4)

k(-1/2)

piecewise(x < 0, -1, x < 1, 0, 1)

(5)

k := proc (x) options operator, arrow; piecewise(x < 0, -1, x < 1, 0, 1) end proc

proc (x) options operator, arrow; piecewise(x < 0, -1, x < 1, 0, 1) end proc

(6)

k(-1/2)

-1

(7)

``


Download Vec2Pw.mw

Please Wait...