syms xf = x^5;fprintf('Taylor series of x^5 \n');N = input('Enter the number of terms in the expansion: ');a = input('Enter the value of a to expand around taylor expansion: ');approx = 0;for n=0:N-1 approx = approx + (1-a)^n * diff(f,n) / factorial(n); endfprintf('\n')fprintf('Taylor series approximation = %.7g \n',approx)fprintf('actual value = %.7g \n',x^5);fprintf('error = %.3g \n',approx-x^5);
MATLAB: Error using fprintf Unable to convert ‘sym’ value to ‘double’. Error in Untitled (line 14) fprintf(‘Taylor series approximation = %.7g \n’,approx)
symbolicSymbolic Math Toolboxtaylor expansion
Best Answer