Wolfram alpha plot of a piecewise function with 2 domains.

707 Views Asked by At

So, Wolfram Alpha is capable of plotting two functions in one figure.

But I am trying to express a piecewise function that has a different form on two (touching) domains.

In C code:

x < pi ? cos(pi/2 + x/2) : cos(x) // for x 0..2pi

I tried things like:

plot cos(pi/2 + x/2) and cos(y) for x=0 to pi and y=pi to 6.28

...but whatever I try, I can't make it plot piecewise?

I also tried the mathematical notation for conditions using the | notation, to no avail.

1

There are 1 best solutions below

3
On BEST ANSWER
f[x_] := Piecewise[{{Cos[\[Pi]/2 + x/2], x < \[Pi]}, {Cos[x], x >= \[Pi]}}]
Plot[f[x], {x, 0, 2 \[Pi]}, Frame -> True, Axes -> False, 
FrameTicks -> {{{-1, 0, 1}, None}, {{0, Pi/2, Pi, (3 Pi)/2, 2 Pi}, None}}, 
GridLines -> {{0, Pi/2, Pi, (3 Pi)/2, 2 Pi}, {-1, -1/2, 0, 1/2, 1}}]

enter image description here

The function plotted is

$$ f(x) = \left\{ \begin{array}{c} \cos (x/2+\pi/2), \quad &(0<x<\pi)\\ \cos(x), \quad &(\pi \le x < 2\pi). \end{array} \right.$$