Trying to learn matlab (Taylor Series)
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.
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.
[FONT=Courier New][SIZE=2]x=input([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#a020f0]'You are computing e^x, what number is x?'[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT] [SIZE=2][FONT=Courier New]d=input([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#a020f0]'What degree of accuracy would you like?'[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT] [SIZE=2][FONT=Courier New]c=0;[/FONT][/SIZE] [FONT=Courier New][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] b=0:1:1100[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] b/(x^b/factorial(b))>1 [/SIZE][/FONT] [SIZE=2][FONT=Courier New]c=c+((x^b)/factorial(b));[/FONT][/SIZE] [FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]disp(sum(c))[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/COLOR][/SIZE][/FONT]
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!
0
Comments
Questions:
What are the variables 'b', 'c', and 'd' supposed to do? You take 'd' as an input but never use it for anything.
You talk about M but what is M in terms of the code you created?
-drasnor
-drasnor
moved to matlab help subforum
Seeing your code really helped me understand how to approach it.
Thanks again.