JuliaApproximation / ApproxFun.jl

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

Newton for simple PDE gives NaN result #887

Open dstahlke opened 1 year ago

dstahlke commented 1 year ago

This simple test gives a NaN result:

using ApproxFun

xdom = Chebyshev(-1..1)
x = Fun(identity, xdom)

N(u, v) = [u - x; v + x]

u0 = 0*x
v0 = 0*x
newton(N, [u0, v0])

Result:

2-element Vector{Fun{Chebyshev{IntervalSets.ClosedInterval{Int64}, Float64}, Float64, Vector{Float64}}}:
 Fun(Chebyshev(-1..1), [NaN, NaN, NaN, NaN])
 Fun(Chebyshev(-1..1), [NaN, NaN, NaN])

And I don't know if it's related, but with a two-dimensional domain it gives a different error:

using ApproxFun

xdom = Chebyshev(-1..1)
ydom = Chebyshev(-1..1)
x, y = Fun(identity, xdom*ydom)

N(u, v) = [u - x; v + y]

u0 = 0*x
v0 = 0*x
newton(N, [u0, v0])

Result:

ERROR: LoadError: ArgumentError: invalid argument #4 to LAPACK call
Stacktrace:
  [1] chklapackerror
    @ ~/apps/julia-1.9.0/share/julia/stdlib/v1.9/LinearAlgebra/src/lapack.jl:38 [inlined]
  [2] gesdd!(job::Char, A::Matrix{Float64})
    @ LinearAlgebra.LAPACK ~/apps/julia-1.9.0/share/julia/stdlib/v1.9/LinearAlgebra/src/lapack.jl:1665
  [3] _svd!
    @ ~/apps/julia-1.9.0/share/julia/stdlib/v1.9/LinearAlgebra/src/svd.jl:125 [inlined]
  [4] svd!(A::Matrix{Float64}; full::Bool, alg::LinearAlgebra.DivideAndConquer)
    @ LinearAlgebra ~/apps/julia-1.9.0/share/julia/stdlib/v1.9/LinearAlgebra/src/svd.jl:105
  [5] svd!
    @ ~/apps/julia-1.9.0/share/julia/stdlib/v1.9/LinearAlgebra/src/svd.jl:100 [inlined]
  [6] #svd#114
    @ ~/apps/julia-1.9.0/share/julia/stdlib/v1.9/LinearAlgebra/src/svd.jl:179 [inlined]
  [7] svd
    @ ~/apps/julia-1.9.0/share/julia/stdlib/v1.9/LinearAlgebra/src/svd.jl:178 [inlined]
  [8] LowRankFun(X::Matrix{Float64}, dx::Chebyshev{IntervalSets.ClosedInterval{Int64}, Float64}, dy::Chebyshev{IntervalSets.ClosedInterval{Int64}, Float64})
    @ ApproxFunBase ~/.julia/packages/ApproxFunBase/9nGis/src/Multivariate/LowRankFun.jl:59
dstahlke commented 1 year ago

Both these test cases are fixed by the following PRs: https://github.com/JuliaApproximation/ApproxFun.jl/pull/891 https://github.com/JuliaApproximation/ApproxFunBase.jl/pull/479