Ask Your Question

Problem with various type in linear programming

asked 2022-09-02 16:28:37 +0100

Cyrille gravatar image

The following program is well defined

f(x) = 4*x-0.9*x^2
pas=1# 0.5,0.25
X=[n(pas*i,14) for i in range(0,Integer(lr/pas))]
pente=[diff(f(x),x).subs(x=X[i]) for i in range(0,Integer(lsp))]
optim_1 = MixedIntegerLinearProgram(maximization=False, solver = "GLPK")
x = optim_1.new_variable(integer=False, indices=[0..len(X)+1]) # les nouvelles variables seront x[1]... x[7]}
for i in range(0, len(X)):

but unfortunatelly for me the constraints are


But in that case, I raise the error unsupported operand parent(s) for +: 'Linear functions over Real Double Field' and 'Symbolic Ring'. I perfectly uderstand the problem but I do not know. I do not know in what type to transform f(X[i]), if this is the problem.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-09-02 16:41:43 +0100

tmonteil gravatar image

updated 2022-09-02 16:52:04 +0100

The problem is that f is a symbolic expression (like a formula, which is good to compute derivatives), not a function that can be called to transform floating-point numbers into floating-point numbers (it will instead return a symbolic expression).

You can transform a symbolic expression into a callable function defined on the floating-point numbers with fast_float:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2022-09-02 16:28:37 +0100

Seen: 93 times

Last updated: Sep 02 '22