Today I struggled with the units package - again...
Let me show you what I did:
Dynamic[Subscript[\[Tau], p]]
Subscript[l, case]
\[Lambda] = \Convert[Subscript[l, case]/Dynamic[Subscript[\[Tau], p]], 1]
This input results in:
27.4889 Meter Milli
281 Meter Milli
Convert::incomp : Incompatible units in (281 Meter Milli)/(27.4889
Meter Milli) and 1.
(281 Meter Milli)/(27.4889 Meter Milli)
If I don't use dynamic but constant tau_p everything is fine...
So Mathematica isn't able to to reduce this fraction? What's the reason
for this behaviour and what can I do about it?
Thanks for your help!
Mathias
David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/
Your example is a bit incomplete, or so it seems. What are the
definitions of Tau p and l case?
And what is the slash in \Convert doing? And why are you using Convert
for this particular conversion? The division of the two variables is
dimensionless, so no need for Convert.
Anyways, your problem is not the Units package, but the use of
Dynamic. Dynamic is a wrapper, much like InputForm or TableForm. It's
used for display in the FrontEnd, but not for calculations in the
kernel. Try for instance this definition:
g[x_Numeric] := x^2
Now enter g[Dynamic[p]]. It displays as g[p]. Now set p to 5 (p=5).
You see the old g[p] change to g[5] and not to 25. This is because the
function doesn't see the number 5, but the object Dynamic[p] which
only displays as 5 in the FrontEnd. It does not represent the value 5
to the kernel.
The same happens with your conversion. Because the units are hidden
within the Dynamic wrapper they can't be simplified by the kernel. The
error message is displayed by the FrontEnd and this exposes the units,
but (it should be clear) this is not what the kernel sees!
Read more about this in the section "Where Should Dynamic Be Placed in
an Expression?" in the tutorial tutorial/IntroductionToDynamic.
Cheers -- Sjoerd
On Mar 19, 12:25 pm, Mathias Lindner <mathias.lind...@web.de> wrote:
> Hi
>
> Today I struggled with the units package - again...
>
> Let me show you what I did:
>
> Dynamic[Subscript[\[Tau], p]]
> Subscript[l, case]
> \[Lambda] = \Convert[Subscript[l, case]/Dynamic[Subscri=
pt[\[Tau], p]], 1]
>
> This input results in:
>
> 27.4889 Meter Milli
> 281 Meter Milli
>
> Convert::incomp : Incompatible units in (281 Meter Milli)=
/(27.4889
>Today I struggled with the units package - again...
>Let me show you what I did:
>Dynamic[Subscript[\[Tau], p]]
>Subscript[l, case]
>\[Lambda] = \Convert[Subscript[l, case]/Dynamic[Subscript[\[Tau], p]], 1]
>This input results in:
>27.4889 Meter Milli
>281 Meter Milli
>Convert::incomp : Incompatible units in (281 Meter Milli)/(27.4889
>Meter Milli) and 1. (281 Meter Milli)/(27.4889 Meter Milli)
>If I don't use dynamic but constant tau_p everything is fine... So
>Mathematica isn't able to to reduce this fraction? What's the reason
>for this behaviour and what can I do about it?
I interpret your "everything is fine" to mean you got the result
you expected/wanted. And it is not at all obvious to me why you
are really attempting to do.
It appears you want to use a subscripted variable. While this
can be done in Mathematica using the Notations package, it is
not as simple as just setting Subscript[\[Tau], p] to some
value. Mathematica sees things with Head Subscript as totally
different than things with Head Symbol. And it is things with
Head Symbol Mathematica treats as variables that can be assigned
values. That is, unless you go to a bit of trouble, Mathematica
does not work as you might expect with subscripts. I strongly
suspect this is the issue you are encountering rather than a
specific issue with the units package.
Try your code using simple symbols without the subscripts. If
this works and you really want subscripted variables, learn how
to use the Notations package.
Today I struggled with the units package - again...
Let me show you what I did:
Dynamic[Subscript[\[Tau], p]]
Subscript[l, case]
\[Lambda] = \Convert[Subscript[l, case]/Dynamic[Subscript[\[Tau], p]], 1]
This input results in:
27.4889 Meter Milli
281 Meter Milli
Convert::incomp : Incompatible units in (281 Meter Milli)/(27.4889 Meter Milli) and 1.
(281 Meter Milli)/(27.4889 Meter Milli)
If I don't use dynamic but constant tau_p everything is fine...
So Mathematica isn't able to to reduce this fraction? What's the reason for this behaviour and what can I do about it?
Thanks for your help!
Mathias
David Bailey
http://www.dbaileyconsultancy.co.uk
Thanks again,
Mathias
Yes, I know. It wasn't the complete calculation. That is because the
complete one is endless ;) You helped me anyway...
>
> And what is the slash in \Convert doing? And why are you using Convert
> for this particular conversion? The division of the two variables is
> dimensionless, so no need for Convert.
No idea about the slash. In StandardForm I typed Convert[]. Must have
been input during the copy&paste into my newsreader.
I use Convert very often and it's annoying. As an example: The result of
the multiplication of a frequency and a time has to be dimensionless.
Anyway, the shown result is always in Hertz Second. Only with
Convert[...,1] the units are avoided. The same applies for Watt/(Volt
Amp), Kilo/Milli etc.
Any idea what goes wrong here?
>
> Anyways, your problem is not the Units package, but the use of
> Dynamic. Dynamic is a wrapper, much like InputForm or TableForm. It's
> used for display in the FrontEnd, but not for calculations in the
> kernel. Try for instance this definition:
>
> g[x_Numeric] := x^2
>
> Now enter g[Dynamic[p]]. It displays as g[p]. Now set p to 5 (p=5).
> You see the old g[p] change to g[5] and not to 25. This is because the
> function doesn't see the number 5, but the object Dynamic[p] which
> only displays as 5 in the FrontEnd. It does not represent the value 5
> to the kernel.
>
> The same happens with your conversion. Because the units are hidden
> within the Dynamic wrapper they can't be simplified by the kernel. The
> error message is displayed by the FrontEnd and this exposes the units,
> but (it should be clear) this is not what the kernel sees!
>
> Read more about this in the section "Where Should Dynamic Be Placed in
> an Expression?" in the tutorial tutorial/IntroductionToDynamic.
Thanks for pointing me to this tutorial. After altering the position of
Dynamic in this equation Mathematica works as expected.
>
> Cheers -- Sjoerd
Also thanks to Bill Rowe! Avoiding subscripts didn't help in my
situation but it's a good advice anyway. I will follow it.
Regards,
Mathias
The problem may lie in the fact that units that may have the same
dimensions sometimes should not be equated. Take, for instance, the
Newton Meter (N m), which occurs in moment of force expressions. It is
dimensional equivalent to a Joule. Nevertheless, in many cases you
wouldn't like the N m to be simplified to J.
BTW I actually never use units in calculations. As long as you keep
track of what the numbers mean there's never a problem.
Cheers -- Sjoerd