MATLAB: Hello i have an iteration table for a maclaurin series, can anyone tell me what’s the coding to make a table like this

maclaurin

Best Answer

There are several ways to calculate a series in MATLAB. From your question, you appear to be a beginner, so I will show an intuitive way using for-loop.
term_n = @(x,n) x^n./factorial(n); % formula for n-th term of series
N = 10; % total number of terms we are going to calculate
result = zeros(1,N+1); % initializng a array to save the partial sums
eplison_t = zeros(1,N+1);
eplison_a = zeros(1,N+1);
x = 1/2; % value of x to use in this calculation
result(1) = term_n(x,0); % calculate first term of the series at n=0
eplison_t(1) = (exp(x) - result(1))/exp(x);
for n=1:N % terms n=1,2,...,N
result(n+1) = result(n) + term_n(x,n); % current partial sum is the addition of last partial sum and the value of n-th term
eplison_t(n+1) = (exp(x) - result(n+1))/exp(x);
eplison_a(n+1) = (result(n+1)-result(n))/result(n+1);
end
eplison_t = 100*eplison_t;
eplison_a = 100*eplison_a;
t = table(result', eplison_t', eplison_a');
disp(t)
Result
>> test_fun
Var1 Var2 Var3
______ __________ __________
1 39.347 0
1.5 9.0204 33.333
1.625 1.4388 7.6923
1.6458 0.17516 1.2658
1.6484 0.017212 0.15798
1.6487 0.0014165 0.015795
1.6487 0.00010024 0.0013163
1.6487 6.2197e-06 9.4018e-05
1.6487 3.4355e-07 5.8761e-06
1.6487 1.7097e-08 3.2645e-07
1.6487 7.741e-10 1.6323e-08