# How to handle Units when Integrating?

I have some functions defined, which are to use units. Now another function is used to integrate over those, with the integration variable also quantified and the input to said function. I better just show some code:

It's not pretty, but I kinda feel nothing is pretty in Mathematica. I am not very proficient in the Wolfram Language, and I don't have a lot of experience using symbolic expressions.

Back to the code: This will run fine, but when I plug some numbers or variables in, it doesn't work:

So, as you see, something is wrong. I have done several hours of research yesterday and I just cannot get it to work. I want to plot this and do some calculations, so nothing fancy, but for this to work, it has to accept inputs like 1 s and t s.

Bonus: I cannot wrap my head around these delayed functions. As you can see, h[x, s, t] evaluates nicely to some easy piecewise function. So why does it take ages and millenia to Plot this? Do I have to do h[x_, s_, t_] = ... instead of :=? This didn't seem to do anything for me. Also, this is assuming I did not use units, so that the above works.

The Code in Text:

Clear["Global*"]
g = UnitConvert[
Entity["Planet", "Earth"][EntityProperty["Planet", "Gravity"]]];
TWR[t : Quantity[_, unit_]?(CompatibleUnitQ[#, "Seconds"] &)] :=
FullSimplify[
Piecewise[{{0.65 Quantity[1, (1/("Seconds"))]*t,
0 Quantity[1, "Seconds"] < t <
2.05 Quantity[1, "Seconds"]}, {1.3325,
t >= 2.05 Quantity[1, "Seconds"]}}], t \[Element] Reals]
a[t : Quantity[_, unit_]?(CompatibleUnitQ[#, "Seconds"] &)] :=
FullSimplify[(TWR[t] - 1) g, t \[Element] Reals]
v[t : Quantity[_, unit_]?(CompatibleUnitQ[#, "Seconds"] &)] :=
FullSimplify[
Integrate[
a[Quantity[T, "Seconds"]], {Quantity[T, "Seconds"],
Quantity[0, "Seconds"], t}, Assumptions -> t \[Element] Reals],
t \[Element] Reals]
h[x_, s_, t : Quantity[_, unit_]?(CompatibleUnitQ[#, "Seconds"] &)] :=
FullSimplify[
x Quantity[1, "Meters"] +
s Quantity[1, (("Meters")/("Seconds"))]*t +
Integrate[
v[Quantity[c, "Seconds"]], {Quantity[c, "Seconds"],
Quantity[0, "Seconds"], t},
Assumptions -> t \[Element] Reals && c \[Element] Reals],
t \[Element] Reals]

• What is your desired output for, say, a[t s] and a[1 s]? Commented Mar 30, 2020 at 9:40
• Well,@CATrevillian, a[t s] is supposed to be -1g when t < 0s and 0.3325g when t > 2.05s and a linear interpolation between that in between. So a[1 s] should be -3.43m/s^2, which it is. Also v[1 s]` does give an acceptable answer, its just that v[t s] does not. Commented Mar 30, 2020 at 11:21