i was asked to develop a program that will evaluate a function for -0.9<x<0.9 in steps of 0.1 by arithmetic statement, and series allowing as many as 50 terms. however, end adding terms when the last term only affects the 6th significant in answer

4 次查看(过去 30 天)
the function and its series expansion is
f(x)=(1+x^2)^(-1/2)=1-1/2*(x^2)+(1*3)/(2*4)*(x^4)-(1*3*5)/(2*4*6)*(x^6)+...-....

回答(2 个)

Youssef  Khmou
Youssef Khmou 2014-11-2
Developing Taylor requires to compute the derivative :
x=-.9:.1:.9;
f=1./sqrt(1+x.^2);
g=1-1/2*(x.^2)+(1*3)/(2*4)*(x.^4)-(1*3*5)/(2*4*6)*(x.^6);
plot(x,g,x,f,'+r')

Roger Stafford
Roger Stafford 2014-11-2
You can use a for-loop with a 'break' to generate successive terms and their sum. For each value of x you are required to use, get the corresponding f with
f = 1;
t = 1;
for k = 1:50
t = -(2*k-1)/(2*k)*x^2*t; % Iteratively compute successive terms
f = f + t; % Update the sum of the series
% Exit the for-loop when the current term, t, is too small
if abs(t) < ????
break
end
end

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by