Array variable - matrix multplication in JuMP

Hello, I am new to Julia and trying to convert one of the tasks that I used to do in Excel into Julia.

I need to find a matrix X. Matrix X represents discrete Markov model transition probabilities with the final column as a default state.

I know the default probabilities so year 1 to 30 so I am trying to solve for the Matrix X.

I am using JuMP and defining my variable matrix as follows:

@variable(model, 0 <= x[1:8, 1:8] <= 1)

Now, let’s say I want to define the probability of being in a default state after 3 years. It would be given by x ^ 3. However, Julia / JuMP does not like this operation. and I get the following error:

Ultimately, I want to use this to calculate the NL objective to solve.

On a side note, x*x works (x^2 doesn’t)

If you are interested in the problem I am trying to solve - it’s here:

Hi there! Take a read of the first post in Please read: make it easier to help you. It explains how you can format your post, and why you should provide code instead of screenshots.

JuMP only supports matrix operators up to quadratic terms. It doesn’t support cubic.

My guess is you want something along the lines of:

model = Model()
@variable(model, 0 <= x[1:8, 1:8] <= 1)
@variable(model, y[1:8, 1:31])
@constraint(model, [t = 1:30], x * y[:, t] .== y[:, t + 1])
2 Likes

Hi,

Thanks @odow, I will remember about the screenshots in future.

Re:

@constraint(model, [t = 1:30], x * y[:, t] .== y[:, t + 1])

I think I get the idea. Shouldn’t y be the same size as x on the first two dimensions and 1:31 on the third dimension?

I will try the following:

model = Model()
@variable(model, 0 <= x[1:8, 1:8] <= 1)
@variable(model, y[1:8, 1:8, 1:31])
@constraint(model, first_t, y[:, :, 1] .== x[:, :])  # I think this is needed
@constraint(model, [t = 1:30], x * y[:, :, t] .== y[:, :, t + 1])

Then, I can set my objective to be based on y.

Let me try this out. Thanks!