Sadly I'm having trouble with ezunits and plotting again. This time in combination with if-clause. This works, but probably not as it should:
/*just works*/
M_K1q(n):= if n <= 500 then 0
else (n-500)^2/20000;
wxdraw2d(explicit(qty(M_K1q(n)), n, 0, 1500));
/*kinda works*/
M_L(n):= (10+n/100`minute)`N*m; /*doesn't*/
M_L(n):= (10+(n`minute)/100)`N*m; /*doesn't*/
M_L(n):= (10`N*m)+n/100`N*m*minute; /*works*/
wxdraw2d(explicit(qty(M_L(n)), n, 0, 1500));
/*but both work that way*/
M_L(n):= (10+n/100`minute)`N*m;
M_L(n):= (10+(n`minute)/100)`N*m;
wxdraw2d(explicit(qty(qty(M_L(n))), n, 0, 1500));
But with units I cannot plot it, have tried many variations of it:
M_K1(n):= block(
(if qty(n) <= 500 then 0
else ((n`minute)-500)^2/20000)`N*m
);
M_K1(99`1/minute); /*works*/
wxdraw2d(explicit(qty(M_K1(n)), n, 450, 600)); /*doesn't*/
Input n
should be in 1/minute
and output should be N*m
.
Looks like qty()
isn't working properly, since the units weren't removed completely:
draw2d (explicit): non defined variable in term: 5.0*10^-5*((realpart(501.7241379310345 ` minute)-500.0)^2-1.0*imagpart(501.7241379310345 ` minute)^2)
-- an error. To debug this try: debugmode(true);
2022-05-29 EDIT:
Yes, using qty() would require entering n
in 1/minute
, which would be an acceptable workaround, if graphs and solving would work.
Damn it, I tried so many versions.
That's the one with no unit at the 0
because it's "global":
M_K1(n):= (if n <= 500`1/minute then 0
else (n`minute-500)^2/20000)`N*m;
Shouldn't the last one also work?
(%i102) M_K1(1000`1/minute);
(%o102) 25/2 ` N*m
(%i108) M_K1(2.5`1/s);
(%o108) 0 ` N*m
(%i111) M_K1((1000/60)`1/s)``N*m;
(%o111) (50/3 ` minute/s-500)^2/20000 ` N*m
Drawing graphs with that takes a minute or two and then crashes:
(%i24) wxdraw2d(explicit(qty(M_K1(n)), n, 450, 600));
draw2d (explicit): non defined variable in term:
realpart(if 455.1724137931034<=500.0 ` 1/minute then 0.0 else 5.0*10^-5*(455.1724137931034 ` minute-500.0)^2)
-- an error. To debug this try: debugmode(true);
Shouldn't it work though?
It looks correct, but using your:
M_K2(n):=if n <= 500 ` 1/minute then 0 ` N*m
else (n-500 ` 1/minute)^2/(45000 ` 1/(kg*m^2));
I get:
(%i40) M_K2(1000`1/minute)``N*m;
(%o40) 1/648 ` N*m
That's not right!
(%i78) M_K2(n):= if n <= 500`1/minute then 0`N*m
else (n`minute-500)^2/45000`N*m;
(%o78) M_K2(n):=if n<=500 ` 1/minute then 0 ` N*m else (n ` minute-500)^2/45000 ` N*m
(%i79) M_K2(1000`1/minute);
(%o79) 50/9 ` N*m
That's more like it.
Also, it should be solvable:
(%i69) res: dimensionally(solve(M_K2(n) = 10`N*m, n)); n_K2P2: rhs(res[1])``1/minute; float(%);
(%o67) [(if n<=500 ` 1/minute then 0 ` N*m else (n^2 ` N*m*minute^2+(-1000*n) ` N*m*minute+250000 ` N*m)/45000)=10 ` N*m]
(%o68) (600*kg*m^2)/s ` 1/minute
(%o69) (600.0*kg*m^2)/s ` 1/minute
Should look like this:
(%i86) res: dimensionally(solve(M_K2(n) = 10`N*m, n)); n_K2P2: rhs(res[2])``1/minute; float(%);
(%o84) [n=(500-12*5^(5/2)) ` 1/minute,n=(12*5^(5/2)+500) ` 1/minute]
(%o85) (12*5^(5/2)+500) ` 1/minute
(%o86) 1170.820393249937 ` 1/minute
If I get one thing working, another one breaks. Looks like one edge-case after the next.