Problem 4: Infinite Series 15pt] Given the following function 2n 1 nse0 using a while loop with a convergence criteria of 10 create a program which solves for theta. Test your program with a arccot(0.267). b) Now instead of calculating one point at a time, add a for loop to calculate 0 in the range -0.99 s x s 0.99 with an increment of 0.01. Store the results in a matrix y(x). Plot the graph of 0 vs x. Add axis labels (add figure to the report). c) Comment on your graph. Is it what you expected?
x=pi/2; %test: cot(pi/2)=1;
error=1;
n=1;
count=0;
while error >= 1*(10^-3);
%x -x^3/3! +x^5/5! ...
count=count+1;
terms(count)=(-1)^(count+1)*(x^n)/factorial(n);
cotx=sum(terms);
n=n+2;
error=abs((cot(x)-cotx)/cot(x))*100;
end
disp(cotx)
b)
output