MATLAB: The problem e ^x= ∑n=0 ∞ * x ^n\ n ! but this program didn’t work . it gives infinity error and I don’t know how to use it. invalid range and called from errors

invalid rangeMATLAB

function [S] = yanital(x,y)
T=0;
for n=0:inf
nf=1;
for i=1:n
nf=nf*i;
T=T(x^n/nf)
S=T;
endfor
endfor
endfunction

Best Answer

n = 20 ; % can be changed
x = pi ; % value of x
y = 0 ; % intilaize the required value
for i = 0:n
y = y+x^i/factorial(i) ;
end
[exp(x) y]
Related Question