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.
$\begingroup$
$\endgroup$
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 π}]
$\begingroup$
$\endgroup$
8
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}]
-
$\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
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