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

plotting equations with units

170 views
Skip to first unread message

phillman5

unread,
Sep 1, 2007, 12:45:38 AM9/1/07
to
If you have loaded the units package and have used units in your
equations, is there an easy way to plot the equations? For the y data
you can easily divide by the 'units' to get a unitless number

Plot[eq/units,{x, start,end}]

but what about the x values? If they have units, the plot functions
croaks. I suppose you can always make a table and use listplot, but
there should be an easier way. I have seen some people here with
packages to download, is there a consensus on the best third part
solution. I'd like a universal solution that would work with other
plotting functions too.

I am using version 6.


David Park

unread,
Sep 2, 2007, 2:53:00 AM9/2/07
to
You don't show your particular case, but the simplist method for you might
be to write a set of rules that set the particular units you have to 1.

For a more general method for handling this I would like to refer you to the
ExtendUnits package from my web site. (I'm selling the package for $30.)
Here is the approach I take.

First, I never put units into an equation or symboic definition. Units are
part of the data. Here is an example. First the symbolic definition and then
the data.

Needs["Units6`ExtendUnits6`"]

x[x0_, v0_, a_][t_] := x0 + v0 t + 1/2 a t^2

data = {x0 -> 3 Feet, v0 -> 2 Yard/Second, a -> 5 Meter/Second^2};

Then we can define a plotting function using the Deunitize command in
ExtendUnits6. The implied units will be in SI, so t will be in Seconds and
the output will be in Meters. It is also possible to specify implied MKS or
GCS units.

xplot[t_] = Deunitize[x[x0, v0, a][t] /. data, {t}]

giving: 1143/1250 + (1143 t)/625 + (5 t^2)/2

Plot[xplot[t], {t, 0, 5},
Frame -> True,
FrameLabel -> {"t Seconds", "x Meters"}]

There is also a more general routine, DeunitizeWithReference. It allows us
to give specific implied input and output units. Here is a variation of the
same case.

Clear[x];
x[t_, x0_, v0_, a_] := x0 + v0 t + 1/2 a t^2

Here we specify a deunitized expression where t is given in Minutes, v0 is
given in Yards/Second and the output will be in Furlongs. x0 and a are given
explicit values. The routine checks that the specified implied units are
consistent and it prints a reference expression with the units in it.

Clear[xplot];
xplot[v0_][t_]=DeunitizeWithReference[x[t Minute, 3 Meter, v0 Yard/Second,
5Meter/Second^2],{t,v0},Furlong]

(I omit the reference equation because it doesn't copy and paste neatly.)

giving: (125 (3 + 9000 t^2 + (6858 t v0)/125))/25146

Here is a plot for v0 = 0 and 100 Yards/Second.

Plot[{xplot[0][t], xplot[100][t]}, {t, 0, 5},
Frame -> True,
FrameLabel -> {"t Minutes", "x Furlongs"}]

The package also has the capability of setting up reduced units where
certain physical constants are set equal to 1 (such as geometric units or
atomic units) and that is another method for obtaining expressions without
explicit units.


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

"phillman5" <PHIL...@gmail.com> wrote in message
news:fbaqpi$qbs$1...@smc.twtelecom.net...

Szabolcs

unread,
Sep 2, 2007, 3:07:11 AM9/2/07
to

If e.g. x has a dimension of length, how about

Plot[Evaluate[eq/units /. x -> x Meter], {x, 0, 10}]

? You need to decide on what units to use for the vertical ('units')
and horizontal ('Meter') axis anyway.

Szabolcs

John Jowett

unread,
Sep 4, 2007, 6:32:47 AM9/4/07
to
Hello,
I felt this need several years ago also and implemented a
function which allows you to do things like

PhysicalUnitsPlot[ x^2 +(10 Meter) x,{x,1 Meter,20 Foot}]

PhysicalUnitsPlot[Eb^2,{Eb,.5 Nano Pascal Meter^3,5 GeV}]

i.e., the range of the x-axis is specified with explicit units and the
maximum and minimum can even be different provided they are of
physically equivalent dimensions. The units are also included in the
axis labels.

I must admit, though, that since developing it I have hardly ever used
this function ...

You can download a version of the package containing this from:

http://jowett.web.cern.ch/jowett/Accelerator/ConstantsUnits.html

The package notebook contains examples.

This is for Mathematica Version 5.2. An update for Version 6 is more
or less ready but still being checked and will be available in a
different form. Let me know if you would like an advance copy.

John Jowett

0 new messages