help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Are scalars precomputed when multiplied with or added to vectors?


From: Olaf Till
Subject: Re: Are scalars precomputed when multiplied with or added to vectors?
Date: Thu, 13 Mar 2008 07:53:57 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

On Wed, Mar 12, 2008 at 04:25:25PM +0100, David Bateman wrote:
> Olaf Till wrote:
> > If x and y are vectors and all other variables are scalars, e.g. in
> >
> > octave:1> y = sqrt (x.^2 * a^2 + sqrt ((a + b)^2 + c * d)) + c + d;
> >
> > will all scalar subexpressions
> >
> > (i.e.: a^2, sqrt ((a + b)^2 + c * d), c + d)
> >
> > be computed by Octave only once for the operations on all components
> > of x, or is it worth explicitly precomputing them?
> >
> >   
> Given the precedence of the above the answer is yes for a^2 and
> sqrt((a+b)^2+c*d). However for c + d the answer is less clear.. I
> believe that the binop will treat this as two scalar/matrix additions
> rather than a scalar/scalar addition and then a matrix/scalar addition..
> Put parenthesis around c+d to ensure what you want.
> 

Thanks, this spares a lot effort.

Olaf


reply via email to

[Prev in Thread] Current Thread [Next in Thread]