help-octave
[Top][All Lists]
Advanced

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

Re: Use of bsxfun


From: Juan Pablo Carbajal
Subject: Re: Use of bsxfun
Date: Thu, 22 Sep 2011 14:30:31 +0200

On Thu, Sep 22, 2011 at 2:18 PM, Bård Skaflestad
<address@hidden> wrote:
> On Thu, 2011-09-22 at 10:00 +0200, Juan Pablo Carbajal wrote:
>> Not long ago JordiGH show me how to exploit the use of bsxfun. However
>> I am having troubles using it
>> Shouldn't the output of this call
>>
>> > bsxfun (@ (x,y) x * y, [1 -1; 2 -2], [6 6; 3 3])
>>
>> be [6 -6; 6 -6] and not [3 3; 6 6]? (The latter is what I get)
>
> Your example demonstrates a slight deficiency in the BSXFUN interface.
> To quote from the help text (in Octave 3.2.3, it may have changed in
> later releases):
>
>        Loadable Function:  bsxfun (F, A, B)
>        Applies a binary function F element-wise to two matrix arguments
>        A and B. ...
>
> In this respect, your expectation ([6, -6; 6, -6]) is reasonable.
> However, as the inputs 'A' and 'B' are (square) matrices, you are
> effectively calling
>
>        bsxfun(@mtimes, A, B)
>
> which reduces to 'A * B' (i.e., ordinary matrix multiplication).  If you
> want to apply element-by-element multiplication, you should be using
> 'array multiply', i.e., the @times function or spelled equivalently
>
>        @(x,y) x.*y
>
> I can't really decide if calling BSXFUN with @MTIMES should be an error
> or not.  There are good arguments for both sides.
>
>
> Sincerely,
> --
> Bård Skaflestad <address@hidden>
> SINTEF ICT, Applied Mathematics
>
>

Thank you very much Bárd,

I think it would be a good idea to put this example in the help text.
It is a built-in function so I cannot do it. Who should I contact?

-- 
M. Sc. Juan Pablo Carbajal
-----
PhD Student
University of Zürich
http://ailab.ifi.uzh.ch/carbajal/


reply via email to

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