Taylor series of log(x) with a = 1.
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
How to Write a Matlab function that sums up a specified number of terms from the Taylor series of log(x) with a = 1.
%I need my own sript.
%I tried this:
function s = etaylor_log(x, n)
syms x
s = taylor(log(x), 'ExpansionPoint', 1, 'Order', n+1)
end
% It does not give values.
% The second :
function s = etaylor_log(x, n)
for i=1:n;
y(i) = (x-1).^(i-1)*(x-1).^i/i;
end
s=sum(y);
% it does not show for n=0.
3 Commenti
Walter Roberson
il 4 Set 2019
When n is 0 then for i=1:n will not execute at all, so you will not create the variable y
Risposte (1)
Kritika Bansal
il 13 Set 2019
Hi,
Taking the analogy from the expression returned by the following command:
taylor(log(x), x, 'ExpansionPoint', 1, 'Order', n);
You can design your script as follows:
function s = etaylor_log(x, n)
if n==0
error("The value of order can only be a positive integer i.e. n>0");
end
if n == 1
s = 0;
return;
end
for i=1:n-1
y(i) = ((x-1).^(i)*(-1).^(i-1))/i;
end
s=sum(y);
end
Hope this helps!
0 Commenti
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!