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: How to create a matrix with increasing power?
Replies: 9   Last Post: Feb 28, 2014 10:06 AM

Advanced Search

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

Posts: 1,995
Registered: 12/6/04
Re: How to create a matrix with increasing power?
Posted: Feb 21, 2014 5:03 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Sven " <svendotholcombe@gmaildot.com> wrote in message <le8g3t$7kg$1@newscl01ah.mathworks.com>...
> "Timothy Liang" <timothy.tliang@gmail.com> wrote in message <le8e48$1uu$1@newscl01ah.mathworks.com>...
> > I just started to learn how to use matlab... Just a simply question...
> >
> > Is there a simple way create a matrix like this?
> > x= 1, 2, 3, 4, 5
> >
> > matrix X=1^0 1^1 1^2 1^3
> > 2^0 2^1 2^2 2^3
> > 3...
> > 4...
> > 5...
> >
> > Thanks!!

>
> Yep, try this:
>
> bsxfun(@power, 0:5, (1:5)')
> ans =
>
> 0 1 2 3 4 5
> 0 1 4 9 16 25
> 0 1 8 27 64 125
> 0 1 16 81 256 625
> 0 1 32 243 1024 3125


I don't think this is what Timothy asked for.

If I understand the OP he wants a 4X5 matrix where given:

x = 1:5
y = 10^(0:3)

for ii = 1:length(x)
X(:,ii) = x(ii)*y;
end

I don't have MATLAB installed on this computer,
but the result should be:
X= [
1 1 2 3
1 2 4 8
1 3 9 27
1 4 16 64
1 5 25 125]

which is what I believe the OP asked for. (Maybe its transposed.)

I know there are more MATLAB efficient ways,
but Timothy did ask for a SIMPLE way.



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.