### Email Archive: pyx-user (read-only)

 Re: [PyX-user] Simpson's Rule From: Stefan Schenk - 2008-07-18 05:04 Hi Dan Am Donnerstag 17 Juli 2008 20:07 schrieb Dan Reinholz: [...] > The problem is that when I run it I get the error: > > bsd% python simpsons_rule.py > Traceback (most recent call last): > File "simpsons_rule.py", line 27, in > g.plot(graph.data.function("y(x)=g(x)", > context=locals(), points=500)) > AttributeError: 'function' object has no attribute > 'plot' > > Can anybody shed some light on the problem? Ok, let's look at the code. You have > g = graph.graphxy(width=8, > x=axis.linear(min=0, max=intl, title="$x$"), > y=axis.linear(title="$\sin(x) + x$")) and also > for i in range(0, nsubintl): > def g(x): > if x0+i*w0 <= x <= x0+(i+1)*w0: return > (f(x0+i*w0) + f(x0+(i+0.5)*w0) + f(x0+(i+1)*w0) )/(2 * > w0 * w0) * x * x + (f(x0+(i+1)*w0) - f(x0+i*w0) )/(2 > * w0) * x + f(x0+(i+0.5)*w0) > > g.plot(graph.data.function("y(x)=g(x)", > context=locals(), points=500)) With the 'def g(x):' you are basically hiding the 'g = graph.graphxy' from before. So the local g is just the function and doesn't have the plot method. Just use another naming for g or g. Gruß, Stefan 

 Re: [PyX-user] Simpson's Rule From: Stefan Schenk - 2008-07-18 05:04 Attachments: Message as HTML Hi Dan Am Donnerstag 17 Juli 2008 20:07 schrieb Dan Reinholz: [...] > The problem is that when I run it I get the error: > > bsd% python simpsons_rule.py > Traceback (most recent call last): > File "simpsons_rule.py", line 27, in > g.plot(graph.data.function("y(x)=g(x)", > context=locals(), points=500)) > AttributeError: 'function' object has no attribute > 'plot' > > Can anybody shed some light on the problem? Ok, let's look at the code. You have > g = graph.graphxy(width=8, > x=axis.linear(min=0, max=intl, title="$x$"), > y=axis.linear(title="$\sin(x) + x$")) and also > for i in range(0, nsubintl): > def g(x): > if x0+i*w0 <= x <= x0+(i+1)*w0: return > (f(x0+i*w0) + f(x0+(i+0.5)*w0) + f(x0+(i+1)*w0) )/(2 * > w0 * w0) * x * x + (f(x0+(i+1)*w0) - f(x0+i*w0) )/(2 > * w0) * x + f(x0+(i+0.5)*w0) > > g.plot(graph.data.function("y(x)=g(x)", > context=locals(), points=500)) With the 'def g(x):' you are basically hiding the 'g = graph.graphxy' from before. So the local g is just the function and doesn't have the plot method. Just use another naming for g or g. Gruß, Stefan