kalen
23 Oct 2007, 07:46pm
I'm supposed to be writing some code in matlab that will allow me to solve the Taylor series of e^x to a minimum term value of M.
The taylor series is
e^x= 1 + x/1! + x^2/2! +.....
I've been using matlabs help and google for about 6 hours trying to figure this out.
x=input('You are computing e^x, what number is x?');
d=input('What degree of accuracy would you like?');
c=0;
for b=0:1:1100
while b/(x^b/factorial(b))>1
c=c+((x^b)/factorial(b));
end
disp(sum(c))
end
I thought that this would cause it to set c as 0. Then run integers in order (1,2,3..) until it reached an answer that was less than the specified d value. Then it would stop and display the total of those values.
This isn't working and I can't figure out what I'm doing wrong.
Help, Please!
The taylor series is
e^x= 1 + x/1! + x^2/2! +.....
I've been using matlabs help and google for about 6 hours trying to figure this out.
x=input('You are computing e^x, what number is x?');
d=input('What degree of accuracy would you like?');
c=0;
for b=0:1:1100
while b/(x^b/factorial(b))>1
c=c+((x^b)/factorial(b));
end
disp(sum(c))
end
I thought that this would cause it to set c as 0. Then run integers in order (1,2,3..) until it reached an answer that was less than the specified d value. Then it would stop and display the total of those values.
This isn't working and I can't figure out what I'm doing wrong.
Help, Please!