Write a function file that determines the following sum for
Write a function file that determines the following sum (for all odd n from 1 to 11) using a for loop. The starting point, ending point, and increment should be input to the function file. Y = sigma 2^n + 2/n - 2 Repeat number 3 using a while loop. In Matlab. Please give me the codes for all the questions ASAP, thanks a lot.
Solution
%%%Code For question 3:%%%
clc
clear all
y = 0;
for n = 1:11
if mod(n,2)~=0 %% mod denotes reminder obtained by division of number by 2 if it is non zero n is odd
x = (2^(n+2)/(n-2));
end
y=y+x;
end
y
%%% Code for question 4%%%
clc
clear all
y = 0;
n=11;
while n > 1
n = n-1
if mod(n,2)~=0
x = (2^(n+2)/(n-2));
end
y=y+x;
end
y
