Skip to content

Maxiters seems to be offset by 1 #63

Closed
@KronosTheLate

Description

@KronosTheLate

Check out the following example:

julia> using NonlinearSolve, LinearAlgebra

julia> f(u,p) = u .* u .- p;

julia> u0 = [1.0, 1.0];

julia> p = 2.0;

julia> probN = NonlinearProblem{false}(f, u0, p);

julia> bla0 = solve(probN, NewtonRaphson(), maxiters = 0).u;

julia> bla1 = solve(probN, NewtonRaphson(), maxiters = 1).u;

julia> bla2 = solve(probN, NewtonRaphson(), maxiters = 2).u;

julia> norm(f(u0, p))
1.4142135623730951

julia> norm(f(bla0, p))
1.4142135623730951

julia> norm(f(bla1, p))
1.4142135623730951

julia> norm(f(bla2, p))
0.3535533905932738

It seems as if setting maxter to 1 acutally results in zero iterations occuring. And I am left to wonder if maxter=2 then means 2 iterations, or actually 1 iteration...

This is the same for my actual application, which makes me more certain that the issue is not specific to this problem. The other example is:

julia> using NonlinearSolve, LinearAlgebra

julia> v = 120;  #kg

julia> k = 2.5;  #m

julia> w = 4.0;  #km/m

julia> α = 2e-7; #kg⁻¹

julia> function F(x⃗, parameters)
           L₀, L, p, x, θ, φ, a, H = x⃗
           (;d, n) = parameters
           return [
           a*(cosh(x/a)-1) - p,
           2a * sinh(x/a) - L ,
           2x + 2k*cos(θ) - d,
           p+k*sin(θ) - n,
           sinh(x/a) - tan(φ),
           (1+v/(w*L₀)) * tan(φ) - tan(θ),
           L₀ * (1 + α*H) - L,
           w*L₀ / 2sin(φ) - H,
           ]
       end;

julia> params = (d=30, n=5);

julia> u0 =    [29, 27, 1, params.d/2, deg2rad(45),  deg2rad(22.5), 40, 500];

julia> probN = NonlinearProblem{false}(F, u0, params);

julia> bla0 = solve(probN, NewtonRaphson(), maxiters = 0).u;

julia> bla1 = solve(probN, NewtonRaphson(), maxiters = 1).u;

julia> bla2 = solve(probN, NewtonRaphson(), maxiters = 2).u;

julia> norm(F(u0, params))
348.4941911206226

julia> norm(F(bla0, params))
348.4941911206226

julia> norm(F(bla1, params))
348.4941911206226

julia> norm(F(bla2, params))
3.865006154302766

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions