pad - mathematica: PadRight[] and \[PlusMinus] -
is there way
padright[a \[plusminus] b,2,""]
returns
{a \[plusminus] b,""}
instead of
\[plusminus] b \[plusminus] ""
?
i believe need somehow deactivate operator properties of [plusminus].
why need this?
i'm creating program display tables physical quantities. me, means tables entries (value of a) [plusminus] (uncertainty of a)
when have several columns different heights, i'm stuffing shorter ones "", can use transpose
numeric part of table.
if column has more 1 entrie, there's no problem:
padright[{a \[plusminus] b,c \[plusminus] d},4,""]
gives want:
{a \[plusminus] b,c \[plusminus] d,"",""}
it when column has 1 entrie problem appears.
this code constructs body stuffed "":
if[tested[sbody],1, body = padright[body, {length[a], max[map[length, body]]
with
tested[a__] := if[length[deleteduplicates[map[dimensions, {a}]]] != 1, false, true];
, function discovers if arguments have same dimension
and
a={quantity1,quantity2,...}
where quantities one's want on table.
thanks
first need aware of expression in mathematica in form of head[body] body may empty, single expression or sequence of expressions separated commas length operate on expressions, not lists length[plusminus[a,b]] returns 2 since body of expression contains expressions (atoms in case) , b
read documentation on padright. second argument define final length of expression padright[{a,b},4,c] results list of length 4 last 2 elements equal padright[{a,b},2,c] results original list since of length 2 therefore padright[plusminus[a,b],2,anything] returns same plusminus[a,b] unchanged since of length 2 so, youר first example wrong. not able result head list using padright when try pad expression head plusminus
there no problem of executing padright[plusminus[a,b],3,""] result looks funny (at best) , logically meaningless, if wanted in first place it, , following explanations above can figure out why
hth
best
yehuda
Comments
Post a Comment