Kirby Urner wrote:
Again, I think you're probably right, that this particular example is
perverse. Edu-sig is a scratch pad for bad ideas too. :-D
Sorry, Kirby, I see we all seemed to jump on top of you here.
--Scott David Daniels
[EMAIL PROTECTED]
S'ok.
From my point of view,
From: Kirby Urner [mailto:[EMAIL PROTECTED]
Now, if g(x) really *did* go on for 30-40 lines, OK, then maybe a
decorator
adds to readability.
Something to think about.
From
http://www.corante.com/many/archives/2005/03/09/one_world_two_maps_thoughts_
on_the_wikipedia_debate.php
When
Oops. meant to reply to all. Sorry.
On Wed, 30 Mar 2005 07:24:16 -0500, Lloyd Hugh Allen
[EMAIL PROTECTED] wrote:
I thought that there already were little black box libraries all over
the place. Just that most of them were in C etc.
On Wed, 30 Mar 2005 07:15:58 -0500, Arthur [EMAIL
From: Arthur [mailto:[EMAIL PROTECTED]
From: Lloyd Hugh Allen [mailto:[EMAIL PROTECTED]
To: Arthur
Subject: Re: RE: [Edu-sig] RE: Integration correction
I thought that there already were little black box libraries all over
the place. Just that most of them were in C etc.
Yes
Kirby got the trapezoidal integration rule wrong.
Right, I was just doing a simple average, not any trapezoid. My rectangles
took the mean between f(x-h) and f(x+h), nothing more. Not the best
approximation, I agree, but simple to think about, and some text books show
it.
This is the
Kirby got the trapezoidal integration rule wrong.
This is the corrected version.
def integrate(f,a,b,n=1000):
sum = 0
h = (b-a)/float(n)
for i in range(1,n):
sum += f(a+i*h)
return h*(0.5*f(a)+sum+0.5*f(b))
Here's the same thing using a generator expression
Here's my implementation of Simpson's, except it divides the interval into
2n segments.
def simpson(f,a,b,n):
h = float(b-a)/(2*n)
sum1 = sum(f(a + 2*k *h) for k in range(1,n))
sum2 = sum(f(a + (2*k-1)*h) for k in range(1,n+1))
return (h/3)*(f(a)+f(b)) +
From: Kirby Urner [EMAIL PROTECTED]
@simpson
def g(x): return x*x
g(0, 3)
9.0036
My resistance to decorators is not unrelated to the fact that I don't seem
capable of getting my mind around them.
I do find it quite disconcerting that the arguments g is expecting
cannot
[EMAIL PROTECTED] wrote:
From: Kirby Urner [EMAIL PROTECTED]
@simpson
def g(x): return x*x
g(0, 3)
9.0036
My resistance to decorators is not unrelated to the fact that I don't
seem capable of getting my mind around them.
I do find it quite disconcerting that the arguments g is
Kirby Urner wrote:
From: Kirby Urner [EMAIL PROTECTED]
[snip ... Kirby, Art and many others including myself discuss
the possible misuse of decorators in the context of calculating
derivatives and integrals numerically end snip]
Now, if g(x) really *did* go on for 30-40 lines, OK, then
Kirby Urner wrote:
Again, I think you're probably right, that this particular example is
perverse. Edu-sig is a scratch pad for bad ideas too. :-D
Sorry, Kirby, I see we all seemed to jump on top of you here.
--Scott David Daniels
[EMAIL PROTECTED]
___
11 matches
Mail list logo