首页 > 解决方案 > MethodError:Julia 中 JuMP 的一些问题

问题描述

我对 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)    

标签: juliajulia-jump

解决方案


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

ERROR: UndefVarError: LinearInterpolation not defined

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


推荐阅读