Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Maclaurin Series function in matlab

Asked by mohamed 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

please help i have to hand this out tomorrow :(

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

0 Comments

mohamed

Products

No products are associated with this question.

3 Answers

Answer by mohamed 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)])

0 Comments

mohamed
Answer by mohamed 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 :(

0 Comments

mohamed
Answer by Iman Ansari 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)])

0 Comments

Iman Ansari

Contact us