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

Write a function to compute the sum of the series S1 given as: S1=1-1/2+1/3-1/4+

ID: 3851346 • Letter: W

Question

Write a function to compute the sum of the series S1 given as: S1=1-1/2+1/3-1/4+1/5-1/6+1/7-1/8+1/9-1/10..........±1/N

where, N is an odd positive integer; for the last term take (+) if N is odd and (-) if N is even The function should have one input N and one output S1. Make use of for_loop and if_statement. Name your function as LastName_FirstName_1. In the command window, test your function for N= 25 and N =125. Copy and paste the command window results into

your function as comments.
Hint: You may need to make use of mod function available in Matlab

Explanation / Answer


function y = LastName_FirstName_1(x)
res=0
a=1
% 25 : res = 0.71275
% 125 : res = 0.69713
for c = 2:x
  
if mod(c,2)==0
res = a+res-1/c
a=0
end
if mod(c,2)!=0
res=res+1/c
  
end
  
disp(res);

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote