Calculating element-wise powers using vectors in MATLAB

76 Views Asked by At

I'm trying to calculate the following using vectors:

The goal is to have a vector that looks as follows:

\begin{align} y &= \begin{bmatrix} 10^1 \\ 10^2 \\ \vdots \\ 10^k \end{bmatrix} \end{align}

Where k=50.

I'm quite new to MATLAB so I thought about doing the following: \begin{align} k &= \begin{bmatrix} 1 & 2 & \dots & k \end{bmatrix} \end{align}

\begin{align} n &= \begin{bmatrix} 10 \\ 10 \\ \vdots \\ 10 \end{bmatrix} \end{align}

The MATLAB code to compute the answer would then be:

n = ones(20, 1)*10

k = 1:20

y = n.^k

But that code doesn't seem to perform element-wise power as I expected. If anyone has any suggestions as to how I could go about doing this without having to use any for loops that would be much appreciated.

1

There are 1 best solutions below

1
On
n = 10.^[1:50]

Hope to help you