# Function that integrates another function, with units

• Mathematica
• Swamp Thing

#### Swamp Thing

Velocity as a function of time, defined with units attached (Quantity feature of Mathematica):
Code:
fnVq[t_ ]:= 2   m/s^2   * t
fnVq[5 s]
Integrate[fnVq[tt],{tt,0 s, 2000 ms}]
10m/s
4m
When we printed above the value and integral, we got the correct results with proper units.

Now I'm trying to define another function:
Code:
fnX[tx_]:=Integrate[fnVq[tt  ], {tt ,0 ,tx   }]
fnX[6 ]
36m/(s)^2

How can I fix the above so it outputs 36 m ? Also, I would like to print say fnX[ 2000 ms ] and have it interpret the milliseconds correctly and output the correct value with correct units.

Velocity as a function of time, defined with units attached (Quantity feature of Mathematica):
Code:
fnVq[t_ ]:= 2   m/s^2   * t
fnVq[5 s]
Integrate[fnVq[tt],{tt,0 s, 2000 ms}]
10m/s
4m
When we printed above the value and integral, we got the correct results with proper units.

Now I'm trying to define another function:
Code:
fnX[tx_]:=Integrate[fnVq[tt  ], {tt ,0 ,tx   }]
fnX[6 ]
36m/(s)^2

How can I fix the above so it outputs 36 m ? Also, I would like to print say fnX[ 2000 ms ] and have it interpret the milliseconds correctly and output the correct value with correct units.

Observe that in the first example, you do not integrate between 0 and 2000, but between 0 s and 2000 ms. In the second example,  fnX computes Integrate[fnVq[tt ], {tt ,0 ,6 }] which is not what you want; you want Integrate[fnVq[tt ], {tt ,0 s,6 s }]. Can you see how to fix the definition of fnX and what argument you must pass to it in order to get that result?

Thanks, this worked:
Code:
fnVq[t_]:=2   m/(s)^2  *t
fnX[x_]:= Integrate[fnVq[tt],{tt,0  s,x}]

fnX[6 s]
fnX[6000 ms]

Out = 36 m
Out = 36 m

Last edited: