0
$\begingroup$

I have defined a variable called y, this contains a huge equation, but when I look for the dimension of y it shows 3. How come a single expression has dimensions of 3? It is supposed to be 1 right?

y=39.25 ω^2 (1.00519 Subscript[a,4][1]^2+1.00102 Subscript[a,4][2]^2+2.19056 Subscript[a,4][1] Subscript[a,4][3]-1.07645 Subscript[a,4][2] Subscript[a,4][3]+1.5 Subscript[a,4][3]^2+0.55507 Subscript[a,4][1] Subscript[a,4][4]+1.54742 Subscript[a,4][2] Subscript[a,4][4]+1.5 Subscript[a,4][4]^2);;
Dimensions[y]
$\endgroup$
6
  • $\begingroup$ Well, it is a product of three things. A one-dimensional list, of three elements. $\endgroup$ Jan 10, 2020 at 13:56
  • $\begingroup$ Dimensions needs a full array as argument (see documentation) . If you apply it to a scalar surprising results like Dimension[a+b] (* 2*) occur. $\endgroup$ Jan 10, 2020 at 14:00
  • $\begingroup$ It is a single expression right. Is it possible to make one expression with dimension 1 $\endgroup$
    – acoustics
    Jan 10, 2020 at 14:00
  • $\begingroup$ Yes, something like {a +b} $\endgroup$ Jan 10, 2020 at 14:05
  • 1
    $\begingroup$ Perhaps you would be interested in LeafCount which gives the total number of indivisible subexpressions. In this case, 78 $\endgroup$
    – Bob Hanlon
    Jan 10, 2020 at 15:53

2 Answers 2

2
$\begingroup$

Maybe what you are looking for is LeafCount. TreeForm is also useful for visualizing expressions.

TreeForm @ y

enter image description here

$\endgroup$
1
$\begingroup$

From the point of view of tensor analysis, a scalar has no dimensions at all. You can make your own function that reflects this:

arrayDimensions[x_?ArrayQ] := Dimensions[x]
arrayDimensions[x_] := {}
arrayDimensions[{1, 2}]
(* {2} *)
arrayDimensions[a + b]
(* {} *}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.