# How to convert Piecewise function to Interpolation function?

In the following piece of code I am trying to convert a Piecewise function to a simple interpolation function f[t_]

T=10000
f[t_] := FunctionInterpolation[
Piecewise[{{0, 0 <= t <= T/4}, {1 - Sin[2*\[Pi]*t/T],
T/4 <= t <= 3*T/4}, {2, 3*T/4 <= t <= T}}], {t, 0, T},
InterpolationOrder -> 10]

However

1. I was not able to plot it: Plot[f[t], {t, 0, T}] resulted in

FunctionInterpolation::range: Argument {0.817143,0,T} is not in the form of a range specification, {x, xmin, xmax}.

2. I was not able to configure WorkingPrecision: when adding ...WorkingPrecision -> 20], WorkingPrecision comes in red.

Can anyone help?

• What is T ? Without its numerical value Plot cannot plot. Commented Feb 5, 2020 at 10:11
• Actually I forgot T but your answer is great: it is more practical to have T as a parameter.
– user67126
Commented Feb 5, 2020 at 10:48

A little large for a comment: Change the function definition as:

f[t_, T_] :=
FunctionInterpolation[
Piecewise[{{0, 0 <= t <= T/4}, {1 - Sin[2*\[Pi]*t/T],
T/4 <= t <= 3*T/4}, {2, 3*T/4 <= t <= T}}], {t, 0, T},
InterpolationOrder -> 10]

Now this yields an Interpolation function.

f[t, 10]

And can be plotted.

Plot[f[t, 10][x], {x, 0., 10.}]

• And what about Working Precision?
– user67126
Commented Feb 5, 2020 at 10:39
• Where were you adding the WorkingPrecision option ? Commented Feb 5, 2020 at 16:32
• Well, I tried in the end of the FunctionInterpolation block, I mean FunctionInterpolation[...bla,bla,bla,....,WorkingPrecision->100]. That is how it works for NDSolve or Plot however it does now work for FunctionInterpolation.
– user67126
Commented Feb 6, 2020 at 10:20
• That is because WorkingPrecision is not a valid option for FunctionInterpolation. See Options[FunctionInterpolation] Commented Feb 6, 2020 at 10:33
• Ok, then this should be discussed in a seperate question. Thanks for your help!
– user67126
Commented Feb 6, 2020 at 11:57