Incompatable array calculation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Incompatable array calculation

Miftahur Rahman
<http://octave.1599824.n4.nabble.com/file/t372913/Screenshot_from_2018-07-10_15-46-36.png>

I have started learning Octave today.
In my attached photo, variale b is an 1x3 array and c is an 3x1 array.
Addition or subtraction of this to variable is not possible. Instead of
error message, i am getting answer which is a 3x3 matrix. what is the
problem?



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Incompatable array calculation

jbect
Le 10/07/2018 à 09:57, Miftahur Rahman a écrit :
<http://octave.1599824.n4.nabble.com/file/t372913/Screenshot_from_2018-07-10_15-46-36.png> 

I have started learning Octave today. 
In my attached photo, variale b is an 1x3 array and c is an 3x1 array.
Addition or subtraction of this to variable is not possible. Instead of
error message, i am getting answer which is a 3x3 matrix. what is the
problem?

There is no problem, this behaviour is called "broadcasting" :

https://octave.org/doc/v4.4.0/Broadcasting.html

@++
Julien



Reply | Threaded
Open this post in threaded view
|

Re: Incompatable array calculation

Sergei Steshenko


On Tuesday, July 10, 2018, 5:45:10 PM GMT+3, Julien Bect <[hidden email]> wrote:


Le 10/07/2018 à 09:57, Miftahur Rahman a écrit :
<http://octave.1599824.n4.nabble.com/file/t372913/Screenshot_from_2018-07-10_15-46-36.png> 

I have started learning Octave today. 
In my attached photo, variale b is an 1x3 array and c is an 3x1 array.
Addition or subtraction of this to variable is not possible. Instead of
error message, i am getting answer which is a 3x3 matrix. what is the
problem?

There is no problem, this behaviour is called "broadcasting" :

https://octave.org/doc/v4.4.0/Broadcasting.html

@++
Julien


This is horrible bug causing a lot of trouble.

--Sergei.


Reply | Threaded
Open this post in threaded view
|

Re: Incompatable array calculation

Przemek Klosowski-7
On 07/10/2018 10:51 AM, Sergei Steshenko wrote:
There is no problem, this behaviour is called "broadcasting" :

https://octave.org/doc/v4.4.0/Broadcasting.html

.. which is a logical extension of a behavior that existed in Matlab language from the beginning:  2*[1,2,3] being evaluated to [2 4 6]
This is horrible bug causing a lot of trouble.
I could see it might be puzzling if you don't know about this behavior, or let it happen accidentally---but it is also very useful when used on purpose.
There's no point in complaining about it, though, provided there's a reliable way to print a warning for (1:2) + (1:2)'.

Having said that, I thought I remembered warning('on','Octave:broadcast') but it didn't do anything.
warning('on','Octave:language-extension')  warns about automatic broadcast---is that the recommended way? I don't remember what else it warns about.

octave:8>octave:8> (1:2) + (1:2)'
warning: performing `operator +' automatic broadcasting
ans =

   2   3
   3   4
 



Reply | Threaded
Open this post in threaded view
|

Re: Incompatable array calculation

Sergei Steshenko


On Tuesday, July 10, 2018, 8:34:22 PM GMT+3, Przemek Klosowski <[hidden email]> wrote:


On 07/10/2018 10:51 AM, Sergei Steshenko wrote:
There is no problem, this behaviour is called "broadcasting" :

https://octave.org/doc/v4.4.0/Broadcasting.html

.. which is a logical extension of a behavior that existed in Matlab language from the beginning:  2*[1,2,3] being evaluated to [2 4 6]
This is horrible bug causing a lot of trouble.
I could see it might be puzzling if you don't know about this behavior, or let it happen accidentally---but it is also very useful when used on purpose.
There's no point in complaining about it, though, provided there's a reliable way to print a warning for (1:2) + (1:2)'.

Having said that, I thought I remembered warning('on','Octave:broadcast') but it didn't do anything.
warning('on','Octave:language-extension')  warns about automatic broadcast---is that the recommended way? I don't remember what else it warns about.

octave:8>octave:8> (1:2) + (1:2)'
warning: performing `operator +' automatic broadcasting


ans =


   2   3
   3   4

 
Your reply is self-contradictory.

I never needed this automatic broadcasting. I'm still using octave-3.6.4, and in ti I can't turn the warning into error.

It's a horrible bug.

--Sergei.