I want to plot only those portions of the following function in which the function is positive (e.g. from $0-0.01$ & $0.02-0.03$ and so on):

$$230\sqrt{2}\sin\left(100\pi t\right)$$

In addition to that, I want to create some dotted lines in the plot with values next to it!

How can I do this in one Mathematica expression?

My code so far:

Plot[{230 Sqrt[2] Sin[100 Pi*t]}, {t, 0, 40*10^(-3)}]
  • $\begingroup$ Look up Plot in the help files and try it out. The help files should be your first go-to when learning new software, and Mathematica's are particularly good. $\endgroup$ – march Sep 9 '15 at 16:59
  • $\begingroup$ I've done that, and I can't -> that's why I choose to ask it here $\endgroup$ – Jan Sep 9 '15 at 17:00
  • $\begingroup$ I'm not sure that I understand what you mean by "positive sides" and why you indicate non-contiguous intervals. You say that you did obtain a plot already: please include the code that worked so far in your question, as a starting point. $\endgroup$ – MarcoB Sep 9 '15 at 17:01
  • 1
    $\begingroup$ Then it's a good idea to post what you tried. $\endgroup$ – march Sep 9 '15 at 17:02

This might give you something to work on as a start.

  230 Sqrt[2] Sin[100 Pi t], {t, 0, 0.03},
  GridLines -> {{0, 0.01, 0.02}, {-100, 250}},
  GridLinesStyle -> {{Dashed, Red}, {Dotted, Blue}},
  Epilog -> {
    Red, Text[Style[0.01, FontSize -> 18], {0.01, 310}, Background -> White],
    Blue, Text[Style[250, FontSize -> 24], {0.025, 250}, Background -> White]
  ImageSize -> Large

Mathematica graphics

I'd suggest that you look up all functions and options used in the code above to familiarize yourself with them and to adapt them to your needs.

You can show only the positive portion of the plot in two ways, either by using a PlotRange option as suggested by george2079, or by specifying a RegionFunction (see docs), with slightly different results.

(* with a RegionFunction *)
  230 Sqrt[2] Sin[100 Pi t], {t, 0, 0.03},
  RegionFunction -> (#2 >= 0 &)


(* with PlotRange *)
Plot[230 Sqrt[2] Sin[100 Pi t], {t, 0, 0.03},
  PlotRange -> {0, Automatic}

Mathematica graphics

As you can see, PlotRange restricts the region of space shown; RegionFunction instead does not alter the plot range, but simply only shows points that conform to the condition specified.

| improve this answer | |
  • $\begingroup$ First of all thanks for your help, but the only thing I dont know is to cut the negative values (in the interval: 0.010 to 0.020) out of the plot? $\endgroup$ – Jan Sep 9 '15 at 17:23
  • $\begingroup$ PlotRange->{0,Automatic} $\endgroup$ – george2079 Sep 9 '15 at 18:41
  • 1
    $\begingroup$ @JanEerland I modified my answer to include your request. Let me know if this is what you were looking for. $\endgroup$ – MarcoB Sep 9 '15 at 20:14
  • $\begingroup$ Wow it worked! Thanks a lot! $\endgroup$ – Jan Sep 9 '15 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.