Currently doing revision for a MATLAB module next year. Was attempting a question and was hoping for some help it.
I am asked to consider this Taylor series expansion:
S(x,n)=(x-1) – 1/2(x-1)^2 + 1/3(x-1)^3 – 1/4(x-1)^4 +…+ ((-1)^(n-1))*(1/n)*(x-1)^n
From this write a matlab function that, given the values of x and a tolerance e, returns the value of k such that the absolute value of the k-th term of the taylor series expansion is less or equal than e.
The issue is with the script i have made:
function S = taylor()
clear all
clc
tol=1e-5 x = input('Select value of x = '); S = 0; m = input('Select value of n = ');
for n = 1:m S = S + ((-1) ^ (n-1)) .* (((x – 1) .^ n)./n); end
disp(' ') fprintf('S(x,n) = %8.4f\n' ,S)
end
As I am a beginner to MATLAB I have no idea how to include a tolerance in the calculation. I am also wondering how I can find the kth term of the series with an absolute value of less or equal e(tolerance).
Just to inform you I the value of e is 10e-5
Thank you in advance for your time
Best Answer