Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Making a square matrix from two vector
Replies: 22   Last Post: Mar 19, 2013 12:37 AM

 Messages: [ Previous | Next ]
 james bejon Posts: 219 Registered: 3/13/10
Re: Making a square matrix from two vector
Posted: Feb 13, 2013 1:51 AM

"Steven_Lord" <slord@mathworks.com> wrote in message <kfdrs7\$rn\$1@newscl01ah.mathworks.com>...
>
>
> "james bejon" <jamesbejon@yahoo.co.uk> wrote in message
> news:kfdpbk\$kdo\$1@newscl01ah.mathworks.com...

> > Bruno--I really like this bsxops stuff, and have started using it in some
> > of my projects at work. In the process, I've realised something which (at
> > least in my view) is rather odd (though is nothing to do with your
> > functions), namely the result of:
> >
> > (1:10).' + 1:10
> >
> > % the right way: (1:10).' + (1:10)

>
> This is intentional behavior.
>
> http://www.mathworks.com/help/matlab/matlab_prog/operators.html#f0-38155
>
> Parentheses are at level 1 in the precedence order. Transpose is at level 2.
> Addition is at level 5. The colon operator is at level 6. Therefore this:
>
> (1:10).' + 1:10
>
> computes (1:10) first (level 1 and level 6 inside the parentheses), then
> transposes the result (level 2), then adds 1 to that result (level 5), then
> uses that vector as the first input to the colon operator (level 6.) That
> just takes the first element as documented on the reference page for COLON.
>
> http://www.mathworks.com/help/matlab/ref/colon.html
>
> "If you specify nonscalar arrays, MATLAB interprets j:i:k as
> j(1):i(1):k(1)."
>
> This also explains why your "the right way" resolves the problem; both sets
> of parentheses at level 1 are processed before the addition at level 5.
>
>
> This is also why -8^(1/3) gives -2 instead of (1+sqrt(3)*1i) as people
> expect and sometimes post about here; exponentiation [8^(1/3)] is at level 2
> while unary minus [- (8^(1/3))] is at level 3. (-8)^(1/3) gives the complex
>
> --
> Steve Lord
> slord@mathworks.com
> http://www.mathworks.com

Thanks for the explanation.

Date Subject Author
2/8/13 Jerry
2/8/13 Barry Shaw
2/8/13 dpb
2/8/13 james bejon
2/9/13 Bruno Luong
2/9/13 james bejon
2/9/13 Bruno Luong
2/12/13 james bejon
2/12/13 Steven Lord
2/12/13 Bruno Luong
2/12/13 dpb
2/12/13 Bruno Luong
2/12/13 dpb
2/13/13 Bruno Luong
2/13/13 dpb
2/14/13 Bruno Luong
2/14/13 dpb
2/14/13 Bruno Luong
2/14/13 dpb
2/14/13 dpb
2/13/13 james bejon
3/18/13 James
3/19/13 Bruno Luong