> > Hi, I'm wondering if it is possible to insert a number into symbolic
> > equation. For example:
>
> > sage: y = x^2
> > sage: diff(y)
> >    2*x
>
> > now is it possible to take the results of the derivative, define x as
> > say 3, and get a numeric answer? Thanks
>
> Try this:
> sage: g = diff(y)
> sage: g
>  x |--> 2*x
> sage: g(3)
>  6

That usage is deprecated. "g" in this case would evaluate to the
expression "2*x", not the function "x |--> 2*x".

You can plug in a value for x using the "subs" method:

sage: y = x^2
sage: diff(y)
2*x
sage: diff(y).subs(x=3)
6
sage: diff(y).subs(x=pi)
2*pi

Alternatively, if you define "y" as a function, "g" would be a
function:

sage: y(x) = x^2
sage: y
x |--> x^2
sage: g = diff(y)
sage: g
x |--> 2*x
sage: g(3)
6
sage: g(pi)
2*pi

Hope this helps.

-- Tianwei

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

Reply via email to