0
$\begingroup$

How to I plot the following function in one diagram: from $0$ to $\frac{\pi}{2}$ the function has to equal $\left|\sin\left(x\right)\right|$ and from $\frac{\pi}{2}$ the function $\exp\left(-\frac{x}{220}\right)$ starts untill that function hits the following bump of $\left|\sin\left(x\right)\right|$ and when that happends the function $\left|\sin\left(x\right)\right|$ starts again and so on.

$\endgroup$
  • $\begingroup$ see mathematica.stackexchange.com/q/138040/9490, and community.wolfram.com/groups/-/m/t/215621 $\endgroup$ – Jason B. Feb 5 '18 at 16:50
  • $\begingroup$ @JasonB. I saw those links before, but I don't get it because I have the property that the two functions hit/cross eachother $\endgroup$ – Jan Feb 5 '18 at 16:51
  • $\begingroup$ Your question isn't really clear as written. Are you looking for something like this? $\endgroup$ – Jason B. Feb 5 '18 at 17:18
  • $\begingroup$ @JasonB. This is maybe better: $$ \begin{cases} y=\left|\sin\left(x\right)\right|\space\space\space\space\space\space\space\space\text{when}\space0\le x<\frac{\pi}{2}\\ \\ \color{red}{y=\exp\left(-\frac{x}{220}\right)\space\space\space\text{when}\space\frac{\pi}{2}\le x<\left(\left|\sin\left(x\right)\right|=\exp\left(-\frac{x}{220}\right)\space\Longleftrightarrow\space x=\dots\right)} \end{cases} $$ For the red part: when you solve $x$ it has to be between the following boundaries: $$\frac{\pi}{2}<x<\frac{3\pi}{2}$$ And then then it starts again. So it is periodic in $x$. $\endgroup$ – Jan Feb 5 '18 at 17:26
  • $\begingroup$ You can see here Plot[{Exp[-x/220], Sin[x]}, {x, 0, 30}, MeshFunctions -> {(Exp[-#1/220] - Sin[#1]) & }, Mesh -> {{0}}, MeshStyle -> Directive[Red, PointSize[Large]] ] that your two functions intersect twice per period. Do you mean for the discontinuities in the piecewise function to occur at these points? Could you add a graphic to show what you mean? Also, add the expanded equation to the post, rather than as a comment $\endgroup$ – Jason B. Feb 5 '18 at 17:32
3
$\begingroup$

Perhaps this is what you are looking for.

f[x_] :=
  With[{u = Mod[x, 3 π/2]},
    Piecewise[{{Abs[Sin[u]], 0 <= u < π/2}, {E^(-u/229), π/2 < u <= 3 π}}]]

Plot[f[x], {x, 0, 3 π}]

plot

$\endgroup$
2
$\begingroup$

Try coding your function instead:

K = 20;
f[x_] := If[-Sin[Mod[x, \[Pi]]] Sign[Cos[Mod[x, \[Pi]]]] > 0, 
Max[Abs[Sin[Mod[x, \[Pi]] - \[Pi]/2]], Exp[-(Mod[x, \[Pi]])/K]], 
Exp[-(Mod[x, \[Pi]])/K]];
Plot[f[x], {x, 0, 10}, PlotRange -> {0, 1}]
$\endgroup$
  • $\begingroup$ You could do this a bit more succinctly as Plot[ Min[{ Abs[ Sin[x]], Exp[-x/220]}], {x,0,20}] $\endgroup$ – Jason B. Feb 5 '18 at 18:27
  • $\begingroup$ Well, this is not what I mean. I mean something like this but not quite: Plot[{Piecewise[{{Abs[Sin[x + (Pi/2)]], -Pi/2 < x <= 0}}], Piecewise[{{Abs[Sin[x + (Pi/2)]], Pi/2 < x <= Pi}}], Exp[(-x)/(1000*220*10^(-3))]}, {x, -2 Pi, 2 Pi}] $\endgroup$ – Jan Feb 5 '18 at 18:58
  • $\begingroup$ @Jan don't use piecewise because you don't know regions. Instead, write a function as a piece of code and plot it. Also I don't really get how your funciton looks like, please make a sketch of it. $\endgroup$ – Vsevolod A. Feb 5 '18 at 19:34
  • $\begingroup$ @VsevolodA. It is the function that you get when you want to plot the output voltage of a full bridge rectifier (see the picture in this link: electronics.stackexchange.com/questions/351453/…). $\endgroup$ – Jan Feb 5 '18 at 19:50
  • $\begingroup$ @Jan I can see that flat parts of the plot do not lie on one smooth curve. Instead, they look like a function that is drawn from different origins. Is that correct? $\endgroup$ – Vsevolod A. Feb 5 '18 at 20:09

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.