How to generate the first twenty powers of x?

后端 未结 4 750
感情败类
感情败类 2021-01-28 18:42

So, I\'ve got X, a 300-by-1 vector and I\'d like [1, X, X*X, X*X*X, ... , X*X*...*X], a 300-by-twenty matrix.

How should I do this?

X=[2;1]
[X,X.*X,X.*X         


        
4条回答
  •  滥情空心
    2021-01-28 19:10

    The element-wise power operator .^ should do what you need:

    x .^ (1:20)
    

    (assuming x is a column vector.)

提交回复
热议问题