Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'piecewise function' topicStudent Support Forum > General > "piecewise function"

Next Comment >Help | Reply To Topic
Author Comment/Response
John T.
12/04/03 11:28pm

I'm plotting this piecewise function, and was able to do it using a nested If statement as follows (see below for an easier to read version of what I'm intending here):

f[x_, n_] :=
If[1/(2 n) ? x ? 3/(4 n), 16 n^2 x - 8 n, If[3/ (4 n) ? x ? 1/n, -16 n^2 x + 16 n, 0]]

Plot[f[x, 1], {x, 0, 1}]

I was wondering if there was a more straightforward way to do it (which I tried first), such as the following, which gave me a "not a machine-size real number" error.

f[x_, n_] := 16 n^2 x - 8 n /; 1/(2 n) ? x ? 3/(4 n)

f[x_, n_] := -16 n^2 x + 16 n /; 3/ (4 n) ? x ? 1/n

f[x_, n_] := 0 /; x > 1/n

Plot[f[x, 1], {x, 0, 1}]




URL: ,

Subject (listing for 'piecewise function')
Author Date Posted
piecewise function John T. 12/04/03 11:28pm
Re: piecewise function John T. 12/08/03 4:12pm
Next Comment >Help | Reply To Topic