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

1 Ansicht (letzte 30 Tage)
Jessie Bessel
Jessie Bessel am 23 Okt. 2017
Beantwortet: KSSV am 24 Okt. 2017
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 Kommentar
John D'Errico
John D'Errico am 24 Okt. 2017
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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KSSV am 24 Okt. 2017
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]) ;


Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by