Re: Piecewise function generator
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg1159] Re: Piecewise function generator
- From: pasquale Nardone <pnardon at ulb.ac.be>
- Date: Sat, 20 May 1995 01:43:22 -0400
- Organization: Universite' Libre de Bruxelles
I forgot to show you a way without recursivity jjj[{{x1_,y1_},{x2_,y2_}},var_]:={ LessEqual[x1,var,x2], ((y2-y1)*var+y1*x2-y2*x1)/(x2-x1)}; this is the same as before g[x_]:=Apply[Which, Flatten[Map[jjj[#,x]&, Thread[List[Drop[pts,-1],Drop[RotateLeft[pts],-1]]]]]] this define the function by mapping jjj on the pair of points: {{p1,p2},{p2,p3},{p3,p4},...} which is build using Thread, List Drop and RotateLeft In[] g[XX] Out[] Which[20 <= XX <= 50, (-12. + 0.72*XX)/30, 50 <= XX <= 250, (160. + 0.*XX)/200, 250 <= XX <= 5000, (3999. - 0.796*XX)/4750] In[] g[80] Out[] 0.8 of course you can Plot g[x] and also add a condition for x<x1 I hope this will help P. Nardone