Message Boards Message Boards

0
|
28158 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Why won't Mathematica plot my functions?

Posted 11 years ago
I am trying to plot a certain piecewise function using RevolutionPlot3D, so it revolves around an axis.
u[x_] := Piecewise[{{.5, {0 <= x <= pi/6, 5 pi/6 < x <= 13 pi/6,
     17 pi/6 < x <= 10}}, {Sin[x], {pi/6 < x <= 5 pi/6,
     13 pi/6 < x <= 17 pi/6}}}]
(It's the upper portion of this graph)

However, whatever I try, the plot is always blank.  I can't even plot it in 2d; it is still blank.  Here are some things I've tried:
RevolutionPlot3D[u[x], {x, 0, 2}]
RevolutionPlot3D[Evaluate[u[x]], {x, 0, 2},
RevolutionAxis -> {1, 0, 0}]
RevolutionPlot3D[Piecewise[{{.5, {0 <= x <= pi/6, 5 pi/6 < x <= 13 pi/6,
     17 pi/6 < x <= 10}}, {Sin[x], {pi/6 < x <= 5 pi/6,
     13 pi/6 < x <= 17 pi/6}}}], {x, 1, 2},
RevolutionAxis -> {1, 0, 0}]
Plot[Evaluate[u[x]], {x, 0, 2}]
Plot[u[x], {x, 0, 2}]
Why won't Mathematica plot my function?
POSTED BY: Frederick Fleitz
3 Replies
Thank you, that answers my question.  I didn't know that || was used to  separate different ranges like that.
POSTED BY: Frederick Fleitz
The list of conditions do not resolve into True or False, try putting them into a structure like Or in case one of them turns True. The symbol pi is not being treated like the constant Pi, use Pi or Esc p Esc instead. The result will look like this:
uOr[x_] := Piecewise[{
   {.5, Or @@ {0 <= x <= Pi/6, 5 Pi/6 < x <= 13 Pi/6, 17 Pi/6 < x <= 10}},
   {Sin[x], Or @@ {Pi/6 < x <= 5 Pi/6, 13 Pi/6 < x <= 17 Pi/6}}
   }]
Karl beat me to it. Nice work.
You have a few syntax issues:

First of all, "pi" is not a built in symbol in Mathematica.  Please recall that all built in symbols in Mathematica begin with a capital letter, so it should be "Pi".

Also, I do not think that you are using an accepted syntax for Piecewise.  At least, when I evaluated your function u for some reasonable number, I do not get a numerical result (which is what would be required for a plot).  I think that what you actually want is this something like this:
u[x_] := Piecewise[{{.5, 0 <= x <= Pi/6 || 5 Pi/6 < x <= 13 Pi/6 || 17 Pi/6 < x <= 10}, {Sin[x], Pi/6 < x <= 5 Pi/6 || 13 Pi/6 < x <= 17 Pi/6}}]

This will then produce a plot:
RevolutionPlot3D[u[x], {x, 0, 2}]
POSTED BY: Karl Isensee
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract