【问题标题】:MethodError: some problems with JuMP in JuliaMethodError:Julia 中 JuMP 的一些问题
【发布时间】:2021-08-17 11:59:51
【问题描述】:

我在使用 JuMP 时遇到了一些问题。当我运行它时,它说:

MethodError: no method matching (::Interpolations.Extrapolation{Float64, 1, ScaledInterpolation{Float64, 1, Interpolations.BSplineInterpolation{Float64, 1, Vector{Float64}, BSpline{Linear{Throw{OnGrid}}}, Tuple{Base.OneTo{Int64}}}, BSpline{Linear{Throw{OnGrid}}}, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}}}, BSpline{Linear{Throw{OnGrid}}}, Throw{Nothing}})(::AffExpr)
Use square brackets [] for indexing an Array.

谢谢!

using JuMP
import Ipopt
β = 0.88
Nb = 1000
δ = 1.5
wage = 1
rate = 1
grid_b = range(0, 5, length = 1000)
w = 5 * (grid_b).^2
w_func = LinearInterpolation(grid_b, w)
choice1 = Model(Ipopt.Optimizer)  
@variable(choice1, x >= 0)
@NLobjective(choice1, Max, x^δ/(1-δ) + β * (w_func.((grid_b[3]*(1+rate)+wage-x) * 3))) 
optimize!(choice1)    

【问题讨论】:

    标签: julia julia-jump


    【解决方案1】:

    如果我尝试运行你的代码,我会得到

    ERROR: UndefVarError: LinearInterpolation not defined
    

    这是哪个包的?另外,您使用的是什么版本的 JuMP?

    【讨论】:

      【解决方案2】:

      您不能在 JuMP 中使用任意函数。您需要使用用户定义的函数: https://jump.dev/JuMP.jl/stable/manual/nlp/#User-defined-Functions

      但这只有在可以自动区分函数的情况下才有效。我不知道这是否适用于 Interpolations.jl。

      附言在多个地方发布相同问题时请提供链接:https://discourse.julialang.org/t/methoderror-no-method-matching-in-jump/66543/2

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多