MATLAB: How to calculate the derivative of function that is referred to in another function

derivativeMATLAB

I am attempting to derivate a function to use in my Newton's method function.
My function code appears as follows:
function y = func(x)
y =-2.18 +5.0768*x-2.6870*(x^2)+0.5129*(x^3)-0.0318*(x^4);
end
My Newton Raphson code appears as follows:
function xr = NewtonRaphson(xs,tol,maxit)
syms x
dfunc = diff(func,x);
However, I get an error when I run this code. Any help is appreciated. Thank you.

Best Answer

syms x
func =-2.18 +5.0768*x-2.6870*(x^2)+0.5129*(x^3)-0.0318*(x^4);
dfunc = diff(func,x);