4

The function is:

We know that f[x] is an even function defined on x < 0 And x > 0,

when x > 0,

0 < x <= 2, Abs[x-1],

x > 2, 1/2 f[x - 2]

There is a problem with drawing an image of f[x] with the following code, see image drawing red circle

f[x_] := 
 Which[0 < x <= 2, Abs[x - 1], x > 2, 1/2 f[x - 2], x < 0, f[-x]]
Plot[f[x], {x, -1, 10}]

enter image description here

The correct image looks like this, and notice that the images at the demarcation point are not connected

enter image description here

How to make the segmentation function automatically draw the correct function image at the break point?

Edmund
  • 42,267
  • 3
  • 51
  • 143
csn899
  • 3,953
  • 6
  • 13
  • Maybe a duplicate: https://mathematica.stackexchange.com/q/39445 There are a couple answers that seem to do the trick. – Goofy Feb 16 '24 at 14:42

2 Answers2

4

For now you could do this workaround but this can be automated if needed. Left as an exercise.

f[x_] := Which[0 < x < 2, Abs[x - 1], x > 2, 1/2  f[x - 2],x < 0, f[-x]]
Plot[f[x], {x, 0, 10}, Exclusions -> Range[2, 10, 2]]

Mathematica graphics

You can add

Plot[f[x], {x, 0, 10}, Exclusions -> Range[2, 10, 2], 
 ExclusionsStyle -> Dashed]

Mathematica graphics

Nasser
  • 143,286
  • 11
  • 154
  • 359
4

If you define your function such that it contains the discontinuities then Mma will automatically exclude them.

The function is piecewise right continuous with modulo 2 step size and vertical shrinking factor of $\frac{1}{2}^n$ where $n$ is the number of steps.

First define the base function with the left side discontinuity.

f1[x_] :=
 Piecewise[{
   {Abs[x - 1], 0 < x <= 2}
   , {Indeterminate, True}
   }]

Next apply the modulo 2 step size and the step dependent shrinking factor.

f2[x_] := f1[Mod[Abs[x], 2]]/(2^Floor[Abs[x]/2])

Mathematica will automatically exclude the discontinuities. You only need provide an exclusion style if you want to show them.

Plot[f2[x], {x, -1, 10}, ExclusionsStyle -> {Dashing[Small], None}]

Mathematica graphics

Hope this helps.

Edmund
  • 42,267
  • 3
  • 51
  • 143