How to generate the first twenty powers of x?

后端 未结 4 746
感情败类
感情败类 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:13

    Use power. It raises something to the power of y, and repeats if y is a vector.

    power(x,1:300)
    

    edit: power and .^ operator are equivalent.

提交回复
热议问题