How do i find roots for a trignometric function? eg (0.1*x)+10*tan(0.1*x)

2 views (last 30 days)
The function roots does not work for this equation ?

Accepted Answer

Star Strider
Star Strider on 9 Oct 2015
Use the fzero function to get real roots. Plot it first, since it likely has several, and the initial estimate of the roots will reveal different values:
eqn = @(x) (0.1*x)+10*tan(0.1*x);
rt = fzero(eqn, 10)
rt =
15.7080
  4 Comments
Star Strider
Star Strider on 9 Oct 2015
You don’t plot it with a for loop, you use the plot to estimate the initial guesses for the parameter. If those initial guesses are for instance 0, 15, 30, ... (that seem appropriate here), you would write the loop as:
X0 = [0:15:15*4];
for k1 = 1:length(X0)
rt(k1) = fzero(eqn, X0(k1));
end
x = linspace(1, 100);
figure(1)
plot(x, eqn(x))
hold on
plot(rt, zeros(size(rt)), 'or')
hold off
grid
Here, I plotted the function afterwards to demonstrate that it detected and estimated the first five positive zeros. The ‘rt’ vector has their locations.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!