0
$\begingroup$

In a Wolfram Notebook,

I declare a function F1[x]=1/x where x is in "Meters"

F1[X_] = With[{x=Quantity[X,"Meters"]},1/x]

I integrate F1. Everything is Ok.

NIntegrate[F1[r],{r,1,2}]

But with the function F2[x]=1/(1-x)

F2[X_] = With[{x=Quantity[X,"Meters"]},1/(1-x)]

Integrating F2 gives an error.

NIntegrate[F2[r],{r,1,2}]

"NIntegrate :NIntegrate was unable to determine the units of quantities that appear in the input."

How can I set units for a function of the type 1/(1-x) and integrate it?

$\endgroup$
2
  • 1
    $\begingroup$ What the message is telling you is that the expression $1-2\mathrm{m}$ doesn't make any sense: you cannot subtract meters from a number. You'll have to add the appropriate unit to the $1$ in the denominator as well $\endgroup$
    – Lukas Lang
    Commented Apr 13 at 11:17
  • $\begingroup$ Thta's right! Thanks a lot for your help! $\endgroup$ Commented Apr 13 at 13:04

1 Answer 1

0
$\begingroup$

Based on @Lukas's comment, I've modified my function to F3 like this:

F3[X_]=Quantity[1/(1-X),"Meters"]

Then, the integration gives a result value with the unit.

NIntegrate[F3[r],{r,2,3}]

Out[11]=-0.693147m
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.