MATLAB: How to find the roots of the Equation

roots of transdental equation

I was trying to find the roots of the equation
tan(x/2)+tanh(x/2)=0.
Can anybody help me in finding the roots.

Best Answer

This question gets asked so often, that it must be part of a homework or something.
fplot(@(x) tan(x/2)+tanh(x/2),[-10,10])
grid
yline(0);
untitled.jpg
There are infinitely many real roots. You can see three of them in the figure. They will surely not have any simple algebraic form you can write down. There may be complex roots, in fact, that is entirely possible. You could investigate that behavior by plotting things very carefully in the complex plane. How?
Hr = fcontour(@(xr,xi) real(tan((xr + i*xi)/2)+tanh((xr + i*xi)/2)),[-10,10,-10,10]);
Hr.LevelList = 0;
Hr.LineColor = 'b';
hold on
Hi = fcontour(@(xr,xi) imag(tan((xr + i*xi)/2)+tanh((xr + i*xi)/2)),[-10,10,-10,10]);
Hi.LevelList = 0;
Hi.LineColor = 'r';
grid
untitled.jpg
So it appears there are solutions in the complex plane. However, they exist only when x is purely real, OR purely imaginary. Those solutions lie at the intersections of the red and blue curves as I have plotted them. It appears that no solutions exist with simultaneously non-zero real and imaginary parts. With some effort, you could probably prove that claim, but it hardly seems worth the effort.
Actually finding any of the solutions for real or imaginary x will involve nothing more than use of a root finder, suze as fzero or vpasolve. Again, the solution that you find will depend on the start point or the starting interval. Here are three arbitrarily found real solutions.
syms x
vpasolve(tan(x/2)+tanh(x/2),x)
ans =
0
vpasolve(tan(x/2)+tanh(x/2),x,5)
ans =
4.730040744862704026024048100833884819898
vpasolve(tan(x/2)+tanh(x/2),x,12)
ans =
10.99560783800167090666903251910589241754
I seem to recall, from the last time I answered this question, that the roots approach a periodic behavior for large or small x. There will be some multiple of pi involved as I recall. This too can surely be shown, with some effort that may not be worth the effort invested for what is surely a homework assignment.