1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Maxima Manual: Functions and Variables for Units</title>
<meta name="description" content="Maxima Manual: Functions and Variables for Units">
<meta name="keywords" content="Maxima Manual: Functions and Variables for Units">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="maxima_toc.html#Top" rel="start" title="Top">
<link href="maxima_264.html#g_t_0423_043a_0430_0437_0430_0442_0435_043b_044c-_0444_0443_043d_043a_0446_0438_0439-_0438-_043f_0435_0440_0435_043c_0435_043d_043d_044b_0445" rel="index" title="Указатель функций и переменных">
<link href="maxima_toc.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="maxima_258.html#unit_002dpkg" rel="up" title="unit-pkg">
<link href="maxima_261.html#zeilberger_002dpkg" rel="next" title="zeilberger-pkg">
<link href="maxima_259.html#Introduction-to-Units" rel="previous" title="Introduction to Units">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
body {color: black; background: white; margin-left: 8%; margin-right: 13%;
font-family: "FreeSans", sans-serif}
h1 {font-size: 150%; font-family: "FreeSans", sans-serif}
h2 {font-size: 125%; font-family: "FreeSans", sans-serif}
h3 {font-size: 100%; font-family: "FreeSans", sans-serif}
a[href] {color: rgb(0,0,255); text-decoration: none;}
a[href]:hover {background: rgb(220,220,220);}
div.textbox {border: solid; border-width: thin; padding-top: 1em;
padding-bottom: 1em; padding-left: 2em; padding-right: 2em}
div.titlebox {border: none; padding-top: 1em; padding-bottom: 1em;
padding-left: 2em; padding-right: 2em; background: rgb(200,255,255);
font-family: sans-serif}
div.synopsisbox {
border: none; padding-top: 1em; padding-bottom: 1em; padding-left: 2em;
padding-right: 2em; background: rgb(255,220,255);}
pre.example {border: 1px solid rgb(180,180,180); padding-top: 1em;
padding-bottom: 1em; padding-left: 1em; padding-right: 1em;
background-color: rgb(238,238,255)}
div.spacerbox {border: none; padding-top: 2em; padding-bottom: 2em}
div.image {margin: 0; padding: 1em; text-align: center}
div.categorybox {border: 1px solid gray; padding-top: 1em; padding-bottom: 1em;
padding-left: 1em; padding-right: 1em; background: rgb(247,242,220)}
img {max-width:80%; max-height: 80%; display: block; margin-left: auto; margin-right: auto}
-->
</style>
<link rel="icon" href="figures/favicon.ico">
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6>"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</head>
<body lang="ru" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Functions-and-Variables-for-Units"></a>
<div class="header">
<p>
Previous: <a href="maxima_259.html#Introduction-to-Units" accesskey="p" rel="previous">Introduction to Units</a>, Up: <a href="maxima_258.html#unit_002dpkg" accesskey="u" rel="up">unit-pkg</a> [<a href="maxima_toc.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="maxima_264.html#g_t_0423_043a_0430_0437_0430_0442_0435_043b_044c-_0444_0443_043d_043a_0446_0438_0439-_0438-_043f_0435_0440_0435_043c_0435_043d_043d_044b_0445" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Functions-and-Variables-for-Units-1"></a>
<h3 class="section">72.2 Functions and Variables for Units</h3>
<a name="setunits"></a><a name="Item_003a-unit_002fdeffn_002fsetunits"></a><dl>
<dt><a name="index-setunits"></a>Function: <strong>setunits</strong> <em>(<var>list</var>)</em></dt>
<dd><p>By default, the <em>unit</em> package does not use any derived dimensions, but will
convert all units to the seven fundamental dimensions using MKS units.
</p><div class="example">
<pre class="example">(%i2) N;
kg m
(%o2) ----
2
s
</pre><pre class="example">(%i3) dyn;
1 kg m
(%o3) (------) (----)
100000 2
s
</pre><pre class="example">(%i4) g;
1
(%o4) (----) (kg)
1000
</pre><pre class="example">(%i5) centigram*inch/minutes^2;
127 kg m
(%o5) (-------------) (----)
1800000000000 2
s
</pre></div>
<p>In some cases this is the desired behavior. If the user wishes to use other
units, this is achieved with the <code>setunits</code> command:
</p><div class="example">
<pre class="example">(%i6) setunits([centigram,inch,minute]);
(%o6) done
</pre><pre class="example">(%i7) N;
1800000000000 %in cg
(%o7) (-------------) (------)
127 2
%min
</pre><pre class="example">(%i8) dyn;
18000000 %in cg
(%o8) (--------) (------)
127 2
%min
</pre><pre class="example">(%i9) g;
(%o9) (100) (cg)
</pre><pre class="example">(%i10) centigram*inch/minutes^2;
%in cg
(%o10) ------
2
%min
</pre></div>
<p>The setting of units is quite flexible. For example, if we want to
get back to kilograms, meters, and seconds as defaults for those
dimensions we can do:
</p><div class="example">
<pre class="example">(%i11) setunits([kg,m,s]);
(%o11) done
</pre><pre class="example">(%i12) centigram*inch/minutes^2;
127 kg m
(%o12) (-------------) (----)
1800000000000 2
s
</pre></div>
<p>Derived units are also handled by this command:
</p><div class="example">
<pre class="example">(%i17) setunits(N);
(%o17) done
</pre><pre class="example">(%i18) N;
(%o18) N
</pre><pre class="example">(%i19) dyn;
1
(%o19) (------) (N)
100000
</pre><pre class="example">(%i20) kg*m/s^2;
(%o20) N
</pre><pre class="example">(%i21) centigram*inch/minutes^2;
127
(%o21) (-------------) (N)
1800000000000
</pre></div>
<p>Notice that the <em>unit</em> package recognized the non MKS combination
of mass, length, and inverse time squared as a force, and converted it
to Newtons. This is how Maxima works in general. If, for example, we
prefer dyne to Newtons, we simply do the following:
</p><div class="example">
<pre class="example">(%i22) setunits(dyn);
(%o22) done
</pre><pre class="example">(%i23) kg*m/s^2;
(%o23) (100000) (dyn)
</pre><pre class="example">(%i24) centigram*inch/minutes^2;
127
(%o24) (--------) (dyn)
18000000
</pre></div>
<p>To discontinue simplifying to any force, we use the uforget command:
</p><div class="example">
<pre class="example">(%i26) uforget(dyn);
(%o26) false
</pre><pre class="example">(%i27) kg*m/s^2;
kg m
(%o27) ----
2
s
</pre><pre class="example">(%i28) centigram*inch/minutes^2;
127 kg m
(%o28) (-------------) (----)
1800000000000 2
s
</pre></div>
<p>This would have worked equally well with <code>uforget(N)</code> or
<code>uforget(%force)</code>.
</p>
<p>See also <code><a href="#uforget">uforget</a></code>. To use this function write first <code>load("unit")</code>.
</p>
</dd></dl>
<a name="uforget"></a><a name="Item_003a-unit_002fdeffn_002fuforget"></a><dl>
<dt><a name="index-uforget"></a>Function: <strong>uforget</strong> <em>(<var>list</var>)</em></dt>
<dd><p>By default, the <em>unit</em> package converts all units to the
seven fundamental dimensions using MKS units. This behavior can
be changed with the <code>setunits</code> command. After that, the
user can restore the default behavior for a particular dimension
by means of the <code>uforget</code> command:
</p><div class="example">
<pre class="example">(%i13) setunits([centigram,inch,minute]);
(%o13) done
</pre><pre class="example">(%i14) centigram*inch/minutes^2;
%in cg
(%o14) ------
2
%min
</pre><pre class="example">(%i15) uforget([cg,%in,%min]);
(%o15) [false, false, false]
</pre><pre class="example">(%i16) centigram*inch/minutes^2;
127 kg m
(%o16) (-------------) (----)
1800000000000 2
s
</pre></div>
<p><code>uforget</code> operates on dimensions,
not units, so any unit of a particular dimension will work. The
dimension itself is also a legal argument.
</p>
<p>See also <code><a href="#setunits">setunits</a></code>. To use this function write first <code>load("unit")</code>.
</p>
</dd></dl>
<a name="convert"></a><a name="Item_003a-unit_002fdeffn_002fconvert"></a><dl>
<dt><a name="index-convert"></a>Function: <strong>convert</strong> <em>(<var>expr</var>, <var>list</var>)</em></dt>
<dd><p>When resetting the global environment is overkill, there is the <code>convert</code>
command, which allows one time conversions. It can accept either a single
argument or a list of units to use in conversion. When a convert operation is
done, the normal global evaluation system is bypassed, in order to avoid the
desired result being converted again. As a consequence, for inexact calculations
"rat" warnings will be visible if the global environment controlling this behavior
(<code>ratprint</code>) is true. This is also useful for spot-checking the
accuracy of a global conversion. Another feature is <code>convert</code> will allow a
user to do Base Dimension conversions even if the global environment is set to
simplify to a Derived Dimension.
</p>
<div class="example">
<pre class="example">(%i2) kg*m/s^2;
kg m
(%o2) ----
2
s
</pre><pre class="example">(%i3) convert(kg*m/s^2,[g,km,s]);
g km
(%o3) ----
2
s
</pre><pre class="example">(%i4) convert(kg*m/s^2,[g,inch,minute]);
`rat' replaced 39.37007874015748 by 5000/127 = 39.37007874015748
18000000000 %in g
(%o4) (-----------) (-----)
127 2
%min
</pre><pre class="example">(%i5) convert(kg*m/s^2,[N]);
(%o5) N
</pre><pre class="example">(%i6) convert(kg*m^2/s^2,[N]);
(%o6) m N
</pre><pre class="example">(%i7) setunits([N,J]);
(%o7) done
</pre><pre class="example">(%i8) convert(kg*m^2/s^2,[N]);
(%o8) m N
</pre><pre class="example">(%i9) convert(kg*m^2/s^2,[N,inch]);
`rat' replaced 39.37007874015748 by 5000/127 = 39.37007874015748
5000
(%o9) (----) (%in N)
127
</pre><pre class="example">(%i10) convert(kg*m^2/s^2,[J]);
(%o10) J
</pre><pre class="example">(%i11) kg*m^2/s^2;
(%o11) J
</pre><pre class="example">(%i12) setunits([g,inch,s]);
(%o12) done
</pre><pre class="example">(%i13) kg*m/s^2;
(%o13) N
</pre><pre class="example">(%i14) uforget(N);
(%o14) false
</pre><pre class="example">(%i15) kg*m/s^2;
5000000 %in g
(%o15) (-------) (-----)
127 2
s
</pre><pre class="example">(%i16) convert(kg*m/s^2,[g,inch,s]);
`rat' replaced 39.37007874015748 by 5000/127 = 39.37007874015748
5000000 %in g
(%o16) (-------) (-----)
127 2
s
</pre></div>
<p>See also <code><a href="#setunits">setunits</a></code> and <code><a href="#uforget">uforget</a></code>. To use this function write first <code>load("unit")</code>.
</p>
</dd></dl>
<a name="usersetunits"></a><a name="Item_003a-unit_002fdefvr_002fusersetunits"></a><dl>
<dt><a name="index-usersetunits"></a>Optional variable: <strong>usersetunits</strong></dt>
<dd><p>Default value: none
</p>
<p>If a user wishes to have a default unit behavior other than that described,
they can make use of <em>maxima-init.mac</em> and the <em>usersetunits</em>
variable. The <em>unit</em> package will check on startup to see if this variable
has been assigned a list. If it has, it will use setunits on that list and take
the units from that list to be defaults. <code>uforget</code> will revert to the behavior
defined by usersetunits over its own defaults. For example, if we have a
<em>maxima-init.mac</em> file containing:
</p><div class="example">
<pre class="example">usersetunits : [N,J];
</pre></div>
<p>we would see the following behavior:
</p><div class="example">
<pre class="example">(%i1) load("unit")$
*******************************************************************
* Units version 0.50 *
* Definitions based on the NIST Reference on *
* Constants, Units, and Uncertainty *
* Conversion factors from various sources including *
* NIST and the GNU units package *
*******************************************************************
Redefining necessary functions...
WARNING: DEFUN/DEFMACRO: redefining function
TOPLEVEL-MACSYMA-EVAL ...
WARNING: DEFUN/DEFMACRO: redefining function MSETCHK ...
WARNING: DEFUN/DEFMACRO: redefining function KILL1 ...
WARNING: DEFUN/DEFMACRO: redefining function NFORMAT ...
Initializing unit arrays...
Done.
User defaults found...
User defaults initialized.
</pre><pre class="example">(%i2) kg*m/s^2;
(%o2) N
</pre><pre class="example">(%i3) kg*m^2/s^2;
(%o3) J
</pre><pre class="example">(%i4) kg*m^3/s^2;
(%o4) J m
</pre><pre class="example">(%i5) kg*m*km/s^2;
(%o5) (1000) (J)
</pre><pre class="example">(%i6) setunits([dyn,eV]);
(%o6) done
</pre><pre class="example">(%i7) kg*m/s^2;
(%o7) (100000) (dyn)
</pre><pre class="example">(%i8) kg*m^2/s^2;
(%o8) (6241509596477042688) (eV)
</pre><pre class="example">(%i9) kg*m^3/s^2;
(%o9) (6241509596477042688) (eV m)
</pre><pre class="example">(%i10) kg*m*km/s^2;
(%o10) (6241509596477042688000) (eV)
</pre><pre class="example">(%i11) uforget([dyn,eV]);
(%o11) [false, false]
</pre><pre class="example">(%i12) kg*m/s^2;
(%o12) N
</pre><pre class="example">(%i13) kg*m^2/s^2;
(%o13) J
</pre><pre class="example">(%i14) kg*m^3/s^2;
(%o14) J m
</pre><pre class="example">(%i15) kg*m*km/s^2;
(%o15) (1000) (J)
</pre></div>
<p>Without <code>usersetunits</code>, the initial inputs would have been converted
to MKS, and uforget would have resulted in a return to MKS rules. Instead,
the user preferences are respected in both cases. Notice these can still
be overridden if desired. To completely eliminate this simplification - i.e.
to have the user defaults reset to factory defaults - the <code>dontusedimension</code>
command can be used. <code>uforget</code> can restore user settings again, but
only if <code>usedimension</code> frees it for use. Alternately,
<code>kill(usersetunits)</code> will completely remove all knowledge of the user defaults
from the session. Here are some examples of how these various options work.
</p><div class="example">
<pre class="example">(%i2) kg*m/s^2;
(%o2) N
</pre><pre class="example">(%i3) kg*m^2/s^2;
(%o3) J
</pre><pre class="example">(%i4) setunits([dyn,eV]);
(%o4) done
</pre><pre class="example">(%i5) kg*m/s^2;
(%o5) (100000) (dyn)
</pre><pre class="example">(%i6) kg*m^2/s^2;
(%o6) (6241509596477042688) (eV)
</pre><pre class="example">(%i7) uforget([dyn,eV]);
(%o7) [false, false]
</pre><pre class="example">(%i8) kg*m/s^2;
(%o8) N
</pre><pre class="example">(%i9) kg*m^2/s^2;
(%o9) J
</pre><pre class="example">(%i10) dontusedimension(N);
(%o10) [%force]
</pre><pre class="example">(%i11) dontusedimension(J);
(%o11) [%energy, %force]
</pre><pre class="example">(%i12) kg*m/s^2;
kg m
(%o12) ----
2
s
</pre><pre class="example">(%i13) kg*m^2/s^2;
2
kg m
(%o13) -----
2
s
</pre><pre class="example">(%i14) setunits([dyn,eV]);
(%o14) done
</pre><pre class="example">(%i15) kg*m/s^2;
kg m
(%o15) ----
2
s
</pre><pre class="example">(%i16) kg*m^2/s^2;
2
kg m
(%o16) -----
2
s
</pre><pre class="example">(%i17) uforget([dyn,eV]);
(%o17) [false, false]
</pre><pre class="example">(%i18) kg*m/s^2;
kg m
(%o18) ----
2
s
</pre><pre class="example">(%i19) kg*m^2/s^2;
2
kg m
(%o19) -----
2
s
</pre><pre class="example">(%i20) usedimension(N);
Done. To have Maxima simplify to this dimension, use
setunits([unit]) to select a unit.
(%o20) true
</pre><pre class="example">(%i21) usedimension(J);
Done. To have Maxima simplify to this dimension, use
setunits([unit]) to select a unit.
(%o21) true
</pre><pre class="example">(%i22) kg*m/s^2;
kg m
(%o22) ----
2
s
</pre><pre class="example">(%i23) kg*m^2/s^2;
2
kg m
(%o23) -----
2
s
</pre><pre class="example">(%i24) setunits([dyn,eV]);
(%o24) done
</pre><pre class="example">(%i25) kg*m/s^2;
(%o25) (100000) (dyn)
</pre><pre class="example">(%i26) kg*m^2/s^2;
(%o26) (6241509596477042688) (eV)
</pre><pre class="example">(%i27) uforget([dyn,eV]);
(%o27) [false, false]
</pre><pre class="example">(%i28) kg*m/s^2;
(%o28) N
</pre><pre class="example">(%i29) kg*m^2/s^2;
(%o29) J
</pre><pre class="example">(%i30) kill(usersetunits);
(%o30) done
</pre><pre class="example">(%i31) uforget([dyn,eV]);
(%o31) [false, false]
</pre><pre class="example">(%i32) kg*m/s^2;
kg m
(%o32) ----
2
s
</pre><pre class="example">(%i33) kg*m^2/s^2;
2
kg m
(%o33) -----
2
s
</pre></div>
<p>Unfortunately this wide variety of options is a little confusing at first,
but once the user grows used to them they should find they have very full
control over their working environment.
</p>
</dd></dl>
<a name="metricexpandall"></a><a name="Item_003a-unit_002fdeffn_002fmetricexpandall"></a><dl>
<dt><a name="index-metricexpandall"></a>Function: <strong>metricexpandall</strong> <em>(<var>x</var>)</em></dt>
<dd><p>Rebuilds global unit lists automatically creating all desired metric units.
<var>x</var> is a numerical argument which is used to specify how many metric
prefixes the user wishes defined. The arguments are as follows, with each
higher number defining all lower numbers’ units:
</p><div class="example">
<pre class="example"> 0 - none. Only base units
1 - kilo, centi, milli
(default) 2 - giga, mega, kilo, hecto, deka, deci, centi, milli,
micro, nano
3 - peta, tera, giga, mega, kilo, hecto, deka, deci,
centi, milli, micro, nano, pico, femto
4 - all
</pre></div>
<p>Normally, Maxima will not define the full expansion since this results in a
very large number of units, but <code>metricexpandall</code> can be used to
rebuild the list in a more or less complete fashion. The relevant variable
in the <em>unit.mac</em> file is <var>%unitexpand</var>.
</p>
</dd></dl>
<a name="Item_003a-unit_002fdefvr_002f_0025unitexpand"></a><dl>
<dt><a name="index-_0025unitexpand"></a>Variable: <strong>%unitexpand</strong></dt>
<dd><p>Default value: <code>2</code>
</p>
<p>This is the value supplied to <code>metricexpandall</code> during the initial loading
of <em>unit</em>.
</p>
</dd></dl>
<hr>
<div class="header">
<p>
Previous: <a href="maxima_259.html#Introduction-to-Units" accesskey="p" rel="previous">Introduction to Units</a>, Up: <a href="maxima_258.html#unit_002dpkg" accesskey="u" rel="up">unit-pkg</a> [<a href="maxima_toc.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="maxima_264.html#g_t_0423_043a_0430_0437_0430_0442_0435_043b_044c-_0444_0443_043d_043a_0446_0438_0439-_0438-_043f_0435_0440_0435_043c_0435_043d_043d_044b_0445" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|