how to write a very concise expression for matrix power

I have a row vector, e.g. [1,2,3,4], and I want to put, say 3 different power [1;2;3] to create a matrix as follow:
[1,2,3,4]?^[1;2;3] = [1,2,3,4 ; 1,4,9,16 ; 1,8,27,64].
Anyone knows how to get it without using a loop. Many thanks!

 채택된 답변

Matt J
Matt J 2016년 10월 12일
As of R2016b, you can just do this
[1;2;3] .^ [1,2,3,4]
Otherwise, use bsxfun()

댓글 수: 4

Xin
Xin 2016년 10월 12일
편집: Xin 2016년 10월 12일
Ahh, I am using 2011, didn't know it works in 2016.
Thanks for reply. Is there any other way to let it work.
Matt J
Matt J 2016년 10월 12일
편집: Matt J 2016년 10월 12일
Upgrade!
Or, use bsxfun() as I suggested.
Nice, bsxfun does work. Thank you so much!
Then please ACCEPT the answer...

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

dpb
dpb 2016년 10월 12일
>> bsxfun(@power,[1:4],[1:3].')
ans =
1 2 3 4
1 4 9 16
1 8 27 64
>>

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

질문:

Xin
2016년 10월 12일

댓글:

dpb
2016년 10월 12일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by