## Maclaurin Series function in matlab

### mohamed (view profile)

on 17 May 2013

e^x=1+x+((x^2)/2!)+((x^3)/3!)+((x^4)/4!)+......

• Implement a MATLAB function that compute e^x using this formula *(Stop when ((epson)a) is below than an error criterion confirming to five significant figures)
• You must display your result , the final value of error you reached and the number of terms taken

i dont have a problem with the real solving but when it comes to matlab im noob :(

## Products

No products are associated with this question.

### mohamed (view profile)

on 17 May 2013
```function Maclaurin
n=5;
x=input('enter the x value: ')
epsilon_s=(0.5*10^(2-n))
epsilon=100
maclaurin(1)=1
iteration=1
while epsilon>epsilon_s
iteration=iteration+1
maclaurin(iteration)=maclaurin(iteration-1)+(x)^(iteration-1)+x^(2+(iteration-1))/factorial(2+(iteration-1))
epsilon=abs((maclaurin(iteration)-maclaurin(iteration-1))/maclaurin(iteration))
end
disp(['number of iterations= ',num2str(iteration)])
disp(['epsilon= ',num2str(epsilon)])
```

### mohamed (view profile)

on 17 May 2013

my problem is: the first iteration its gives me 1 2nd iteration gives me 1.5208 but its should be 1.5 please someone help me :(

### Iman Ansari (view profile)

on 17 May 2013
```function Maclaurin
n=5;
x=input('enter the x value: ');
epsilon_s=(0.5*10^(2-n));
epsilon=100;
maclaurin(1)=1;
iteration=1;
while epsilon>epsilon_s
iteration=iteration+1;
maclaurin(iteration)=maclaurin(iteration-1)+(x)^(iteration-1)/factorial(iteration-1);
epsilon=abs((maclaurin(iteration)-maclaurin(iteration-1))/maclaurin(iteration));
end
disp(['e^' num2str(x) ' = ' num2str(maclaurin(iteration))])
disp(['number of iterations= ',num2str(iteration)])
disp(['epsilon= ',num2str(epsilon)])
```