
Solving trigonometric equation problem
26 views (last 30 days)
Show older comments
Hello I couldn't solve this equation on Matlab.Can anyone help me?
I want to find at least 6 roots.I'm trying to find frequency of beam.
(sin(x)-sinh(x))*(-x*sin(x)-x*sinh(x))-(cos(x)-cosh(x))*(x*cos(x)-x*cosh(x))=0
Same one is below.

2 Comments
Image Analyst
on 2 May 2020
x = linspace(-45, 45, 20000);
y = (sin(x)-sinh(x)).*(-x.*sin(x)-x.*sinh(x))-(cos(x)-cosh(x)).*(x.*cos(x)-x.*cosh(x))
plot(x, y, 'b-');
grid on;

Answers (1)
Ameer Hamza
on 3 May 2020
Edited: Ameer Hamza
on 3 May 2020
There is no direct way to find all the roots of such an equation. It is quite complicated, so solve() isn't able to find a closed-form expression (it might not exist since wolfram alpha also didn't return any). So your only option is to use a numerical solver like fsolve(). However, the output of fsolve() depends on the initial guess. We need to use some heuristics based on your function values to handle the problem of finding the initial guesses.
If we start by simply plotting you function over some range, it is not obvious how can we proceed
f = @(x) (sin(x)-sinh(x)).*(-x.*sin(x)-x.*sinh(x))-(cos(x)-cosh(x)).*(x.*cos(x)-x.*cosh(x));
x = linspace(0, 35, 10000);
plot(x,f(x))

However, the first step for finding the root of an equation is to find the zero-crossing points. So we can use sign() function to do that.

Each edge corresponds to a zero. As you can see, there are more than 6 roots for your equation.
Now we find the x-values at these zero-crossing points by taking the average of left and right x-values at the zero-crossing.
f = @(x) (sin(x)-sinh(x)).*(-x.*sin(x)-x.*sinh(x))-(cos(x)-cosh(x)).*(x.*cos(x)-x.*cosh(x));
x = linspace(0, 35, 10000);
ys = sign(f(x));
idx = find(diff(ys)); % find index of zero corssing points
x_zeros_left = x(idx); % left x-values at zero crossing points
x_zeros_right = x(idx+1); % right x-values at zero crossing points
x_zeros = (x_zeros_left+x_zeros_right)/2; % average x-values at zero crossing points
x_zeros = x_zeros(1:6); % select first 6 values to find out 6 roots
and then we write a for-loop and use these points as a starting guess for fsolve()
x_roots = zeros(1,6);
for i=1:6
x_roots(i) = fsolve(f, x_zeros(i));
end
To check if the roots we found are correct, check the function values at points in x_roots
for i=1:6
fprintf('Value of f(x) at x=%8.5f is %8.5f\n', x_roots(i), f(x_roots(i)));
end
Result
Value of f(x) at x= 0.00175 is -0.00000
Value of f(x) at x= 4.73004 is 0.00000
Value of f(x) at x= 7.85320 is -0.00000
Value of f(x) at x=10.99561 is 0.00000
Value of f(x) at x=14.13717 is 0.00000
Value of f(x) at x=17.27876 is 0.00000
2 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!