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

조회 수: 1 (최근 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