MATLAB question Use for loops or nested for loops to evaluat
MATLAB question:
Use for loops or nested for loops to evaluate the series.
Sigma^10_m = 0 Sigma^10_n = 0 1/3^m + n Set the answer to p2c. Sigma^20_m = 0 Sigma^m_n = 0 1/3^m + n Set the answer to p2d.Solution
%%Create a matlab file with name anything like, \'forloops.m\'
%% c)
%%Set p2c=0
p2c=0;
%%run m value from 0 to 10
for m=0:10
%%run n value from 0 to 10
for n=0:10
%%add values p2c
p2c=p2c+(1/3^(m+n));
end
end
%%print p2c to console
disp(\'Resulst,p2c = \',p2c);
%% d)
p2d=0;
%%run m value from 0 to 10
for m=0:20
%%run n value from 0 to m
for n=0:m
%%add values to p2d
p2d=p2d+(1/3^(m+n));
end
end
%5print p2d to console
disp(\'Resulst,p2d = \',p2d);
------------------------------------------------------------------------------------------------------------------------------------
Run the file forloops from the command prompt or press F5
Sample Output:
Resulst,p2c =
2.2500
Resulst,p2d =
1.6875

