Creating a matrix of variables in optim

I was wondering if anyone could help format my code:

I want to have a diagonal matrix Q and flipped diagonal matrix R where optim runs through values for the diagonal components for the optimization procedure. This is what I have so far but its not quite right obviously because I have R and Q as functions not matrices:

using Optim
N=2
L=100000

R(R1,R2) = flipdim(Matrix(Diagonal(R1:R2)),2) 
Q(Q1,Q2) = Diagonal(R1:R2) 

Can you please provide some more context?

  • Can you write down an objective function, either mathematically or in Julia?
  • What are your decision variables?

This thread is more in-depth with the same problem: https://discourse.julialang.org/t/translating-jump-variables-to-optim/11607

As before, it may be helpful to start with some simple problems in Optim and build up to your problem rather than diving straight in. Optim does not define variables in the same way as JuMP. A helpful place to start is by reading:
http://julianlsolvers.github.io/Optim.jl/stable/user/minimization/#minimizing-a-multivariate-function

Here is the original JuMP thread: Help creating a JuMP variable array - #19 by tkoolen

2 Likes

Unfortunately I am doing this in University (this is not homework it is an outside project I am working with faculty on) and I am on a strict timeline which is why I dived right in. I have been taking your advice and searching on that page but the variable definition and specifically linear algebra portion of using optim I still do not quite get and it may be helpful to see some examples. I have looked through it for many hours and for some reason it is not clicking, I will keep trying though.