Automatic differentiation unexpected behavior

More
4 years 5 months ago #2627 by Gotya
Hi all,

When I make a CoefficientFunction(x) then Diff(x) returns the expected result of 1.
However, when I make a CoefficientFunction from a GridFunction and then call Diff(x) it returns 0. Is this expected behavior?

Is there a function which I can call that returns the derivative with respect to x of a CoefficientFunction that consists of a GridFunction? Or is the only way to manually specify the derivative using Grad of the GridFunction?

In the attachments there is a small example.

Best,
Gotya
More
4 years 5 months ago #2628 by christopher
Symbolic diff uses pointer comparision and diff rules. So when you for example build a coefficientfunction cf = x*x then cf.Diff(x) = (Product rule) x*x.Diff(x) + x.Diff(x) * x = (Pointer comparison) x*1 + 1*x.
The gridfunction doesn't "know" anything about the cf x.
You can build the derivative you want by using the chain rule, for example:
Code:
func = sin(gf) dfunc = func.Diff(gf) * grad(gf)
Best
The following user(s) said Thank You: Gotya
Time to create page: 0.090 seconds