3 Resized image so it's not interpolated smaller edited Feb 13 '12 at 20:27 David 11.5k33 gold badges4242 silver badges7979 bronze badges You can pretty much enter your question in that form in Mathematica:  The first definition, f[x_, n_] /; n == 0, reads "define $$f_n(x)$$ in the case of $$n=0$$ to be the following". The fancy bracket is pretty frontend notation for the Piecewise function (shortcut: EscpwEsc). The next line is the same thing again, after that there's the definition of your function $$f(x)$$, which is the partial sum up to $$\mathcal N$$. I don't think you can use $$\mathcal N=\infty$$ in this case, as it will exceed the maximum recursion depth by, well, infinity. If you want to have an exact result, try using RSolve to get an explcit equation for $$f_n(x)$$. If you want to evaluate the code above on your own, here's a copyable version: f[x_, n_] /; n == 0 := Piecewise[{ {3 x, 0 <= x <= 1/3}, {-3 x + 2, 1/3 < x <= 2/3}, {3 x + 2, 2/3 < x <= 1}, {Indeterminate, True} }] f[x_, n_] /; n >= 0 := Piecewise[{ {1/3 f[3 x, n - 1], 0 <= x <= 1/3}, {1/3 + 1/3 f[3 x - 1, n - 1], 1/3 < x <= 2/3}, {2/3 + 1/3 f[3 x - 2, n - 1], 2/3 < x <= 1}, {Indeterminate, True} }] f[x_, _, \[ScriptCapitalN]_] := Sum[(-1)^k f[x, k], {k, 0, \[ScriptCapitalN]}] Plot[f[x, _, 10], {x, 0, 1}, PlotPoints -> 100, MaxRecursion -> 5]  For the third part of your question, simply define $$p$$ as an additional parameter for your function, so it's something like f[x_, n_, p_] := ..., and edit the definitions accordingly. You can pretty much enter your question in that form in Mathematica: The first definition, f[x_, n_] /; n == 0, reads "define $$f_n(x)$$ in the case of $$n=0$$ to be the following". The fancy bracket is pretty frontend notation for the Piecewise function (shortcut: EscpwEsc). The next line is the same thing again, after that there's the definition of your function $$f(x)$$, which is the partial sum up to $$\mathcal N$$. I don't think you can use $$\mathcal N=\infty$$ in this case, as it will exceed the maximum recursion depth by, well, infinity. If you want to have an exact result, try using RSolve to get an explcit equation for $$f_n(x)$$. If you want to evaluate the code above on your own, here's a copyable version: f[x_, n_] /; n == 0 := Piecewise[{ {3 x, 0 <= x <= 1/3}, {-3 x + 2, 1/3 < x <= 2/3}, {3 x + 2, 2/3 < x <= 1}, {Indeterminate, True} }] f[x_, n_] /; n >= 0 := Piecewise[{ {1/3 f[3 x, n - 1], 0 <= x <= 1/3}, {1/3 + 1/3 f[3 x - 1, n - 1], 1/3 < x <= 2/3}, {2/3 + 1/3 f[3 x - 2, n - 1], 2/3 < x <= 1}, {Indeterminate, True} }] f[x_, _, \[ScriptCapitalN]_] := Sum[(-1)^k f[x, k], {k, 0, \[ScriptCapitalN]}] Plot[f[x, _, 10], {x, 0, 1}, PlotPoints -> 100, MaxRecursion -> 5]  For the third part of your question, simply define $$p$$ as an additional parameter for your function, so it's something like f[x_, n_, p_] := ..., and edit the definitions accordingly. You can pretty much enter your question in that form in Mathematica: The first definition, f[x_, n_] /; n == 0, reads "define $$f_n(x)$$ in the case of $$n=0$$ to be the following". The fancy bracket is pretty frontend notation for the Piecewise function (shortcut: EscpwEsc). The next line is the same thing again, after that there's the definition of your function $$f(x)$$, which is the partial sum up to $$\mathcal N$$. I don't think you can use $$\mathcal N=\infty$$ in this case, as it will exceed the maximum recursion depth by, well, infinity. If you want to have an exact result, try using RSolve to get an explcit equation for $$f_n(x)$$. If you want to evaluate the code above on your own, here's a copyable version: f[x_, n_] /; n == 0 := Piecewise[{ {3 x, 0 <= x <= 1/3}, {-3 x + 2, 1/3 < x <= 2/3}, {3 x + 2, 2/3 < x <= 1}, {Indeterminate, True} }] f[x_, n_] /; n >= 0 := Piecewise[{ {1/3 f[3 x, n - 1], 0 <= x <= 1/3}, {1/3 + 1/3 f[3 x - 1, n - 1], 1/3 < x <= 2/3}, {2/3 + 1/3 f[3 x - 2, n - 1], 2/3 < x <= 1}, {Indeterminate, True} }] f[x_, _, \[ScriptCapitalN]_] := Sum[(-1)^k f[x, k], {k, 0, \[ScriptCapitalN]}] Plot[f[x, _, 10], {x, 0, 1}, PlotPoints -> 100, MaxRecursion -> 5]  For the third part of your question, simply define $$p$$ as an additional parameter for your function, so it's something like f[x_, n_, p_] := ..., and edit the definitions accordingly. 2 Added plain text version, corrected error edited Feb 13 '12 at 20:20 David 11.5k33 gold badges4242 silver badges7979 bronze badges You can pretty much enter your question in that form in Mathematica:  The first definition, f[x_, n_] /; n == 0, reads "define $$f_n(x)$$ in the case of $$n=0$$ to be the following". The fancy bracket is pretty frontend notation for the Piecewise function (shortcut: EscpwEsc). The next line is the same thing again, after that there's the definition of your function $$f(x)$$, which sumsis the partial sum up to $$\infty$$ by default$$\mathcal N$$. I don't think you can use $$\mathcal N=\infty$$ in this case, but for debuggingas it might be useful to be able to specifywill exceed the summation boundarymaximum recursion depth by, well, infinity. If you want to have an exact result, try using the parameter $$\mathcal N$$RSolve to get an explcit equation for $$f_n(x)$$. In any case I can't do and further testing since the function seemsIf you want to get out of the interval $$[0,1]$$ pretty quickly, see the output inevaluate the code above image. However, once you've definedon your function like thisown, plotting ishere's a standard problem.copyable version: f[x_, n_] /; n == 0 := Piecewise[{ {3 x, 0 <= x <= 1/3}, {-3 x + 2, 1/3 < x <= 2/3}, {3 x + 2, 2/3 < x <= 1}, {Indeterminate, True} }] f[x_, n_] /; n >= 0 := Piecewise[{ {1/3 f[3 x, n - 1], 0 <= x <= 1/3}, {1/3 + 1/3 f[3 x - 1, n - 1], 1/3 < x <= 2/3}, {2/3 + 1/3 f[3 x - 2, n - 1], 2/3 < x <= 1}, {Indeterminate, True} }] f[x_, _, \[ScriptCapitalN]_] := Sum[(-1)^k f[x, k], {k, 0, \[ScriptCapitalN]}] Plot[f[x, _, 10], {x, 0, 1}, PlotPoints -> 100, MaxRecursion -> 5]  For the third part of your question, simply define $$p$$ as an additional parameter for your function, so it's something like f[x_, n_, p_] := ..., and edit the definitions accordingly. You can pretty much enter your question in that form in Mathematica: The first definition, f[x_, n_] /; n == 0, reads "define $$f_n(x)$$ in the case of $$n=0$$ to be the following". The fancy bracket is pretty frontend notation for the Piecewise function (shortcut: EscpwEsc). The next line is the same thing again, after that there's the definition of your function $$f(x)$$, which sums to $$\infty$$ by default, but for debugging it might be useful to be able to specify the summation boundary using the parameter $$\mathcal N$$. In any case I can't do and further testing since the function seems to get out of the interval $$[0,1]$$ pretty quickly, see the output in the above image. However, once you've defined your function like this, plotting is a standard problem. For the third part of your question, simply define $$p$$ as an additional parameter for your function, so it's something like f[x_, n_, p_] := ..., and edit the definitions accordingly. You can pretty much enter your question in that form in Mathematica: The first definition, f[x_, n_] /; n == 0, reads "define $$f_n(x)$$ in the case of $$n=0$$ to be the following". The fancy bracket is pretty frontend notation for the Piecewise function (shortcut: EscpwEsc). The next line is the same thing again, after that there's the definition of your function $$f(x)$$, which is the partial sum up to $$\mathcal N$$. I don't think you can use $$\mathcal N=\infty$$ in this case, as it will exceed the maximum recursion depth by, well, infinity. If you want to have an exact result, try using RSolve to get an explcit equation for $$f_n(x)$$. If you want to evaluate the code above on your own, here's a copyable version: f[x_, n_] /; n == 0 := Piecewise[{ {3 x, 0 <= x <= 1/3}, {-3 x + 2, 1/3 < x <= 2/3}, {3 x + 2, 2/3 < x <= 1}, {Indeterminate, True} }] f[x_, n_] /; n >= 0 := Piecewise[{ {1/3 f[3 x, n - 1], 0 <= x <= 1/3}, {1/3 + 1/3 f[3 x - 1, n - 1], 1/3 < x <= 2/3}, {2/3 + 1/3 f[3 x - 2, n - 1], 2/3 < x <= 1}, {Indeterminate, True} }] f[x_, _, \[ScriptCapitalN]_] := Sum[(-1)^k f[x, k], {k, 0, \[ScriptCapitalN]}] Plot[f[x, _, 10], {x, 0, 1}, PlotPoints -> 100, MaxRecursion -> 5]  For the third part of your question, simply define $$p$$ as an additional parameter for your function, so it's something like f[x_, n_, p_] := ..., and edit the definitions accordingly. 1 answered Feb 13 '12 at 18:17 David 11.5k33 gold badges4242 silver badges7979 bronze badges You can pretty much enter your question in that form in Mathematica: The first definition, f[x_, n_] /; n == 0, reads "define $$f_n(x)$$ in the case of $$n=0$$ to be the following". The fancy bracket is pretty frontend notation for the Piecewise function (shortcut: EscpwEsc). The next line is the same thing again, after that there's the definition of your function $$f(x)$$, which sums to $$\infty$$ by default, but for debugging it might be useful to be able to specify the summation boundary using the parameter $$\mathcal N$$. In any case I can't do and further testing since the function seems to get out of the interval $$[0,1]$$ pretty quickly, see the output in the above image. However, once you've defined your function like this, plotting is a standard problem. For the third part of your question, simply define $$p$$ as an additional parameter for your function, so it's something like f[x_, n_, p_] := ..., and edit the definitions accordingly.