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: David Bateman
Subject: Re: Are scalars precomputed when multiplied with or added to vectors?
Date: Wed, 12 Mar 2008 16:25:25 +0100
User-agent: Thunderbird 2.0.0.12 (X11/20080306)

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.

D.

-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



reply via email to

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