I am trying to write a program that estimates the derivative of a polynominal and determines the error. So far my code is
% The code for Problem 3.
a=54*x^2+3*x^32*x^4+x^5; % ask for a function to be differentiated
x=input('Enter the value x at which to find the derivative '); % ask for input
dh=.5;
for i=1:dh:100% do the loop
dh=.5*(1/2)^i; % step size
df=((54.*(x+dh).^2+3.*(x+dh).^32.*(x+dh).^4+(x+dh).^5)(54*x^2+3*x^32*x^4+x^5))/dh; % centered difference approximation
if 1+dh==1
break
else
dh=dh/2;
end
end
error=(8*x+9*x^28*x^3+5*x^4)df;
disp(df)
disp(error)
The result is two numbers that are correct but the df is switched with error and vise versa. Does anyone know what I am doing wrong
