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 views (last 30 days)
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)+...-....

Answers (2)

Youssef  Khmou
Youssef Khmou on 2 Nov 2014
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 on 2 Nov 2014
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

Community Treasure Hunt

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

Start Hunting!