On Friday, June 22, 2018 at 9:14:17 PM UTC+1, Matthias Goerner wrote:
>
> I have a function such as cos(x/y) and values for x and y and want to use
> automatic differentiation (a la wikipedia article
> <https://en.wikipedia.org/wiki/Automatic_differentiation#Automatic_differentiation_using_dual_numbers>)
>
> to find the value and derivatives with respect to x and y. Can this be done
> easily in Sage, preferably using interval arithmetic?
>
why would you want interval arithmetic for something that can be done
symbolically?
sage: var('x,y')
(x, y)
sage: f=cos(x/y)
sage: f.diff(x)
-sin(x/y)/y
sage: f.diff(y)
sage: var('x,y')
(x, y)
sage: f=cos(x/y)
sage: f.diff(x)
-sin(x/y)/y
sage: f.diff(y)
x*sin(x/y)/y^2
sage: fy=f.diff(y)
sage: fy(x=2,y=3)
2/9*sin(2/3)
sage: fy(x=2,y=3).n()
0.137415511793275
> I was hoping for an object that I could use something like this:
>
> sage: A.<dx, dy> = AutomaticDifferentiationField(RDF, 2)
> sage: x = 2.0 + dx
> sage: y = 3.0 + dy
> sage: f = cos(x,y)
> sage: f
> 0.785887260776948 -0.303099142275227 * dx + 0.137415511793275 * dy
> sage: f.value()
> 0.785887260776948
> sage: f.derivatives()
> [-0.303099142275227, 0.137415511793275]
>
> And replacing RDF by RIF and setting x = RIF(1.99, 2.01) + dx, y = ...
> would do it over interval arithmetic then.
>
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.