[SciPy-user] optimize.bisect
Alan G Isaac
aisaac@american....
Mon Nov 10 08:54:40 CST 2008
>> On 11/10/2008 8:51 AM Nils Wagner apparently wrote:
>>> how can I use optimize.bisect if the function f is only
>>> given at discrete points instead of a continuous
>>> function
>>> like sin(x) ?
> On Mon, 10 Nov 2008 09:10:01 -0500 Alan G Isaac wrote:
>> Do you have the points ``x``?
>> Then shouldn't you just take
>> x[np.argmin(np.abs(f(x)))]?
On 11/10/2008 9:26 AM Nils Wagner apparently wrote:
> Your approach returns a single root.
> How do I extract successive zeros of a sampled signal ?
Ah, you had proposed a bisection algorithm, which will also
return a single zero...
I don't know a good answer to this new question,
but you could look at the diff of f(x)>0. This should
get you close:
>>> x = np.linspace(-1,1,21)
>>> def f(x): return x**2 - 0.5
...
>>> fd = np.diff( f(x)>0 )
>>> z = x[fd>0]
>>> z
array([-0.8, 0.7])
Cheers,
Alan
More information about the SciPy-user
mailing list