I've created this code to calculate roots by using Newtons Method. However I only need the first 10 roots that I find with this code. I think I have to create a 10×1 matrix and populate it with the results that are not repeated. I have no idea how to do that… Any ideas? Thanks!!
syms f(x) xf(x) = x*tan(x)-0.1; %Function
g = diff(f);for e=1:100 %Trying different initial guesses to get all the roots
x(1)=e ;%initial guess
for i=1:1000 %it should be stopped when tolerance is reached
x(i+1) = x(i) - f(x(i))/g(x(i));%Newtons Method
if( abs(f(x(i+1)))<0.001) % tolerance
disp(double(x(i+1))); %Display result
break; end endend
Best Answer