Difference between revisions of "Units"
Line 79: | Line 79: | ||
b=a<>(mi); | b=a<>(mi); | ||
− | + | b<>mi<>km | |
+ | b<>mi<>km | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 104: | Line 105: | ||
|- | |- | ||
| 10mi || km || 16.093439999999998km | | 10mi || km || 16.093439999999998km | ||
+ | |- | ||
+ | | 11mi || km || 17.702783999999998km | ||
+ | |- | ||
+ | | 12mi || km || 19.312127999999998km | ||
+ | |- | ||
+ | | 13mi || km || 20.921471999999998km | ||
+ | |- | ||
+ | | 14mi || km || 22.530815999999998km | ||
+ | |- | ||
+ | | 15mi || km || 24.140159999999998km | ||
+ | |- | ||
+ | | 16mi || km || 25.749503999999998km | ||
+ | |- | ||
+ | | 17mi || km || 27.358848km | ||
+ | |- | ||
+ | | 18mi || km || 28.968192km | ||
+ | |- | ||
+ | | 19mi || km || 30.577536km | ||
+ | |- | ||
+ | | 20mi || km || 32.186879999999995km | ||
+ | |- | ||
+ | | 21mi || km || 33.796223999999995km | ||
+ | |- | ||
+ | | 22mi || km || 35.405567999999995km | ||
+ | |- | ||
+ | | 23mi || km || 37.014911999999995km | ||
+ | |- | ||
+ | | 24mi || km || 38.624255999999995km | ||
+ | |- | ||
+ | | 25mi || km || 40.233599999999996km | ||
+ | |- | ||
+ | | 26mi || km || 41.842943999999996km | ||
+ | |- | ||
+ | | 27mi || km || 43.452287999999996km | ||
+ | |- | ||
+ | | 28mi || km || 45.061631999999996km | ||
+ | |- | ||
+ | | 29mi || km || 46.670975999999996km | ||
+ | |- | ||
+ | | 30mi || km || 48.280319999999996km | ||
+ | |- | ||
+ | | 31mi || km || 49.889663999999996km | ||
+ | |- | ||
+ | | 32mi || km || 51.499007999999996km | ||
+ | |- | ||
+ | | 33mi || km || 53.108352km | ||
+ | |- | ||
+ | | 34mi || km || 54.717696km | ||
+ | |- | ||
+ | | 35mi || km || 56.32704km | ||
+ | |- | ||
+ | | 36mi || km || 57.936384km | ||
+ | |- | ||
+ | | 37mi || km || 59.545728km | ||
+ | |- | ||
+ | | 38mi || km || 61.155072km | ||
+ | |- | ||
+ | | 39mi || km || 62.764416km | ||
+ | |- | ||
+ | | 40mi || km || 64.37375999999999km | ||
+ | |- | ||
+ | | 41mi || km || 65.983104km | ||
+ | |- | ||
+ | | 42mi || km || 67.59244799999999km | ||
+ | |- | ||
+ | | 43mi || km || 69.201792km | ||
+ | |- | ||
+ | | 44mi || km || 70.81113599999999km | ||
+ | |- | ||
+ | | 45mi || km || 72.42048km | ||
+ | |- | ||
+ | | 46mi || km || 74.02982399999999km | ||
+ | |- | ||
+ | | 47mi || km || 75.639168km | ||
+ | |- | ||
+ | | 48mi || km || 77.24851199999999km | ||
+ | |- | ||
+ | | 49mi || km || 78.857856km | ||
+ | |- | ||
+ | | 50mi || km || 80.46719999999999km | ||
+ | |- | ||
+ | | 51mi || km || 82.076544km | ||
+ | |- | ||
+ | | 52mi || km || 83.68588799999999km | ||
+ | |- | ||
+ | | 53mi || km || 85.295232km | ||
+ | |- | ||
+ | | 54mi || km || 86.90457599999999km | ||
+ | |- | ||
+ | | 55mi || km || 88.51392km | ||
+ | |- | ||
+ | | 56mi || km || 90.12326399999999km | ||
+ | |- | ||
+ | | 57mi || km || 91.732608km | ||
+ | |- | ||
+ | | 58mi || km || 93.34195199999999km | ||
+ | |- | ||
+ | | 59mi || km || 94.951296km | ||
+ | |- | ||
+ | | 60mi || km || 96.56063999999999km | ||
+ | |- | ||
+ | | 61mi || km || 98.169984km | ||
+ | |- | ||
+ | | 62mi || km || 99.77932799999999km | ||
+ | |- | ||
+ | | 63mi || km || 101.388672km | ||
+ | |- | ||
+ | | 64mi || km || 102.99801599999999km | ||
+ | |- | ||
+ | | 65mi || km || 104.60735999999999km | ||
+ | |- | ||
+ | | 66mi || km || 106.216704km | ||
+ | |- | ||
+ | | 67mi || km || 107.82604799999999km | ||
+ | |- | ||
+ | | 68mi || km || 109.435392km | ||
+ | |- | ||
+ | | 69mi || km || 111.04473599999999km | ||
+ | |- | ||
+ | | 70mi || km || 112.65408km | ||
+ | |- | ||
+ | | 71mi || km || 114.26342399999999km | ||
+ | |- | ||
+ | | 72mi || km || 115.872768km | ||
+ | |- | ||
+ | | 73mi || km || 117.48211199999999km | ||
+ | |- | ||
+ | | 74mi || km || 119.091456km | ||
+ | |- | ||
+ | | 75mi || km || 120.70079999999999km | ||
+ | |- | ||
+ | | 76mi || km || 122.310144km | ||
+ | |- | ||
+ | | 77mi || km || 123.91948799999999km | ||
+ | |- | ||
+ | | 78mi || km || 125.528832km | ||
+ | |- | ||
+ | | 79mi || km || 127.13817599999999km | ||
+ | |- | ||
+ | | 80mi || km || 128.74751999999998km | ||
+ | |- | ||
+ | | 81mi || km || 130.356864km | ||
+ | |- | ||
+ | | 82mi || km || 131.966208km | ||
+ | |- | ||
+ | | 83mi || km || 133.575552km | ||
+ | |- | ||
+ | | 84mi || km || 135.18489599999998km | ||
+ | |- | ||
+ | | 85mi || km || 136.79424km | ||
+ | |- | ||
+ | | 86mi || km || 138.403584km | ||
+ | |- | ||
+ | | 87mi || km || 140.012928km | ||
+ | |- | ||
+ | | 88mi || km || 141.62227199999998km | ||
+ | |- | ||
+ | | 89mi || km || 143.231616km | ||
+ | |- | ||
+ | | 90mi || km || 144.84096km | ||
+ | |- | ||
+ | | 91mi || km || 146.450304km | ||
+ | |- | ||
+ | | 92mi || km || 148.05964799999998km | ||
+ | |- | ||
+ | | 93mi || km || 149.668992km | ||
+ | |- | ||
+ | | 94mi || km || 151.278336km | ||
+ | |- | ||
+ | | 95mi || km || 152.88768km | ||
+ | |- | ||
+ | | 96mi || km || 154.49702399999998km | ||
+ | |- | ||
+ | | 97mi || km || 156.10636799999997km | ||
+ | |- | ||
+ | | 98mi || km || 157.715712km | ||
+ | |- | ||
+ | | 99mi || km || 159.325056km | ||
+ | |- | ||
+ | | 100mi || km || 160.93439999999998km | ||
|} | |} | ||
+ | |||
Revision as of 11:48, 13 June 2016
How to specify units
Units are a unique, inherent and simple feature of the z^3 language.
Using units is simple and easy. For example:
a=1m;
indicates that a is now a variable containing the value of 1 meter. For more complex units we can enclose them in brackets as in 3(m/sec).
If a variable needs to be specified in specific units, simply use the <> operator. Such as: a<>(m/sec);
In z^3 language, <> is the unit conversion operator. Also, any arithmetic operator such as +, -, *, /, ^, % etc. should be enclosed within < and > to allow unit conversions to propagate through these operations. These conversion operations can be done on arrays as parameters also. Hence to add a meter to 2 centimeters, do the following: a=1m<+>2cm; and z^3 will give the answer: 102 cm.
Note, that this result now carries the units with it for further operations. For example: a=(1m<+>2cm)<^>3; gives the answer as 1061208 cm3.
To convert the current value of a variable to a different unit, simply use the <> operator: a<>cm;
Notice that if a already had a unit, it will be appropriately converted using the units. If it did not have units inherently, it will simply be given the units. $> a=1 1 $> a<>cm; 1 cm.
$> a=1m; 1 m. $> a<>cm; 100 cm.
In the second case, 1m is converted to 100cm.
Unit Prefixes
Similarly, scales such as milli, mega, etc. are supported using conventional SI units. a=1m; 1 m. a<>ym; 1.0000000000000001e+24 ym.
Here a now has the unit yoctometer.
Using uppercase Y, we get the answer in Yottameter. a=1m; 1 m. a<>Ym; 1.0000000000000001e-24 Ym.
These conversions of scale follow the SI unit prefix standards.
Conversion among Unit Systems
z^3 supports conversion among unit systems, such as SI Units and FPS systems.
For example:
a=1mi; 1 mi.
a<>km; 1.6093439999999999 km.
Notice that the mi (miles) unit of variable a is converted to km.
Units on Array of Values
Units work on variables as simple numerical values or as arrays.
Let us consider numbers 1 to 100. a=1..100;
b=a<>(mi);
b<>mi<>km b<>mi<>km
Numeric | Units | UNITSOF |
---|---|---|
1mi | km | 1.6093439999999999km |
2mi | km | 3.2186879999999998km |
3mi | km | 4.828031999999999km |
4mi | km | 6.4373759999999995km |
5mi | km | 8.046719999999999km |
6mi | km | 9.656063999999999km |
7mi | km | 11.265407999999999km |
8mi | km | 12.874751999999999km |
9mi | km | 14.484096km |
10mi | km | 16.093439999999998km |
11mi | km | 17.702783999999998km |
12mi | km | 19.312127999999998km |
13mi | km | 20.921471999999998km |
14mi | km | 22.530815999999998km |
15mi | km | 24.140159999999998km |
16mi | km | 25.749503999999998km |
17mi | km | 27.358848km |
18mi | km | 28.968192km |
19mi | km | 30.577536km |
20mi | km | 32.186879999999995km |
21mi | km | 33.796223999999995km |
22mi | km | 35.405567999999995km |
23mi | km | 37.014911999999995km |
24mi | km | 38.624255999999995km |
25mi | km | 40.233599999999996km |
26mi | km | 41.842943999999996km |
27mi | km | 43.452287999999996km |
28mi | km | 45.061631999999996km |
29mi | km | 46.670975999999996km |
30mi | km | 48.280319999999996km |
31mi | km | 49.889663999999996km |
32mi | km | 51.499007999999996km |
33mi | km | 53.108352km |
34mi | km | 54.717696km |
35mi | km | 56.32704km |
36mi | km | 57.936384km |
37mi | km | 59.545728km |
38mi | km | 61.155072km |
39mi | km | 62.764416km |
40mi | km | 64.37375999999999km |
41mi | km | 65.983104km |
42mi | km | 67.59244799999999km |
43mi | km | 69.201792km |
44mi | km | 70.81113599999999km |
45mi | km | 72.42048km |
46mi | km | 74.02982399999999km |
47mi | km | 75.639168km |
48mi | km | 77.24851199999999km |
49mi | km | 78.857856km |
50mi | km | 80.46719999999999km |
51mi | km | 82.076544km |
52mi | km | 83.68588799999999km |
53mi | km | 85.295232km |
54mi | km | 86.90457599999999km |
55mi | km | 88.51392km |
56mi | km | 90.12326399999999km |
57mi | km | 91.732608km |
58mi | km | 93.34195199999999km |
59mi | km | 94.951296km |
60mi | km | 96.56063999999999km |
61mi | km | 98.169984km |
62mi | km | 99.77932799999999km |
63mi | km | 101.388672km |
64mi | km | 102.99801599999999km |
65mi | km | 104.60735999999999km |
66mi | km | 106.216704km |
67mi | km | 107.82604799999999km |
68mi | km | 109.435392km |
69mi | km | 111.04473599999999km |
70mi | km | 112.65408km |
71mi | km | 114.26342399999999km |
72mi | km | 115.872768km |
73mi | km | 117.48211199999999km |
74mi | km | 119.091456km |
75mi | km | 120.70079999999999km |
76mi | km | 122.310144km |
77mi | km | 123.91948799999999km |
78mi | km | 125.528832km |
79mi | km | 127.13817599999999km |
80mi | km | 128.74751999999998km |
81mi | km | 130.356864km |
82mi | km | 131.966208km |
83mi | km | 133.575552km |
84mi | km | 135.18489599999998km |
85mi | km | 136.79424km |
86mi | km | 138.403584km |
87mi | km | 140.012928km |
88mi | km | 141.62227199999998km |
89mi | km | 143.231616km |
90mi | km | 144.84096km |
91mi | km | 146.450304km |
92mi | km | 148.05964799999998km |
93mi | km | 149.668992km |
94mi | km | 151.278336km |
95mi | km | 152.88768km |
96mi | km | 154.49702399999998km |
97mi | km | 156.10636799999997km |
98mi | km | 157.715712km |
99mi | km | 159.325056km |
100mi | km | 160.93439999999998km |
a=(1..100)<>℃
b=a<>℉
E:=(m<>kg)*(SPEEDOFLIGHT()<^>2); E(2kg)
a=1mi; b=10km; [a,b,(a<+>b)<>mi]
10mi<>km
Pi seems to be obfuscated.
SIN(90<>deg)
(rad2piby10)<>rad<>deg
((rad2piby10)<>rad<>deg)@SIN .graphin() //did not work in safari. (1..10)<>kg
b=(100$<+>3020¢); b<>$;
SETCONVERSION(1<>euro,1<>dollar,1.1)
SETCONVERSION(1$,1€,0.9); PRINTCONVERSION(); 345$<>€
1$<>1₹ // without conversion will fail.
(1..100)<>℃<>℉
SETCONVERSION(1<>€,1<>$,1.1); (1..100)<>€<>$
SETCONVERSION(1<>€,1<>$,1.10); (1..1000..10)<>€<>$
SETCONVERSION(1<>€,1<>$,1.10); (0..1000..20)<>€<>$
UNITIFY([1m,2m,3cm])
SUM(UNITIFY([1m,2m,3mm]))
(100$<+>300¢<+>30¢)<>$ PMT(4%,12,1000$,120000¢,0)
PMT(4%,12,1000$,1200.00¢,0) PMT(4%,12,1000$,120000¢,0)
1<>gal<>l 1<>l<>oz
(1..100)<>l<>ul 1Pa<>atm
E:=(m<>kg)<*>(SPEEDOFLIGHT()<^>2); b=E(2g); ConvertToUnitOfNature(b,"energy")
1m<>>1cm;
[1m,2m]<>>[1cm,200cm];
[1m,2m]<>=>[1cm,200cm];
[1m,2m]<<>[1cm,200cm];
[1m,2m]<<>[1cm,200cm];
[1m,2m]<==>[1cm,200cm];
[1m,2m]<!=>[1cm,200cm];
[1m,2m]<<=>[1cm,199.99cm];
[1m,2m]<<=>[1cm,200.01cm];
((1..10)<>m)<>>3m;
((0.1..10)<>m)<>>30cm
CONSTANT("G")
CONSTANT("G")<*>1kg<*>110kg</>(6000m<^>2) // did not work.
(CONSTANT("G")<*>1kg<*>110kg)</>((6000m)<^>2) // how to bracket the units to be inside and ignore < etc? // ## can be used to name variables with spaces in them. // the actual variable is named by removing the spaces. // otherwise it goes into code as it is. ##weight of zone=3m; ++(##weight of zone);
##weight of zone=3m; a=3.4mm<+>(##weight of zone);
//%G is gravitational constant GF:=%G*m1*m2/r^2; GF(1,2,300)
v:=u+%g*t; // this uses %g as default g value v(1,2)
%planck %boltzmann; %planck length;
PRINTCONVERSIONS() CONSTANTS() CONVERT()
A¹=34; A=[23,4,5,5]; /* no array indexing on subscript yet. Will decide on that later. */ A¹=[23,4,5,5] A¹[2]
a=%gravit; b=30<*>a
a=%gravit; b=(1..10)<*>a
E:=m<>kg<*>%c<^>2; E(1000kg) E(1000kg<>lbm) // - will gave same result as 1000kg E(1000lbm) //lbm is used for units of lb mass.
// %G<*>1kg<*>110kg(6000m<^>2) // %G<*>1kg<*>110kg((6000m)<^>2) // -did not work. Said 7.34149141e-9Nm3UNITPOWERUNITSOF %G<*>1kg<*>110kg<*>((6000m)<^>2)
%G<*>1kg<*>110kg</>((6000m)<^>2)
// make this work.
1..100 @> x.txt; // send output to
a <@ x.txt; // read input from
a;
1.3J<>GeV 1.3J<>eV
1J<>l.atm; // 0.0098692latm 1J<>(l.atm-1) // this should fail. and will keep original units. maybe safer. 1m2<>in2 1m²<>in²
10m2<>are 1m2<>are
100m2<>acre
E:=m<>kg<*>%c<^>2; b=E(1000kg)<>J
c=b<>eV;
[b,c]
1..100.$("[SIN(x),COS(x),TAN(x)]") 1..100.$([SIN,COS,TAN]) worked. 1..100.$("[x,x^2,x^3,x^4,x^3+x^4,SIN(x)]") works 1..100.$("[SIN(x),COS(x),TAN(x)]") 1..100.$([SIN,COS,TAN]) x=SERIESOF("1/x",9,10) //this is to from in parameter sequence. x=SERIESOF("1/x",19,10) SERIESOF("1/x",10,5) x=SERIESOF "1/LOG(x,2)" 100 1 x=SERIESOF "1/log2x" 100 91 //removed: 1..10.$_([+,-]) 1..10.$_([SUM,MINUS]) //removed: 1..10.$_|+| EXPOF(5) [SIN,COS]@[1..100] 1..10.$_("+") 1..10.$_("+") 1..10@["+"] 1..10@"+"
(1..100)<>m<+>10cm
MAGICSQUARE(3).$$(SUM) MAGICSQUARE(3).$$$(SUM) MAGICSQUARE(3).$_(SUM)
a=1m<>mm<+>400km 1m<>eor // should give nothing as there is no such conversion. (((1..100)<>m)<^>2)<>are
(1..1000)<>$ (((1..100)<>m)<^>2)<>km2 // why chinese headers here?
(1..100)m<>cm
F=%G<*>100kg<*>10g</>((100km)<^>2);
1.3J<>GeV //check this
velocity=3<>(m/sec); time=1hr; velocity<*>time;
1(g.m)<>(mg.cm)
a=LAZYRANGE(1,100) a(1..100) // generate numbers in the range at that interval, without having to generate the array ahead of time. Useful in things like INTEGRALS etc. a() a=LAZYOBJECT(1,100,1000) // can even take a(0.1); a.islazyrange()
1(kg.m2s-2)<>(N.m)
1(kg.m2s-2)<>J
1(kg.m2s-2)<>(N) // also should work as we want to get rid of the /s here in this case.
1(kg.m2s-2)<>(N.m2) // should fail.
1(kg.m2s-2)<>(J/s) // should fail.
1(kg.m2s-3)<>(J/s)
1(kg.m2.s)<>(J/s) // should this fail? it works now.
12(g.m-1/s)<>(g.cm) // should fail. 12(g.m)<>(g.mm) // should not fail. 12(g.m)<>(g.cm) // should not fail.
12(g.m)<>(g.s) // should fail. original should be returned. 12(g.m)<>(g.mm) 12(g.m)<>(g.s) 12(g.m-1)<>(g.mm-1) 12(g.m-1/s)<>(g.cm-1) // converts, but this is ok, since /s on left sometimes we want to get rid off for some reason for using it on another calculation. Say N/s but you only want to use the N on it. 1(kg.m2/s2)<>e // how to make this conversion?
1(kg.m2/s2)<>J<>e
1.3(kg.m2/s2)<>Jo // would fail and original will be kept.
(((1..100)<>m)<^>2)<>are (1..100)<>are [1cm2,2m2]<>are %pi*34; %e; %avo;
q=1(mol/s); heat=%avo<*>q;
1Pa<>atm 1atm<>psi 1atm<>hPa
a=1<>(kg/m.s-2)<>Pa<>torr 1J<>BTU 1ly<>m 10ly<>m<>km
1atm<>inHg<>mmHg
1atm<+>1bar (1atm<+>1bar)<>atm 1km<>m<>lightyear
1lightyear<>km
1lightyear<>pc
1m<>ly
1km<>ly //seemed off. this is possibly correct. (1km<+>1ly)<>km
1Å<>km
1Å<>m
(1..100)<>AU<>m
1degree<>arcminute
1Tsec<>sec
1(m/s)<>(km/hr) 1(km/s)<>(km/hr)
1(cal/mn)<>(J/sec) // d
1(kg/m3)<>(slug.ft-3)
2(rad/sec)<>rpm // did not convert. not sure why.
(1..100)<>USD<>EUR
SUPPORTEDUNITS()
1nibble<>bit 102400000000bit<>MB 1kB<>MB // seems wrong. 1kB<>Mb 1(kb)<>(bit) Pi<>(rad/sec)<>rpm 1(rad/sec)<>rpm 1(rad/mn)<>rpm (1(rad/mn)<>rpm)*2*Pi // should give 1. 1(rotation/mn)<>rpm 1(cycle/mn)<>(rad/mn)
1(cycle/mn)<>rpm
60rad<>deg 60rad<>deg<>rotation
1MB<>kB 1B<>kB 1MB<>B 1kB<>B
a=1(kg/m/s-2/t3) a=1(kg/m/s-2/t3) a=1(kg/m/s-2/t3) a=1(kg/m/s-2/t3) a=1<>(kg/m.s-2) // this worked though.
1(kg/m3)<>(slug/ft^3) // will not work due to ^. 1(kg/m3)<>(slug/ft3) //works 1(kg/m3)<>(slug.ft-3) //works
1(s-1)<>Hz 1(mn-1)<>Hz
velocity=3<>(m/s); time=1hr; velocity<*>time;
(((1..100)<>m)<^>2)<>acre
((1..100)<>m)<^>2