kcrisman wrote:
> Dear support,
>
> I'm giving a talk Wednesday and would like to do the following
> interact as an example of how easy interacts are:
>
> y = var('y')
> @interact
> def _(g=input_box(default = 1-y)):
> P=plot_slope_field(g,(x,0,3),(y,0,20))
> y = function('y',x)
> f = desolve(diff(y,x) + g, y, ics=[2,2])
> Q=plot(f,0,3)
> show(P+Q)
>
> Only it isn't easy. The declaring of y = function('y',x), which is
> necessary to use desolve, causes the following error:
>
> UnboundLocalError: local variable 'y' referenced before assignment
>
> And the 'g' in the desolve also causes problems shortly thereafter. I
> tried a lot of things to fix this, but nothing seemed to work quite
> right. Note that this works nicely without interact.
>
> Any help one can give in a relatively timely basis would be much
> appreciated! Thanks in advance,
It looks like you are confusing y-as-a-variable and y-as-a-function an
awful lot. How about:
y = var('y')
@interact
def _(g=input_box(default = 1-y)):
P=plot_slope_field(g,(x,0,3),(y,0,20))
yfun = function('yfun',x)
f = desolve(diff(yfun,x) + g(y=yfun), yfun, ics=[2,2])
Q=plot(f,0,3)
show(P+Q)
Does that give what you want?
Jason
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org