Closed chkwon closed 7 years ago
Hmm this is odd. I don't have time to take a closer look right now, but thank you for reporting.
@KristofferC if you have any time to look into this that'd be great -- if not that's ok too!
Since I know nothing of this thing you call "complementary problems" I am not the right person to ask :)
All I can see is that it says |f(x)| < 1.0e-08: true
so it considers the equation solved.
@chkwon was this ever solved?
@pkofod It seems not.
I'm not at a computer but it seems as if f! Has a 🐜. You need to assign into fvec, copy! or similar. Fvec isn't updated the way you're doing it
Good catch @pkofod.
Defining
function f!(x, fvec)
copy!(fvec, M * x + q)
end
results in
julia> r = mcpsolve(f!, [0., 0., 0., 0.], [Inf, Inf, Inf, Inf],
[1.25, 0., 0., 0.5], reformulation = :smooth, autodiff = true)
Results of Nonlinear Solver Algorithm
* Algorithm: Trust-region with dogleg and autoscaling
* Starting Point: [1.25,0.0,0.0,0.5]
* Zero: [2.8,-4.72171e-16,0.8,1.2]
* Inf-norm of residuals: 0.000000
* Iterations: 6
* Convergence: true
* |x - x'| < 0.0e+00: false
* |f(x)| < 1.0e-08: true
* Function Calls (f): 7
* Jacobian Calls (df/dx): 7
julia> x = r.zero # [1.25, 0.0, 0.0, 0.5]
4-element Array{Float64,1}:
2.8
-4.72171e-16
0.8
1.2
julia> @show dot( M*x + q, x ) # 0.5
dot(M * x + q,x) = -4.468660707835697e-14
-4.468660707835697e-14
julia> sol = [2.8, 0.0, 0.8, 1.2]
4-element Array{Float64,1}:
2.8
0.0
0.8
1.2
julia> @show dot( M*sol + q, sol ) # 0.0
dot(M * sol + q,sol) = 3.552713678800501e-16
3.552713678800501e-16
Brilliant! Thanks a lot!
I've tried to solve the following simple linear complementarity problem using
NLsolve
.While the solution is know to
[2.8, 0.0, 0.8, 1.2]
, I obtained[1.25, 0.0, 0.0, 0.5]
, just same as the initial solution provided.It seems that it was not run properly with 0 iterations.