I have a matrix ,e.g., d2={{3,2},{4,1},{5,6}}, and I want to create a 3D array, e.g., d3={{3,18,2},{4,32,1},{5,50,6}} from the 2D matrix, note that the inserted middle element is 2 times the square of the first element . I can not figure out how to do this in mathematica
In[1]:= d = {{3, 2}, {4, 1}, {5, 6}};
In[2]:= d /. {a_, b_} -> {a, 2*a^2, b}
Out[2]= {{3, 18, 2}, {4, 32, 1}, {5, 50, 6}}
d2 = {{3, 2}, {4, 1}, {5, 6}}
a = {18, 32, 50}
d3 = Table[{d2[[n, 1]], a[[n]], d2[[n, 2]]}, {n, 1, 3}]
This will yield
3 18 2
4 32 1
5 50 6