# finding all roots of a trignometric equation

7 ビュー (過去 30 日間)
pooja sudha 2020 年 12 月 30 日
コメント済み: Ameer Hamza 2020 年 12 月 31 日
Can we find all roots of a trignometric equation using matlab?
for e.g., tan(x)-x=0.

サインインしてコメントする。

### 回答 (2 件)

Ameer Hamza 2020 年 12 月 30 日
range of tan(x) is (-inf inf), so this equation has an infinite number of solutions. Also, the solutions to this equation cannot be represented analytically. There is no general way to find multiple solutions to such equations. One solution is to start the numerical solver with several starting points and choose unique values. For example
eq = @(x) tan(x)-x;
x_range = 0:0.1:20;
sols = ones(size(x_range));
for i = 1:numel(sols)
sols(i) = fsolve(eq, x_range(i));
end
sols = uniquetol(sols, 1e-2);
##### 2 件のコメントなしを表示なしを非表示
Walter Roberson 2020 年 12 月 30 日
The solutions to tan(x)-x tend towards being close to 2*pi apart, so it is possible to generate reasonable starting points for as many points as desired until you start losing too much floating point precision.
However, you will never have enough memory to return them "all".
Ameer Hamza 2020 年 12 月 31 日
Yes, thats a good observation to give the initial points. The solutions are pi apart from each. Following will also give same result as one in the answer.
eq = @(x) tan(x)-x;
x_range = 0.1:pi:20;
sols = ones(size(x_range));
for i = 1:numel(sols)
sols(i) = fsolve(eq, x_range(i));
end

サインインしてコメントする。

Image Analyst 2020 年 12 月 30 日
Well here's one way. Use fminbnd() to find out where the equation is closest to zero:
x = linspace(-1, 1, 1000);
y = tan(x);
plot(x, x, 'b-', 'LineWidth', 2);
hold on;
plot(x, y, 'r-', 'LineWidth', 2);
grid on;
axis equal
% Use fminbnd() to find where d = 0, which is where tan(x) = x.
xIntersection = fminbnd(@myFunc, -1.5,1.5)
% Put a line there
xline(xIntersection, 'Color', 'g', 'LineWidth', 3);
caption = sprintf('xIntersection = %f', xIntersection);
title(caption, 'FontSize', 20)
function d = myFunc(x)
d = abs(tan(x) - x);
end
You get
xIntersection =
-1.66533453693773e-16

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by