Find zeros of numeric function

조회 수: 33 (최근 30일)
KostasK
KostasK 2019년 11월 29일
댓글: ME 2019년 11월 29일
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).
KR,
KMT.
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.

채택된 답변

ME
ME 2019년 11월 29일
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;
x=linspace(1,100);
for i=1:numel(x)
x0(i)=fzero(fun,x(i));
end
x0=unique(x0)
  댓글 수: 2
KostasK
KostasK 2019년 11월 29일
Yes, this could be one way that it can be done. However in this case i have a numeric function not an analytic one. So I only have two vectors of numbers essentially. I will edit my question to clarify this better.
ME
ME 2019년 11월 29일
Well then you could look at the below if you essentially just want to find the sign changes

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by