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 <module>
>     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

Attachment: pgpFurqzIpNtO.pgp
Description: PGP signature

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to