Re: recursive blues :(
- To: mathgroup at smc.vnet.net
- Subject: [mg70315] Re: recursive blues :(
- From: dimmechan at yahoo.com
- Date: Thu, 12 Oct 2006 05:38:13 -0400 (EDT)
- References: <egi1qo$jaa$1@smc.vnet.net>
Your syntax is completely wrong. Try Clear[f] f[x_] := f[x + 2] /; x < -2^(-1) f[x_] := f[x - 2] /; x > 3/2 f[x_] := 2 /; -2^(-1) < x < 1/2 f[x_] := 1 /; 1/2 < x < 3/2 Then execute the following command to get a plot Plot[f[x], {x, -3 3}, Frame -> {True, True, False, False}, Axes -> False, ImageSize -> 400] (*plot to be displayed*) If you want not to displayed the undesirable vertical lines connecting the discontinuities you can use the following one-liner which modifies slightly the Plot function. (see also http://groups.google.gr/group/comp.soft-sys.math.mathematica/browse_thread/thread/ece0e44f7b2f8600/df67129bb8472a9f?lnk=gst&q=plotDisc&rnum=1#df67129bb8472a9f ) plotDisc[g_, x_, a_, b_, c___, {opts___}] := Show[(Plot[g, {x, #1[[1]], #1[[2]]}, opts, DisplayFunction -> Identity] & ) /@ Partition[{a, c, b}, 2, 1], DisplayFunction -> $DisplayFunction] Then plotDisc[f[x], x, -3, 3, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, {Frame -> True, Axes -> False, PlotStyle -> Red}] (*plot to be displayed*) Let see one other way of defining your f function. If you have Mathematica version 5.1 and newer you can use the following definition Clear[f] f[x_] := Piecewise[{{f[x + 2], x < -2^(-1)}, {f[x - 2], x > 3/2}, {2, -2^(-1) < x < 1/2}, {1, 1/2 < x < 3/2}}] Plot[f[x], {x, -3, 3}] (*plot to be displayed*) (my plotDisc cannot be applied here...) Regards Dimitris