MATLAB Question 1 Given a vector x write a script to create

MATLAB


 


Question 1.


Given a vector x, write a script to create a vector v, which consists of the indices of all the


elements in vector are greater than 3.


 


Question 2.


The sum of geometric series is written as


1 + 1/2+1/4+1/8+1/16+ …..


Write a function to find the sum of the geometric series, which receive the number of term as


input argument


Solution

1.)

MATLAB CODE :

d=length(x);

v=zeros(1,d);

n=0;

for k=1:d

if(x(k)>3)

   n=n+1;

v(n)=k;

   end

end

v=v(1:n)

2.)

code for sum of geometric series:

MATLAB CODE :

sum=0;

for k=1:n

sum=sum+(1/2)^(k-1);

end

sum

MATLAB Question 1. Given a vector x, write a script to create a vector v, which consists of the indices of all the elements in vector x are greater than 3. Ques
MATLAB Question 1. Given a vector x, write a script to create a vector v, which consists of the indices of all the elements in vector x are greater than 3. Ques

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site