Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

zero crossing

Status
Not open for further replies.

Guest
How do I compute the zero crossing of one function given two values. Ex a value where zero crossing occurs for
sin(x) where 7<x>6?
 
Replies continue below

Recommended for you

Hi,
This is a simple solution for you:
--------------------------------------------------
function [x0,XTOL]=zercros(F,LLIM,ULIM,XTOL,YTOL)
TOL=(ULIM-LLIM)*XTOL;
n=0;
J=[];
while isempty(J) & n<100
x=linspace(LLIM,ULIM,round(1/TOL));
y=eval([F '(x)']);
ay=abs(y); % absolute value
J=find(ay<YTOL);
TOL=TOL/2;
n=n+1;
end
dy=diff(y); % derivative
J1=find(dy(J)); % nonzero derivatives at detected points
x0=x(J(J1));
XTOL=TOL/((ULIM-LLIM);
______________________________
Note that this method may give you less zero crossings than exists because it designed to find at least one or give up after 100 iterations. If you find that XTOL have changed, you better run it again with a twice value of the resulted XTOL to find if there are other solutions in the region.
Usually you will get for each zero crossing to values of x0, one just before and the second just after it.

Joe
BSTEX - Equation viewer for Matlab
 
Thanks for the help, it was very usefull.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor