I'm trying to make a taylor series expression for e^x = sum(x^n/n!) for n=0:50 and for x^n/n!>0.01 So far I have this:
function [ xs ] = myExpfunction(x)xs=zeros(1,length(x));xl=zeros(51,1); %preallocation of the storage
for n= 1:50 if ((x.^n)/factorial(n))>0.01 xl(n+1,:) = ((x.^n)/factorial(n)); %save every iteration result
endendfor ii = 1:length(x) xs(ii)=1+sum(xl(:,ii)) ; %calculate the sum of the iteration results
endend
I get and error:
??? Subscripted assignment dimension mismatch.Error in ==> myExpfuntion at 6 xl(n+1,:) = ((x.^n)/factorial(n)); %save every iteration result
Im trying to get a result of for example x=[1,2,3,4] into xs=[2.7083 7.3810 20.0797 54.5940]. Thank you in advance for the help 🙂
Best Answer