Vectorized exponentiation

爱⌒轻易说出口 提交于 2019-12-02 04:02:00

Use bsxfun:

bsxfun(@power, X, N)

This assumes that X is a column vector and N is a row vector. If you want to guarantee that, use the following syntax which is more robust:

bsxfun(@power, X(:), N(:).')

This is probably a bit sloppier than the bsxfun answer, but you could use meshgrid:

E = X.^(meshgrid(N)')

This assumes both X and N are row vectors. If both are column vectors then it becomes:

E = X.^(meshgrid(N))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!