Function that integrates another function, with units

  • #1
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.
 
  • #2
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[6] 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?
 
  • #3
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[31] = 36 m
Out[32] = 36 m
 
Last edited:

Suggested for: Function that integrates another function, with units

Replies
7
Views
1K
Replies
1
Views
672
Replies
13
Views
1K
Replies
5
Views
1K
Replies
1
Views
508
Replies
4
Views
759
Replies
0
Views
541
Replies
10
Views
1K
Back
Top