hello i have an iteration table for a maclaurin series, can anyone tell me what's the coding to make a table like this?

4 vues (au cours des 30 derniers jours)

Réponse acceptée

Ameer Hamza
Ameer Hamza le 16 Avr 2020
Modifié(e) : Ameer Hamza le 16 Avr 2020
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
  4 commentaires
Ramdit P
Ramdit P le 17 Avr 2020
i was wondering, you didn't input the coding for the formula of epsilon s. can you tell me why??
Ameer Hamza
Ameer Hamza le 17 Avr 2020
It was not on the table, so I didn't notice it. You can follow the same method to add it to the code.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by