How can i find with a simpe and easy code the zero crossing of a function?

2 ビュー (過去 30 日間)
Jessie Bessel
Jessie Bessel 2017 年 10 月 23 日
回答済み: KSSV 2017 年 10 月 24 日
Let's say that I have a sinus wave and i want to find and plot the zero crossing for that function.How can i do that, with a simple code?
  1 件のコメント
John D'Errico
John D'Errico 2017 年 10 月 24 日
Why not read the help for fzero? You might even find an example in there, rather than asking someone to re-write the documentation for fzero.
doc fzero


回答 (1 件)

KSSV 2017 年 10 月 24 日
t = linspace(0,2*pi,5000) ;
y = sin(t) ;
hold on
plot(t,y) ;
%%get zeros
tol = 10^-3 ;
idx = abs(y-0)<=tol ;
plot(t(idx),y(idx),'*r') ;
%%using fzero
fun = @sin ;
x = fzero(fun,[0 2*pi]) ;


Community Treasure Hunt

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

Start Hunting!

Translated by