zero crossing
zero crossing
(OP)
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?
sin(x) where 7<x>6?
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS Come Join Us!Are you an
Engineering professional? Join Eng-Tips Forums!
*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting GuidelinesJobs |
|
RE: zero crossing
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
http://www.geocities.com/bstex2001
RE: zero crossing