@CPPhysics wrote:
Hello, I am doing an optimization problem and want to extend a minimizing vector to become an initial guess for the same problem in a larger parameter space (one can think of it as being in a larger dimension), with all extra parameters being zero. I am having some trouble figuring out the code to do this, although I believe I am most of the way there:
First I create a function which will take a real valued vector and create complex matrices A4 and B4
x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] function Initializer(x::Vector) A4 = reshape(Complex.(x[1:2:7],x[2:2:8]),2,2) B4 = reshape(Complex.(x[9:2:15],x[10:2:16]),2,2) end
I then create the same matrices in the larger parameter space out of zeros (A6, B6), and replace their upper left corner elements with that of A4 and B6:
function Initializer(x::Vector) A4 = reshape(Complex.(x[1:2:7],x[2:2:8]),2,2) B4 = reshape(Complex.(x[9:2:15],x[10:2:16]),2,2) A6 = reshape(Complex.(zeros(9),zeros(9)),3,3) B6 = reshape(Complex.(zeros(9),zeros(9)),3,3) A6[1:2,1:2] = A4 B6[1:2,1:2] = B4 global X0 = ? end
A6 and B6 are exactly what I want, but I need to be able to create them as they are in a different function. So I want to create a global variable (call it X0) which will be able to populate a new function in the exact way that A6 and B6 are created in “Initializer()”, which would look like the following:
function Create(x::Vector) A6 = reshape(Complex.(x[1:2:17],x[2:2:18]),3,3) B6 = reshape(Complex.(x[20:2:35],x[21:2:36]),3,3) end
Where
Create(X0)
would give me the same A6 and B6 that I am left with at the end of the Initialize function. Any help would be greatly appreciated!
Posts: 1
Participants: 1