Clear Filters
Clear Filters

How to find the roots along a real line?

3 views (last 30 days)
KT on 23 Sep 2020
Commented: KT on 25 Sep 2020
Hi guys,
I am trying to determine the first 5 eigen frequencies of a bending beam with rotational and translational spring supports. This is done by setting the determinant of the coefficient matrix equal to zero. I use vpasolve to solve the equation, as I am solving a syms variable. The first 5 values I show get are: (found using Maple)
But when I try solving this in matlab I get the following output:
Can someone tell me why matlab does not find the 0.0659 value?
Is there a Matlab function to find the roots along a real line? My code is not very efficient due to the fact that I must first figure out in what range the first 5 eigen values lay before I can use the function I made. My code is attached.
Any advice would be appreciated!

Accepted Answer

Dana on 23 Sep 2020
Numerical solvers are not guaranteed to find all roots of an expression. That's what's happening here. The algorithm vpasolve is using doesn't "notice" the root near 0.0659. If your start/end range bracketed that value, it would find it however:
>> vpasolve(freq,B, [.99,1.01]*0.0659)
ans =
Unless you can find a way to bracket each root like this, you'll never be 100% sure to catch all of them. One option to increase the likelihood of finding every root is to start with a small bracket, then gradually increase the upper bound until you find a root, then shift your bracket over. So for example, if you instead make your FindBeta function something like:
function Bet = FindBeta(FrequencyEquation, StartAt, EndAt, NumberOfBetas)
Bet = zeros(NumberOfBetas,1);
syms B
incStrt = 1e-9; % increment from previous root to start search for next root
incEnd = 1e-2; % increment to add to upper bound of search range each time
StrtRg = StartAt; % initial lower bound of search range
for i = 1:NumberOfBetas
EndRg = StrtRg + incEnd; % set initial upper bound of search range
NoRoot = true; % = true when we still haven't found the i-th root
while NoRoot
% try to get a root:
Beti = vpasolve(FrequencyEquation,B, [StrtRg; EndRg]);
if isempty(Beti) % if we didn't find a root
if EndRg > EndAt % if we've already exceeded EndAt
Beti = NaN; % indicate no such root exists using NaN
NoRoot = false; % stop searching
EndRg = EndRg + incEnd; % increase upper bound of search range
% and then try again
else % if we found a root
if Beti > EndRg % if the root exceeds EndAt
Beti = NaN; % indicate no such root exists using NaN
NoRoot = false; % flag that a root has been found
if isnan(Beti) % if the upper bound has been exceeded
Bet(i:end) = NaN; % set all remaining roots to NaN
return; % and then exit function
else % otherwise
Bet(i) = Beti; % store found root
StrtRg = Beti + incStrt; % increase the start range and repeat
Beta =
The parameter incEnd is a key one that must be tuned somehow. Smaller values make it more likely that you'll find all the roots, but at the cost of increasing the amount of time it takes to do so.
  1 Comment
KT on 25 Sep 2020
Hi Dana!
Thank so much for the reply! This really help!

Sign in to comment.

More Answers (0)


Find more on Creating and Concatenating Matrices in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!