JuliaApproximation / ApproxFun.jl

Julia package for function approximation
http://juliaapproximation.github.io/ApproxFun.jl/
Other
538 stars 71 forks source link

What is the difference between adjoint and a Derivative (newton solver)? #935

Open GrigorySarnitsky opened 6 months ago

GrigorySarnitsky commented 6 months ago

Not so much of an issue, but a highly confusing point. Apparently both ' and Derivative() compute the derivative but in different ways:

> Fun(x -> x^2)'
Fun(Chebyshev(), [0.0, 2.0])

and

> Derivative() * Fun(x -> x^2)
Fun(Ultraspherical(1), [0.0, 1.0])

This is the most confusing while using newton(). The example from the docs with ' works:

using ApproxFun
using Plots

N1(u, x = Fun()) = [u(-1.)-1., u(1.)+0.5, 0.001u'' + 6(1-x^2)u' + u^2 - 1];
u = newton(N1, 0 * Fun())

plot(u)

but changing it to

∂x = Derivative()
N1(u, x = Fun()) = [u(-1.)-1., u(1.)+0.5, 0.001 * (∂x^2 * u) + 6(1-x^2) * (∂x * u) + u^2 - 1];

throws an error:

MethodError: no method matching space(::ApproxFun.DualFun{Fun{Chebyshev{ChebyshevInterval{Float64}, Float64}, Float64, Vector{Float64}}, ConstantOperator{Float64, Chebyshev{ChebyshevInterval{Float64}, Float64}}})

Closest candidates are:
  space(::LowRankFun, ::Integer)
   @ ApproxFunBase [~/.julia/packages/ApproxFunBase/clvO0/src/Multivariate/LowRankFun.jl:348](http://localhost:8888/home/grigory/.julia/packages/ApproxFunBase/clvO0/src/Multivariate/LowRankFun.jl#line=347)
  space(::LowRankFun)
   @ ApproxFunBase [~/.julia/packages/ApproxFunBase/clvO0/src/Multivariate/LowRankFun.jl:349](http://localhost:8888/home/grigory/.julia/packages/ApproxFunBase/clvO0/src/Multivariate/LowRankFun.jl#line=348)
  space(::Fun)
   @ ApproxFunBase [~/.julia/packages/ApproxFunBase/clvO0/src/Fun.jl:339](http://localhost:8888/home/grigory/.julia/packages/ApproxFunBase/clvO0/src/Fun.jl#line=338)
  ...