JuMP: defining objective function uses matrix multiplication

Hi I am trying to recreate a relatively simple optimization function that I have working with python using (casadi + ipopt).

I am having some trouble figuring out how I can describe the objective function since it involves matrix/vectors. What would be the correct method to handle such a function with JuMP?

Reference working python code (Function in line 11): http://ix.io/2Ecl
What I have got with Julia so far: http://ix.io/2Ecp (line 55 in solve_InfMat())

Thanks for your help :slight_smile:

I do not know Python so many things are not clear to me in your example, from where comes U? Are I variables? (I am not sure of what comes from a .mat file.) If I am not wrong Ipopt supports arbitrary functions so you could code a function that does the same your objective function in python does and pass it to Ipopt by JuMP. I think this post summarises some of the difficulties of working with non-linear objectives in Ipopt.

Sorry, i should’ve been more explicit.

I is an MxN matrix (45x37). I am pulling that from the mat file. Some experimental data in reality.

U is an Nx1 vector. This is the unknown I am trying to solve for.

Z is a Mx1 vector. That’s the known target. I set it to zeros. But explicitly set z[4]=-2.0 in my example code.

I am of course able to describe the same function in both languages see (lines 11 in Python and 55 in Julia version).

Thanks for sharing the post. I noticed this linked there: https://jump.dev/JuMP.jl/stable/nlp/#User-defined-functions-with-vector-inputs-1

I couldn’t quite grasp the work around. I am new to Julia so perhaps I misunderstand something. Its a relatively simple linear equation:

obj_function(U) = 0.5 * ((U’ * (I’ * I)) * U) + transpose(-1 * (I’ * z)) * U

How could something like this be passed without using vectors/matrices?

For reference. I use IPOPT to minimize this function. The only constrains are that each element of U is within 0-400^2

JuMP doesn’t have the same features as CasADi for writing nonlinear problems with matrix-valued and vector-valued subexpressions. However, it looks like you’re in luck because your objective appears to be quadratic with respect to U. You can therefore write something like:

@objective(m, Min, 0.5 * ((U’ * (I’ * I)) * U) + transpose(-1 * (I’ * z)) * U)

(possibly with modifications to make sure the output is a scalar and not a 1x1 matrix).


Thanks. That way of writing the objective does indeed solve the problem correctly.