How can I set values going up by powers of $2$ in matlab

54 Views Asked by At

I am writing a code which will need values of $\sin(x)$ for $x = 2^2, 2^3, 2^4, \dots, 2^{25}$

Being fairly new at matlab still, I am unsure how to do this in the most efficient manner.

I know

n=0:10
0 1 2 3 4 5 6 7 8 9 10

But putting in something like

n = 2^2:2^x:2^25

Doesn't make sense, so what would be another way I could do this?

I suppose I could let

x=3:24

But where would I proceed for there?

1

There are 1 best solutions below

3
On BEST ANSWER

The following script should work fine:

% Initiate the loop, i.e., the power of 2, from n=2 to n=25
for n = 2:25

    % Find the value of 2 raised to the power of n where n ranges from 2 to 25
    x = 2^n;

    % Evaluate the value of sin at x and store it in an array y (row vector)
    y(n) = sin(x); 
end

Let me know if you have any problems.