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

(1) Write Matlab scripts to calculate the sum of the following series. You need

ID: 3010355 • Letter: #

Question

(1)
Write Matlab scripts to calculate the sum of the following series. You need to make use of for and while loops to solve this problem. No use Matlab builtin function is allowed. You need to use three forms of loop statement: for, while(condition, and while(1) or infinite loop. That means each of (a) and (b) will have three variants.

11 + 21 + 31 + ......................................... + 191

9 + 12 + 15 + 18................................................... 35 Terms

(2)
Write Matlab scripts to determine the sum of the following series using both while and for loops.

2+5+11+23+47+ ........................ 30terms

Hints: 2 1;

(3)

Write a user defined Matlab function that will take an array X as the input and will return the range (defined by the minima and maxima) and the average value X. Note that the range is a vector, that is rangeX=[minx, maxx] Test your function with [2, 6, 7, 9, 3, 1, 10].
Do not use any builtin function. You are allowed to use the KEYWORDS only.

Explanation / Answer

1. a> 11 + 21 + 31 + ......................................... + 191

the above series is in an AP (Arithmetic progression)

the nth term is = An = a+(n-1)d

a=first term , n = the nth term and d = common difference

=> An = 11+(n-1)10 = (10n + 1)

now we'll find the range for n

first term = 11 = 10n+1 ,=> n = 1

last term = 191 = 10n+1 , => 19

hence n E [ 1 , 19 ]

now the code

% We initialize our sum
s = 0;
% We are going to get the first 19 terms,
% one-by-one in our sequence
for n = 1 : 19
    % This is the shown formula for our arithmetic sequence
    pn = 10*n + 1
    % We add-up every term in the series
    s = s + pn;
end

% We display the sum of the series
s

b>

9 + 12 + 15 + 18................................................... 35 Terms

the nth term is An = a+(n-1)d = 9+(n-1)3 = 3n + 6

the matlab code is :

% We initialize our sum
s = 0;
% We are going to get the first 35 terms,
% one-by-one in our sequence
for n = 1 : 35
    % This is the shown formula for odd numbers
    tn = 3*n+6
    % We add-up every term in the series
    s = s + tn;
end

% We display the sum of the series
s