MATLAB: How to solve for multiple roots

infiniteroots

Hello, I am trying to solve the first 500 roots of the following equation tan (x)= (3x)/(3+(60.5*(x^2)) But I cannot figure out how to do it. Any help will be appreciated.

Best Answer

The first 500 roots? Why 500? Are there 500 such roots?
By the way, I think you need to learn to use fewer parens.
f = @(x) tan(x) - 3*x./(3+60.5*x.^2);
One root clearly lies at x == 0. In fact, quick examination suggests that n*pi is a good approximation to all non-negative roots.
f(pi*(0:10))
ans =
0 -0.015705 -0.0078821 -0.0052584 -0.0039448 -0.0031562 -0.0026303 -0.0022546 -0.0019728 -0.0017537 -0.0015783
So just use a loop, calling fzero for each starting value n*pi.
xn = zeros(1,11);
for n = 1:10;
xn(n+1) = fzero(f,n*pi);
end
xn
xn =
Columns 1 through 7
0 3.15721947602233 6.29105738669815 9.43003337009966 12.570314108792 15.7111187818028 18.8521858417768
Columns 8 through 11
21.9934029606895 25.134713911635 28.2760874364729 31.4175047721421
ezplot(f,[0,35])
hold on
refline(0,0)
plot(xn,0,'ro')