# Error when supplying initial guess

**URL:** <https://discourse.julialang.org/t/error-when-supplying-initial-guess/86574>\
**Category:** Optimization (Mathematical)\
**Created:** [August 30, 2022, 10:49pm UTC](https://discourse.julialang.org/t/error-when-supplying-initial-guess/86574 "2022-08-30T22:49:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivzktch99](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@ivzktch99](https://discourse.julialang.org/u/ivzktch99)\
**Post date:** [August 30, 2022, 10:49pm UTC](https://discourse.julialang.org/t/error-when-supplying-initial-guess/86574/1 "2022-08-30T22:49:01Z")

</div>

If I set my variable to be lower trianglar, how can I supply an initial guess? The following gives me an error that has to do with the difference in the data type between the variable X and the initial guess X0

```julia
using JuMP
using LinearAlgebra
n = 4
model = Model()
@variable(model, X[1:n, 1:n], Symmetric)
X = LowerTriangular(X)
X0 = ones(n,n)
# Xl0 = LowerTriangular(X0)
set_start_value.(X, X0)
# set_start_value.(X, Xl0)

```

> MethodError: no method matching set\_start\_value(::AffExpr, ::Float64)  
> Closest candidates are:  
> set\_start\_value(::ConstraintRef{\<:AbstractModel, \<:MathOptInterface.ConstraintIndex{\<:MathOptInterface.AbstractVectorFunction, \<:MathOptInterface.AbstractVectorSet}}, ::Any) at ~/.julia/packages/JuMP/60Bnj/src/constraints.jl:141  
> set\_start\_value(::ConstraintRef{\<:AbstractModel, \<:MathOptInterface.ConstraintIndex{\<:MathOptInterface.AbstractScalarFunction, \<:MathOptInterface.AbstractScalarSet}}, ::Any) at ~/.julia/packages/JuMP/60Bnj/src/constraints.jl:168  
> set\_start\_value(::VariableRef, ::Union{Nothing, Float64}) at ~/.julia/packages/JuMP/60Bnj/src/variables.jl:1015

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [August 30, 2022, 11:06pm UTC](https://discourse.julialang.org/t/error-when-supplying-initial-guess/86574/2 "2022-08-30T23:06:09Z")

</div>

This is a problem broadcasting over a `LowerTriangular` matrix. A lot of the rules in Julia’s `LinearAlgebra` submodule don’t play nicely with JuMP.

Do:

```nohighlight
using JuMP
using LinearAlgebra
n = 4
model = Model()
@variable(model, X[1:n, 1:n], Symmetric, start = 1)

```

or

```julia
using JuMP
using LinearAlgebra
n = 4
model = Model()
@variable(model, X[1:n, 1:n], Symmetric)
X0 = ones(n,n)
set_start_value.(X, X0)
Xl = LowerTriangular(X)

```

---

<div class="post-metadata">

**Author:** ![ivzktch99](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@ivzktch99](https://discourse.julialang.org/u/ivzktch99)\
**Post date:** [September 9, 2022, 10:51pm UTC](https://discourse.julialang.org/t/error-when-supplying-initial-guess/86574/3 "2022-09-09T22:51:20Z")

</div>

@odow Actually this did does not work. For some reason, if you check the initial value for the variable Xl by typing

> start\_value.(Xl)

or

> start\_value(Xl[1,1])

and

> start\_value(Xl[1,2])

, you will see that only the diagonal elements of of X0 are stored as starting values, and the rest of the elements of Xl do not store the starting value!! It’s weird.

Is there any other way to store this starting value with this lower triangular matrix formulation?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [September 9, 2022, 11:36pm UTC](https://discourse.julialang.org/t/error-when-supplying-initial-guess/86574/4 "2022-09-09T23:36:19Z")

</div>

> Actually this did does not work

It works for me. Can you show an example where it doesn’t?

> start\_value(Xl[1,2])

This value doesn’t exist because it refers to the upper triangular component. You need instead `Xl[2, 1]`.

---

<div class="post-metadata">

**Author:** ![ivzktch99](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@ivzktch99](https://discourse.julialang.org/u/ivzktch99)\
**Post date:** [September 10, 2022, 12:13am UTC](https://discourse.julialang.org/t/error-when-supplying-initial-guess/86574/5 "2022-09-10T00:13:10Z")

</div>

@odow Yes you are right. It worked in the original example but here is an example where it failed.

> using LinearAlgebra  
> using JuMP
> 
> model = Model()  
> A0 = [0.8838690285718926 0.0 0.0 0.0 0.0 0.0; -0.008316152744522753 0.121162277532093 0.0 0.0 0.0 0.0; -0.28631572272021377 0.9037570584321651 0.2690998746247849 0.0 0.0 0.0; 0.0246261554790738 0.349183281792961 0.0022806121676061416 0.12469557341957281 0.0 0.0; 4.152455739766909 5.31344761542315 1.6323392598339788 -10.168089383216701 -0.09688778288749404 0.0; -687.1727963778304 -106.0785112003266 -253.33763817980469 -217.40093361126466 1264.761769244352 0.11405506253479718];  
> n = 6  
> @variable(model, A[1:n, 1:n] , Symmetric)  
> set\_start\_value.(A, A0)  
> start\_value.(A)  
> Al = LowerTriangular(A)  
> start\_value(Al[2,1])

I think it does NOT have to do with the Lower triangular structure since the error appears before. I am still not sure why it only takes the diagonal elements of A0

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [September 10, 2022, 12:26am UTC](https://discourse.julialang.org/t/error-when-supplying-initial-guess/86574/6 "2022-09-10T00:26:38Z")

</div>

Ah. I misunderstood your question. The issue is that JuMP represents the symmetric matrix as upper triangular, and your `A0` is lower triangular. Do `set_start_value.(A, A0')`.

---

<div class="post-metadata">

**Author:** ![ivzktch99](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@ivzktch99](https://discourse.julialang.org/u/ivzktch99)\
**Post date:** [September 10, 2022, 11:56am UTC](https://discourse.julialang.org/t/error-when-supplying-initial-guess/86574/7 "2022-09-10T11:56:02Z")

</div>

@odow Yes it worked now! Thank you so much for the help
