Finalizing my Code for taylor series, gets error
Mostra commenti meno recenti
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
end
end
for ii = 1:length(x)
xs(ii)=1+sum(xl(:,ii)) ; %calculate the sum of the iteration results
end
end
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 :)
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!