# Why doesn't this function definition work?

I am trying to define a following function (which is a convolution integral)

force[τ_] :=
Piecewise[{
{F0 τ/(t1/2), 0 <= τ < t1/2},
{2 F0 (1 - τ/t1), t1/2 <= τ < t1},
{0, t1 <= τ}}]
x1[t_] :=
Integrate[
1/m force[τ] 1/ω0 Sin[ω0 (t - τ)], {τ, 0, t},
Assumptions -> {0 <= t, t <= t1/2}]

F0 = 31.6*1000 (*N*);
t1 = 0.0109 (*s*);
m = 4200(*kg*);
k = 40000;
ω0 = Sqrt[k/m];

xprvi = Plot[x1[t], {t, 0, t1/2}, PlotRange -> All]


Yet this doesn't work at all. Not even close. The output is empty. I thought this is a correct definition, yet it looks like I was wrong.

• What happens if you replace := with = in the definition for x1 (after clearing all previous definitions)? – J. M.'s discontentment Apr 10 '16 at 13:49

You have made a couple of simple mistakes.

1. Define x1 with Set, not SetDelayed. You don't want to do the integral over and over again when you plot it.

2. Plot x1[t], not x1. Otherwise, the t in x1 will be in a different scope than the t in the 2nd argument to Plot.

F0 = 31.6*1000 (*N*);
t1 = 0.0109 (*s*);
m = 4200(*kg*);
k = 40000;
ω0 = Sqrt[k/m];

force[τ_] :=
Piecewise[
{{F0 τ/(t1/2), 0 <= τ < t1/2},
{2 F0 (1 - τ/t1), t1/2 <= τ < t1},
{0, t1 <= τ}}]
x1[t_] =
Integrate[
1/m force[τ] 1/ω0 Sin[ω0 (t - τ)], {τ, 0, t},
Assumptions -> {0 <= t, t <= t1/2}]

Piecewise[{{7.24771 (20. t - 6.48074 Sin[3.08607 t]), 0. < t <= 0.00545}}, 0.]

Plot[x1[t], {t, 0, t1/2}] 