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

MATLAB Using for loop or while loop write a code (script file named sc3 or sc34

ID: 3718985 • Letter: M

Question

MATLAB

Using for loop or while loop write a code (script file named sc3or sc34if you use it for both problems 3 and 4) to find the summation S.

S = 1+ 1/2 + 1/2^2 + 1/2^3 + 1/2^4 +... 1/2^n

       Write down the numerical value of S for                                   

        n = 2,              S= …………

        n = 3,              S= …………

        n = 5,              S= ………

        n = 10 ,           S= …………

       when n goes to infinity, what will be the value of S?

        n = infinity,            S= …………

Explanation / Answer

for i=1:10
S=1;
for j=1:i
S = S + 1/2^j;
end
if j==2 || j==3 || j==5 || j==10
disp(S);
end
end

//output

for n=2 then s = 1.7500

for n=3 then s = 1.8750

for n=5 then s = 1.9688

for n=10 then s = 1.9990

//IF it goes to infinity it will say that it is invaid range