- Thank you received: 0
Automatic differentiation unexpected behavior
4 years 6 months ago #2627
by Gotya
Automatic differentiation unexpected behavior was created 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
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
Attachments:
- christopher
- Offline
- Administrator
Less
More
- Thank you received: 101
4 years 6 months ago #2628
by christopher
Replied by christopher on topic Automatic differentiation unexpected behavior
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:
Best
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)
The following user(s) said Thank You: Gotya
Time to create page: 0.099 seconds