![](https://secure.gravatar.com/avatar/612395b66b3e7959997007b342b3688a.jpg?s=120&d=mm&r=g)
Hi all, how can I use optimize.bisect if the function f is only given at discrete points instead of a continuous function like sin(x) ? Cheers, Nils
![](https://secure.gravatar.com/avatar/39916bae984cb93b797efd2b175f59c0.jpg?s=120&d=mm&r=g)
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) ?
Do you have the points ``x``? Then shouldn't you just take x[np.argmin(np.abs(f(x)))]? What is the point of using an algorithm designed for continuous functions? Alan Isaac
![](https://secure.gravatar.com/avatar/612395b66b3e7959997007b342b3688a.jpg?s=120&d=mm&r=g)
On Mon, 10 Nov 2008 09:10:01 -0500 Alan G Isaac <aisaac@american.edu> wrote:
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) ?
Do you have the points ``x``? Then shouldn't you just take x[np.argmin(np.abs(f(x)))]? What is the point of using an algorithm designed for continuous functions?
Alan Isaac
Hi Alan, Thank you very much. I have overlooked your approach. Nils
![](https://secure.gravatar.com/avatar/612395b66b3e7959997007b342b3688a.jpg?s=120&d=mm&r=g)
On Mon, 10 Nov 2008 09:10:01 -0500 Alan G Isaac <aisaac@american.edu> wrote:
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) ?
Do you have the points ``x``? Then shouldn't you just take x[np.argmin(np.abs(f(x)))]?
Your approach returns a single root. How do I extract successive zeros of a sampled signal ? Nils
![](https://secure.gravatar.com/avatar/39916bae984cb93b797efd2b175f59c0.jpg?s=120&d=mm&r=g)
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
participants (2)
-
Alan G Isaac
-
Nils Wagner