I'm trying to make a list of functions by parts and then graph them. But I have troubles accessing a variable element in list G, how could I solve it?
G = {x^2, Sin[x], (x - \[Pi])^2}
Y = {}
xl = {{-2, 0}, {0, \[Pi]}, {\[Pi], \[Pi] + 2}}
For[i = 1, i <= 3, i++,
AppendTo[Y, Which[xl[[i, 1]] < x < xl[[i, 2]], G[[i]]]]
]
Plot[Y, {x, -3, 6}]