Find zeros of numeric function

31 views (last 30 days)
KostasK on 29 Nov 2019
Commented: ME on 29 Nov 2019
Hi all,
I have a numeric function which for the sake of simplicity resembles the following:
x = linspace(1:100) ;
y = sin(x) ;
I would like to know if there is a function in matlab where it returns the zeros of the above (presumably based on the sign change of adjacent elements).
EDIT: The function as I say above is numeric, hence cannot be analitically expressed (i.e. sin cosing or whatever) as it is shown in my example. I used the above example just to create to numeric vectors.

Accepted Answer

ME on 29 Nov 2019
You could use fzero for this. Only issue is that it returns the zero closest to a chosen start point, therefore I've put a loop in to find multiple zeros. Maybe somebody could show a more elegant way?
fun = @sin;
for i=1:numel(x)
ME on 29 Nov 2019
Well then you could look at the below if you essentially just want to find the sign changes

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by