Manipulate sparse arrays

I am using sparse array as variables in the following:

using Ipopt,JuMP
model = Model(Ipopt.Optimizer)  
n = 4
@variable(model, X[i=1:n, j=1:i-1] >=0)  
@variable(model, y[1:n]>=0)
@variable(model, z[1:n])
@NLconstraint(model, sum(y[i]*sum(X[i,j]*z[j] for j in 1:i-1) for i in 1:n) == 1/6 );
optimize!(model)
println()
@show value.(X)
@show value.(y);

The output is

value.(X) = [2, 1] = 64868.4
[3, 1] = 88415.6
[3, 2] = 88656.4
[4, 1] = 88765.4
[4, 2] = 89160.9
[4, 3] = 89683.5
value.(y) = [90285.94521391376, 64868.38148872992, 65936.12398526275, 65775.99086506596]

My questions are

  1. How to get the solution X (Sparse array) in 16 digits, like the normal array y?
  2. Is there a simple way to embed the sparse array X into an n by n matrix with corresponding indices (Rather than showing individual X[i,j].

Thanks

@show defaults to showing only 6 digits, but the rest of them are still there. Just use e.g. println(value.(X)) and println(value.(Y)).

(That being said, I’m not sure what the default tolerances are in JuMP and Ipopt, but I doubt it’s converging to anything close to 16 accurate digits by default. Accuracy ≠ precision.)

  1. How to get the solution X (Sparse array) in 16 digits, like the normal array y?

As @stevengj says, the answer is a Float64. It’s just not printing all the digits:

julia> value(X[2, 1])
64738.465349791164
  1. Is there a simple way to embed the sparse array X into an n by n matrix with corresponding indices (Rather than showing individual X[i,j].

Do something like

x = zeros(n, n)
for i in 1:n, j in 1:i-1
    x[i, j] = value(X[i, j])
end

Once you have this new matrix x, you can see how the printing interacts:

julia> x
4×4 Matrix{Float64}:
     0.0      0.0      0.0  0.0
 64738.5      0.0      0.0  0.0
 88357.6  88590.0      0.0  0.0
 88709.1  89096.8  89624.3  0.0

julia> println(x)
[0.0 0.0 0.0 0.0; 64738.465349791164 0.0 0.0 0.0; 88357.62229617922 88590.03612752583 0.0 0.0; 88709.11275515296 89096.83641038097 89624.33730302201 0.0]

julia> display(x)
4×4 Matrix{Float64}:
     0.0      0.0      0.0  0.0
 64738.5      0.0      0.0  0.0
 88357.6  88590.0      0.0  0.0
 88709.1  89096.8  89624.3  0.0