Series (Help)

I have a function which is integral of(bounds are from minus infinity to x) e^((-0.5)*t^2)/sqrt(2*pi) dt.

Its Taylor Series is: 0.5+[1/sqrt(2*pi)*(x+(-0.5)*x^3/1!*1/3+(-0.5)^2*x^5/2!*1/5+...+(-0.5)^25*x^51/25!*1/51+...

I need to write a function that keeps counting the series until the sum doesn't change...

I have written this code:

function fx=f(x)
clear all
clc
format long
x=input('Enter a value to expand around:');
fx=(1/sqrt(2*pi))*exp(-0.5*x.^2)
k=0;
term=x;
sum=0;
while (fx~=sum)
fx=sum;
k=k+1
term=term*(-0.5)*x^2/k*(2*k-1)/(2*k+1)
sum=sum+term
end
Fix=0.5+(sum/sqrt(2*pi))
exact_solution=0.5+0.5*erf(x/sqrt(2))
end

But I cannot get accurate solution. What is the problem with my code???
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories