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: Integrating bsxfun in a for-loop
Replies: 1   Last Post: Feb 23, 2014 5:02 PM

Advanced Search

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

Posts: 1,983
Registered: 12/6/04
Re: Integrating bsxfun in a for-loop
Posted: Feb 23, 2014 5:02 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Timothy Liang" <timothy.tliang@gmail.com> wrote in message <leb9qk$qn0$1@newscl01ah.mathworks.com>...
> Hi,
>
> I am trying to integrate bsxfun into a loop... but it turned out to be unsuccessful...
>
> i=1:10000
> x=i/10000
> for q=0:20
> X=bsxfun(@power,x',q);
> [Q,R]=qr(X)
> ...
> end
>
> What I want was that as q increase, the matrix would be
> for q=0
> X=x1^0
> x2^0
> x3^0
> ...
>
> then for q=1
> X=x1^0 x1^1
> x2^0 x2^1
> x3^0 x3^1
>
> for q=2
> X=x1^0 x1^1 x1^2
> x2^0 x2^1 x2^2
> x3^0 x3^1 x3^2
> and so on...
>
> However, the result of my codes was Xs are always 10000by1 column matrices, where the first matrix is x^0, second one x^1...
> How do I fix this? Thanks in advance!!!!


You are overwriting X each time thru your for loop.
You need to modify the above code to something like:

i=1:10000
x=i/10000
maxq = 21
X = zeros(maxq,length(x)) % preallocatefor efficiency
for q=1:maxq
X(q,:)=bsxfun(@power,x',(q-1));
[Q,R]=qr(X)
...
end




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.