1 /* tests for solving dimensional equations */
3 (load (physical_constants), 0);
6 ([a, c, d] : [1 ` m, 2 ` m, 3 ` m], 0);
9 dimensionally (solve ([A = a * b, b = c * d], [A, b]));
10 [[A = 6 ` m^3,b = 6 ` m^2]];
12 foo : dimensionally (solve (x ` m = 5 ` ft, x));
21 /* A quadratic equation. */
23 foo : dimensionally (solve (10^6 ` Btu = 1/2 * (10 ` lbm) * v^2, v));
24 [v = (-8*5^(5/2)) ` sqrt(Btu)/sqrt(lbm),v = 8*5^(5/2) ` sqrt(Btu)/sqrt(lbm)];
27 ['dimensions(v) = length/time,'dimensions(v) = length/time];
30 [v `` m/s = (-128*5^(13/2)*sqrt(1055)/sqrt(45359237)) ` m/s,
31 v `` m/s = 128*5^(13/2)*sqrt(1055)/sqrt(45359237) ` m/s];
34 [v `` m/s = (-21567.92463845543) ` m/s,v `` m/s = 21567.92463845543 ` m/s];
36 /* An example involving symbolic constants (Planck's and speed of light). */
38 (declare ([E, %lambda], dimensional),
39 foo : block ([E : 10^-20 ` J], dimensionally (solve (E * %lambda = %c * %h, %lambda))));
40 [%lambda = %c*%h*(100000000000000000000 ` 1/J)];
43 ['dimensions(%lambda) = length];
45 foo1 : foo, constvalue;
46 [%lambda = 6207642188737199/312500000000000000000 ` m];
49 [%lambda = 1.986445500395904E-5 ` m];
51 /* Stefan-Boltzmann law -- radiant heat transfer
52 * Try it 2 ways -- one late substitution with numerical values, one early,
53 * should turn out the same both ways
56 declare ([E, %A, %T, sigma_sb], dimensional);
59 foo : dimensionally (solve (E = %A * %T^4 * sigma_sb, %T));
60 [%T = %i*(E/(%A*sigma_sb))^(1/4),%T = -(E/(%A*sigma_sb))^(1/4),
61 %T = -%i*(E/(%A*sigma_sb))^(1/4),%T = (E/(%A*sigma_sb))^(1/4)];
64 ['dimensions(%T) = 'dimensions(%i)*('dimensions(E)/('dimensions(%A)*'dimensions(sigma_sb)))^(1/4),
65 'dimensions(%T) = -('dimensions(E)/('dimensions(%A)*'dimensions(sigma_sb)))^(1/4),
66 'dimensions(%T) = -'dimensions(%i)*('dimensions(E)/('dimensions(%A)*'dimensions(sigma_sb)))^(1/4),
67 'dimensions(%T) = ('dimensions(E)/('dimensions(%A)*'dimensions(sigma_sb)))^(1/4)];
69 foo_late : subst ([E = 7 ` kW, %A = 11 ` m^2, sigma_sb = 56697/10000/10^8 ` W/m^2/K^4], foo);
70 [%T = 1000*7^(1/4)*%i/623667^(1/4) ` K*kW^(1/4)/W^(1/4),
71 %T = (-1000*7^(1/4)/623667^(1/4)) ` K*kW^(1/4)/W^(1/4),
72 %T = (-1000*7^(1/4)*%i/623667^(1/4)) ` K*kW^(1/4)/W^(1/4),
73 %T = 1000*7^(1/4)/623667^(1/4) ` K*kW^(1/4)/W^(1/4)];
75 dimensions (foo_late);
76 ['dimensions(%T) = temperature,'dimensions(%T) = temperature,
77 'dimensions(%T) = temperature,'dimensions(%T) = temperature];
79 foo1_late : foo_late `` K;
80 [%T `` K = 7^(1/4)*1000^(5/4)*%i/623667^(1/4) ` K,
81 %T `` K = (-7^(1/4)*1000^(5/4)/623667^(1/4)) ` K,
82 %T `` K = (-7^(1/4)*1000^(5/4)*%i/623667^(1/4)) ` K,
83 %T `` K = 7^(1/4)*1000^(5/4)/623667^(1/4) ` K];
86 [%T `` K = 325.4890020542776*%i ` K,%T `` K = (-325.4890020542776) ` K,
87 %T `` K = (-325.4890020542776*%i) ` K,%T `` K = 325.4890020542776 ` K];
89 foo_early : dimensionally (solve (subst ([E = 7 ` kW, %A = 11 ` m^2, sigma_sb = 56697/10000/10^8 ` W/m^2/K^4], E = %A * %T^4 * sigma_sb), %T));
90 [%T = 1000*7^(1/4)*%i/623667^(1/4) ` K*kW^(1/4)/W^(1/4),
91 %T = (-1000*7^(1/4)/623667^(1/4)) ` K*kW^(1/4)/W^(1/4),
92 %T = (-1000*7^(1/4)*%i/623667^(1/4)) ` K*kW^(1/4)/W^(1/4),
93 %T = 1000*7^(1/4)/623667^(1/4) ` K*kW^(1/4)/W^(1/4)];
95 dimensions (foo_early);
96 ['dimensions(%T) = temperature,'dimensions(%T) = temperature,
97 'dimensions(%T) = temperature,'dimensions(%T) = temperature];
99 foo1_early : foo_early `` K;
100 [%T `` K = 7^(1/4)*1000^(5/4)*%i/623667^(1/4) ` K,
101 %T `` K = (-7^(1/4)*1000^(5/4)/623667^(1/4)) ` K,
102 %T `` K = (-7^(1/4)*1000^(5/4)*%i/623667^(1/4)) ` K,
103 %T `` K = 7^(1/4)*1000^(5/4)/623667^(1/4) ` K];
106 [%T `` K = 325.4890020542776*%i ` K,%T `` K = (-325.4890020542776) ` K,
107 %T `` K = (-325.4890020542776*%i) ` K,%T `` K = 325.4890020542776 ` K];
109 /* from mailing list 2018-12-06: "ezunits: strange multiplication behaviour?" */
111 (kill (x, dx, t, c1, c2, c3),
112 x : c1*t^2 + c2*t + c3,
117 declare ([c1, c2, c3], dimensional) $
120 eqns : [ev(x, t=t0`s) = x0`m, ev(x, t=5`s) = 5`m, ev(dx, t=t0`s) = 1`m/s];
121 [c1*(t0^2 ` s^2)+c2*(t0 ` s)+c3 = x0 ` m,
122 c3+(5 ` s)*c2+(25 ` s^2)*c1 = 5 ` m,
123 c1*(2*t0 ` s)+c2 = 1 ` m/s];
125 /* call ratsimp(foo - bar) to test for equivalence of foo and bar,
126 * since expected result doesn't match; that might or might not
127 * be a bug in simplification or grind or something.
129 (soln: dimensionally (solve (eqns, [c1, c2, c3])),
130 expected: [[c1 = (t0-x0)/(t0^2-10*t0+25) ` m/s^2,
131 c2 = (2*t0*x0-t0^2-10*t0+25)/(t0^2-10*t0+25) ` m/s,
132 c3 = (-((10*t0-25)*x0-10*t0^2+25*t0)/(t0^2-10*t0+25)) ` m]],
133 ratsimp (soln - expected));
134 [[0 = 0 ` m/s^2, 0 = 0 ` m/s, 0 = 0 ` m]];
136 ev (soln, t0=0, x0=0);
137 [[c1 = 0 ` m/s^2,c2 = 1 ` m/s,c3 = 0 ` m]];
139 eqns0 : subst ([t0 = 0, x0 = 0], eqns);
140 [c1*(0 ` s^2)+c2*(0 ` s)+c3 = 0 ` m,
141 c3+(5 ` s)*c2+(25 ` s^2)*c1 = 5 ` m,
142 c1*(0 ` s)+c2 = 1 ` m/s];
144 soln0: dimensionally (solve (eqns0, [c1, c2, c3]));
145 [[c1 = 0 ` m/s^2,c2 = 1 ` m/s,c3 = 0 ` m]];