[Date Index]
[Thread Index]
[Author Index]
Multiplying piecewise functions
*To*: mathgroup at smc.vnet.net
*Subject*: [mg14547] Multiplying piecewise functions
*From*: sergio at scisun.sci.ccny.cuny.edu
*Date*: Thu, 29 Oct 1998 04:33:39 -0500
*Organization*: Deja News - The Leader in Internet Discussion
*Sender*: owner-wri-mathgroup at wolfram.com
(*
Hello fellows:
Using Mathematica of course, would it be possible
to get, after multiplying two or more piecewise
functions defined using Which, a single (one Which)
expression which can be integrated later.? For instance,
let's say one has:
*)
Clear[f]
f[x_] := Which[ -1 <= x < 5,
100*x^2 + 1,
5<=x,
x^3,
True,
10*x - 200 ]; Clear[g]
g[x_] := Which[ -10 <= x < 10,
x^4 + 100,
10 <= x,
x^3,
True,
-100*x ];
(* The product of this functions is given by: *) Clear[FG];
FG[x_] := Evaluate[f[x]*g[x]] ;
(* QUESTION: How can I instruct Mathematica to write
it in something similar to: *) Clear[fg]
fg[x_] := Which[ x < -10,
(10*x - 200)*(-100*x),
-10 <= x < -1,
(10*x - 200)*(x^4 + 100),
-1 <= x < 5,
(100*x^2 + 1)*(x^4 + 100),
5 <= x < 10,
x^3*(x^4 + 100),
10 <= x ,
x^3*x^3 ];
(* The equivalence of FG[x] and fg[x] can be
asserted from: *)
Clear[p1,p2];
pFG = Plot[FG[x],{x,-20,20},PlotRange -> All,
Frame -> True,
PlotStyle -> {AbsoluteThickness[3],Hue[0.1]},
FrameLabel -> {"","","This is f[x]*g[x]",""}]
pfg = Plot[fg[x],{x,-20,20},PlotRange -> All,
Frame -> True,
PlotStyle -> {AbsoluteThickness[5],Hue[0.4]},
FrameLabel -> {"","","This is fg[x]",""}]
Show[pfg,pFG,Frame -> True,
FrameLabel -> {"","","This is fg[x] and FG[x]",""}]
val = Table[Random[Real,{-100,100}],{30}]; Print["using x =
Random[Real,{-100,100}] -> fg[x]-FG[x]] = ",
Map[fg,val]-Map[FG,val]] (*
Sergio
Email: sergio at scisun.sci.ccny.cuny.edu *)
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Prev by Date:
**Bubble help in palwttes**
Next by Date:
**Re: Re: Corrupted NB**
Previous by thread:
**Re: Bubble help in palwttes**
Next by thread:
**ListSurfacePlot3D problem**
| |