I try to find all the roots of the function f=(x^3)*cos(x)
between -6pi and 6pi using fzero
.
I create a function:
function y3=f(x)
f=(x^3)*cos(x);
end
% Then at the command window:
syms x;
fun=@f
x1=-6*pi;
x2=-5*pi;
r=zeros(1,12);
for i=1:12
x=fzero(@fun,[x1 x2]);
r(i)=x;
x1=x1+pi;
x2=x2+pi;
end
I got this error:
Error: "fun" was previously used as a variable, conflicting with its use here as the name of a function
or command. See "How MATLAB Recognizes Command Syntax" in the MATLAB documentation for details.
How can I solve it? Thank you