USING MATLAB ONLY PLEASE COMMENT CODE Write an Mfile Using

USING MATLAB ONLY - PLEASE COMMENT CODE

Write an M-file.

Using the for loop structure write a program to calculate terms of the geometric series with a = 1 and r = 0.5. Set format long.

The program will prompt the user to enter a value for n and then calculate the harmonic series from i = 1 to n. Now run your program for n = 1, 3, 10, 50, and 100. You must use the for loop structure.

******************

With pen, paper and calculator calculate the harmonic series for n = 1 and 3 and compare it with the results of your program.

The geometric series is defined as follows 2 This series is convergent if and divergent otherwise Write an M-file Using the tor loop structure write a program to calculate terms of the geometric serieS with a 1 and 0.5. Set format long. The program will prompt the user to enter a value for n and then calculate the harmonic series from i = 1 to n. Now run your program for n = 1, 3, 10, 50, and 100, You must use the forloop structure

Solution

Code:format long %defining the values
a = 1;
r = 0.5;
n = input(\'Enter the n upper bound : \'); %taking the input from the user
s = 0;
for i=1:n
s = s + a*r.^(n-1); %calculating the summation
end

Output:

Enter the n upper bound : 1

s = 1


Enter the n upper bound : 3

s = 0.750000000000000


Enter the n upper bound : 10

s = 0.019531250000000

Enter the n upper bound : 50

s = 8.881784197001252e-14

Enter the n upper bound : 100

s = 1.577721810442024e-28

USING MATLAB ONLY - PLEASE COMMENT CODE Write an M-file. Using the for loop structure write a program to calculate terms of the geometric series with a = 1 and

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site