How to calculate "sqrt (a^2 + b^2 + c^2) " with only one "expr" object ?

Cheng Chien-Wen's icon

I would like to know the way to use "pow" in "expr" object. The help file of pow is not clear about its use. For example, if I need to calculate "sqrt (a^2 + b^2 + c^2) ", how should I write it with "expr" object ?

Please help. Thanks.

Christopher Dobrian's icon
Max Patch
Copy patch and select New From Clipboard in Max.
$Adam's icon

A small comment: for your specific case probably

expr sqrt ( $f1*$f1 + $f2*$f2 + $f3*$f3 )

is the most efficient way to go.

Roman Thilenius's icon

expr pow($f/,2) shoudl also work, but its longer. :)

Peter Castine's icon

pow($f1 , 2) will work, but it's much more CPU-intensive than $f1*$f1. D'uh. Mind you, compared to the overhead of message-passing between objects the difference between pow() and multiplication is not worth losing sleep over.

Rule of thumb #1: if one mathematical operation is harder for you to carry out, it's almost always more CPU intensive for the computer. Since pow() is a general-purpose exponentiation that can handle exponents with fractional components, it has to take logarithms and all that sort of junior high school math stuff. Multiplication--even long multiplication--is something that you mastered (or ought to have mastered;-) in elementary school.

Rule of thumb #2: don't worry much about this in Max unless you're noticing real performance issues.

Christopher Dobrian's icon

Adam and Peter are correct that in the simple case of squaring a number $f1*$f1 is more efficient than pow($f1, 2). (I was in didactic mode, paying more attention to your question regarding 'the way to use "pow" in "expr" object.')