You are adding it wrong... I can't remember whether Matlab has a built-in function for factorial. If not, you need to implement it yourself. Shouldn't be that difficult.
Actually x^1/1! is not always equal to 1. If it is wrong, you may need to do it differently as...
Let see if this is what should be like...
sum = 1;
temp = -1;
for i = 2:2:n %with step 2
sum += temp * ((x^i)/fact(i));
temp = -temp;
end
PS: Your code starts the value of "i" with 1 and step up 2, so the values used in the function are 1, 3, 5, ...
PSS: The value "n" in your function is still unclear to me. Is it the maximum it should go or it is else?
Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239