-
-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiplication of matrix expression and variables leads to stack overflow and matmul error #3714
Comments
It's hard to reproduce your issue since your code is also not reproducible: can you either give the full expression for |
Definitely! The code to reproduce the issue: using JuMP
using NLopt
const R_EARTH = 6.378136300e6 # [m] GGM05s Value
const GM_EARTH = 3.986004415e14 # [m^3/s^2] GGM05s Value
const J2_EARTH = 0.0010826358191967 # [] GGM05s value
const OMEGA_EARTH = 7.292115146706979e-5
ωₑ = OMEGA_EARTH;
μ = GM_EARTH;
Rₑ = R_EARTH;
J₂ = J2_EARTH;
function dT(x...)
(a,e,i,ω,Ω,θ) = x
p = a*(1-e^2)
r = p/(1+e*cos(θ))
h = a*√(μ/a)
ωₛ = √(μ/a^3)
A = replace(
[.0,.0,.0,.0,(-3/2)*(Rₑ^2/(a*(1-e^2))^2)*J₂*ωₛ*cos(i),h/r^2]
, NaN=>0, Inf=>0, -Inf=>0)
return A
end
function dU(x...)
(a,e,i,ω,Ω,θ) = x
p = a*(1-e^2)
r = p/(1+e*cos(θ))
h = a*√(μ/a)
ωₛ = √(μ/a^3)
B = replace(
[(2*a^2/h)*(e*sin(θ)) (2*a^2/h)*(p/r) 0
(1/h)*(p*sin(θ)) (1/h)*((p+r)*cos(θ) + r*e) 0
0 0 (r*cos(θ+ω))/h
-p*cos(θ)/(e*h) (p+r)*sin(θ)/(e*h) -(r*sin(θ+ω)*cos(i))/(h*sin(i))
0 0 (r*sin(θ+ω))/(h*sin(i))
(p*cos(θ))/(e*h) -((p+r)*sin(θ))/(e*h) 0]
, NaN=>0, Inf=>0, -Inf=>0)
return B
end
begin
h = 2
n = 6
m = 3
model = Model(NLopt.Optimizer)
set_optimizer_attribute(model, "algorithm", :AUGLAG)
local_optimizer = NLopt.Opt(:LD_LBFGS, n*(h+1) + m*h)
local_optimizer.xtol_rel = 1e-4
set_optimizer_attribute(model, "local_optimizer", local_optimizer)
@variables model begin
X[1:6, 1:h+1]
U[1:3, 1:h]
27000.0 <= T[1:h]
end
let i=1
B = dU(X[:,i]...)
B*U[:,i]
end
end This is required to set up the dynamics constraints for the control problem, U is the effort input and B is the jacobian of X with effort. Later on when the formulation is done, we minimise the norm of U to minimise fuel use of transfer. |
I can run your code, but I can't reproduce any errors on the latest JuMP version. I recommend upgrading to the latest package versions. On Julia Version 1.10.2, these are (jl_6E3tDY) pkg> st
Status `../jl_6E3tDY/Project.toml`
[4076af6c] JuMP v1.20.0
[76087f3c] NLopt v1.0.2 |
Yes! That resolved the issue. |
I have an optimal orbital transfer problem:
Trying to multiply an expression matrix
with
by executing:
Results in the following stack overflow error:
Whereas doing:
B1*U[:,:]
Gives the correct result, a 6x2 matrix.
Help in understanding and resolving the problem is appreciated!
The text was updated successfully, but these errors were encountered: