Message Boards Message Boards

0
|
12413 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Assigning a variable a unit

Posted 10 years ago
POSTED BY: Saf Al
4 Replies
Posted 10 years ago

Hi M.,

Your method works fine. I just entered the Quantity-Command in your Module to keep variables local, as follows:

Module[{}, WaveLenght = Quantity[\[Lambda], "Nanometers"]; 
 f[\[Lambda]_] = UnitConvert[Quantity[1, "SpeedOfLight"]]/WaveLenght; 
 f[\[Lambda]]]

Also, I realized that your units must be in Nanometer, if the example to be physically realistic. Thank you again.

POSTED BY: Saf Al
POSTED BY: Marco Thiel

Hi,

it appears that in principle the thing works, e.g.

Module[{\[Lambda]0 = Quantity[850 10^-9, "Meters"], \[Sigma] = 
   Quantity[32 10^-9, "Meters"], 
  g0 = Quantity[50 10^-2, ("Meters")^-1], \[Alpha] = 
   Quantity[32.2 10^-2, ("Meters")^-1]}, 
 pts = NSolve[
   g0 E^(-(\[Lambda] - \[Lambda]0)^2/(2 \[Sigma]^2)) == 
    Quantity[1, "Meters"^-1], {\[Lambda]}]]

I think that your input is a bit difficult to understand. Take

NSolve[g0 E^(-(\[Lambda] - \[Lambda]0)^2/(2 \[Sigma]^2)) && \[Alpha]t == 0, {\[Lambda]}]]

The first bit

g0 E^(-(\[Lambda] - \[Lambda]0)^2/(2 \[Sigma]^2))

is not an equation at all. The second bit

\[Alpha]t == 0

seems to be an impossible requirement as you have defined

\[Alpha]t = Quantity[32.2 10^-2, ("Meters")^-1]

a bit earlier. So both the magnitude and the units do not match. Remember that 0 has no unit in your equation!, i.e. 0 is not the same as Quantity[0,"Meters"^-1].

The units must be consistent in your equations or Mathematica runs in to trouble.

Cheers,

Marco

POSTED BY: Marco Thiel
Posted 10 years ago
POSTED BY: Saf Al
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract