Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Incompatible units?

17 views
Skip to first unread message

Mathias Lindner

unread,
Mar 19, 2009, 6:25:12 AM3/19/09
to
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[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

unread,
Mar 20, 2009, 3:39:19 AM3/20/09
to
Why don't you give us a complete set of evaluable code, including loading
the package. Without that it is difficult to see what is happening.


David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/

Sjoerd C. de Vries

unread,
Mar 20, 2009, 3:41:28 AM3/20/09
to
Hi Mathias,

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

Bill Rowe

unread,
Mar 20, 2009, 3:41:50 AM3/20/09
to
On 3/19/09 at 5:25 AM, mathias...@web.de (Mathias Lindner)
wrote:

>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.


Mathias Lindner

unread,
Mar 20, 2009, 3:43:25 AM3/20/09
to
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[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

unread,
Mar 21, 2009, 6:19:11 AM3/21/09
to
Your code is still obviously incomplete - for example, the number
27.4889 must come from something. Give us some complete code, and try to
explain what you are trying to do with the Dynamic.

David Bailey
http://www.dbaileyconsultancy.co.uk

Mathias Lindner

unread,
Mar 21, 2009, 6:19:33 AM3/21/09
to
Thank you all very much. Even within those few answers I have learned
really much. Well, I am sure I use Mathematica the wrong way - without
doubts. I always used another system to do such engineering calculations but
because of a change of licenses I was forced to migrate to Mathematica.
Don't get me wrong, I like it, but I never had the time to completely
learn it. I just used it the way I used the other system and it worked more or
less ;)
I will try the recommendations you gave and will report back.

Thanks again,
Mathias

Mathias Lindner

unread,
Mar 24, 2009, 6:27:19 AM3/24/09
to
Sjoerd C. de Vries schrieb:

> Hi Mathias,
>
> Your example is a bit incomplete, or so it seems. What are the
> definitions of Tau p and l case?

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

Sjoerd C. de Vries

unread,
Mar 25, 2009, 6:42:11 AM3/25/09
to
On Mar 24, 12:27 pm, Mathias Lindner <mathias.lind...@web.de> wrote:
> 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?

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

0 new messages