Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a script file that creates a row vector v containing all the powers of 2 b

ID: 3109115 • Letter: W

Question

Write a script file that creates a row vector v containing all the powers of 2 below 1000. The output

vector should have the form: v = [ 2; 4; 8; 16 : : : ]. Use a while loop

use mat lab

% Initiate variables.

power = ??;

k = ??; % initiate counter

% Initiate vector V of powers of 2.

V = ??;

% Compute powers of 2 and store in V.

while ?? < ?? % specify condition of while-loop: stop iterating once

% condition is no longer satisfied

power = ??; % compute next value of power at each iteration

V = ??; % concatenate vector V with new element at each iteration

k = ??; % increment counter k

end

% Display vector V.

<code>

Explanation / Answer

clc;
clear all;
close all;
format short
n=1;
while (2^n < 1000)
v(n)=2^n;
n=n+1;
end
v

output:

v =

2 4 8 16 32 64 128 256 512

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote