Question: Programming question

Hello everyone,

There is a problem that I cannot solve (I just learnt Maple's language one day ago and I'm not a programmer):

I wrote a procedure which asks the user to enter any number of (x,y) pairs and then calculates polynomials p[i] between x_i and x_(i+1) for i=1..n, where n:=nargs/2-1.

Then I want to be able to combine these pieces of polynomials as a piecewise defined function. Can anyone tell me how I can do it? In order to call the built-in piecewise procedure of Maple one needs to know how many variables will be used, so it's useless. An ad-hoc solution I found was to write
if n=3 then
  S(x) := piecewise(x<=args[3], p[1], x<=args[5], p[2])
else
  if n=4 then
    S(x) := piecewise(x<=args[3], p[1], x<=args[5], p[2], x<=args[7], p[3])
  else
    if n=5 then
      S(x) := piecewise(x<=args[3], p[1], x<=args[5], p[2], x<=args[7], p[3], x<=args[9], p[4])
    else ...

but obviously this is bad programming.

Any ideas?

Thanks in advance.
Ozgur  

Please Wait...