Finding all roots of nonlinear function

10 views (last 30 days)
Hmm! on 4 Mar 2021
How would I find all the roots of the function
I know all sine functions have multiple roots and so this function may also have multiple roots but how would I find all these roots? Using matlab fzero which uses the brackect criteria for the existence of solution only gives one root to the function.
So plotting the function might help but I think I have problems understanding what the graph is telling me. Can someone help to interpret the graph for me? How would I know the root(s) of the function? Atleast, I know one root is 0.25957 using fzero.
fplot( @(x) sin(10*x)-2*x, [-.5,.5])
%ploting the function with interval [-5, 5]
grid on

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 4 Mar 2021
Read the help for the fzero function and you will see that it returns a solution, not all. It accepts a range for x0 that restricts the region where it searches for the solution. Use that to work in a systematic way.
Bjorn Gustavsson
Bjorn Gustavsson on 8 Mar 2021
Yes, possibly. If you specify a region with 2 components then the function needs to have different signs at the 2 end-points, if you select regions snuggly around a zero you will get that root. If you have an odd number of solutions in that region you will get one of them, I don't know which that will be in a general case.
You an also draw three additional lines in your plot:
fplot( @(x) sin(10*x)-2*x, [-2,2])
%ploting the function with interval [-5, 5]
grid on
hold on
fplot(@(x) -2*x+1,[-2 2])
fplot(@(x) -2*x-1,[-2 2])
fplot(@(x) sin(10*x+sqrt(2))-2*x,[-2 2])
From those three curves you can also conclude that this function only has those 3 zeros.
@John D'Errico: If you help me then maybe we can make it a technical term! (From my name and lack of spelling skills you must have guessed that "the language of the Bard" is not my native tounge - but I derive great joy from cobbling up terms that you natives find quirky...)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!