Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
james bejon

Posts: 213
Registered: 3/13/10
Re: Making a square matrix from two vector
Posted: Feb 13, 2013 1:51 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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
> answer.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com


Thanks for the explanation.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.