Reputation: 117
Code - Quasi Newton Problem
This is the code for Quasi Newton Problem. For this, I am getting an error
MethodError: no method matching isless(::Matrix{Float64}, ::Matrix{Float64})
Closest candidates are:
isless(::Any, ::Missing) at missing.jl:88
isless(::Missing, ::Any) at missing.jl:87
Stacktrace:
[1] <(x::Matrix{Float64}, y::Matrix{Float64})
@ Base .\operators.jl:279
[2] >(x::Matrix{Float64}, y::Matrix{Float64})
@ Base .\operators.jl:305
[3] bracket_minimum(f::var"#45#46"{typeof(k), Matrix{Float64}, Matrix{Float64}}, x::Int64; s::Float64, k::Float64)
@ Main .\In[122]:12
[4] bracket_minimum(f::Function, x::Int64) (repeats 2 times)
@ Main .\In[122]:10
[5] line_search(f::typeof(k), x::Matrix{Float64}, d::Matrix{Float64})
@ Main .\In[122]:35
[6] step!(M::BFGS, f::Function, ∇f::typeof(l), x::Matrix{Float64})
@ Main .\In[122]:48
[7] quasi_method(f::typeof(k), g::Function, x0::Matrix{Float64})
@ Main .\In[122]:67
[8] top-level scope
@ In[128]:3
[9] eval
@ .\boot.jl:360 [inlined]
[10] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1116
I still couldn't figure what's the issue with line 10 and 12. So help me out here? Maybe it's due to Matrix we are using or some other issues, I couldn't debug.
Upvotes: 1
Views: 1603
Reputation: 42194
You forgot to vectorize your code. See the example below for reference:
julia> a=[1. 2.; 3. 4.]; b=[1. 3.; 5. 7.];
julia> a < b
ERROR: MethodError: no method matching isless(::Matrix{Float64}, ::Matrix{Float64})
Now let us add dot to vectorize:
julia> a .< b
2×2 BitMatrix:
0 1
1 1
If you want to check if all elements are lower use all
:
julia> all(a .< b)
false
In your code bracket_minimum
does the comparison yc > yb
and those values are matrices while your code expects scalars.
Upvotes: 2