x = {1, 2, 3, 4};
y1 = {3, 4, 5, 6};
y2 = {{5}, {6}, {8}, {9}};
To correct y2
when has been already generated, you just need to apply Flatten
to y2
and then plot the transpose of x
and the flattened y2
.
ListPlot[
{Transpose[{x, y1}], Transpose[{x, Flatten[y2]}]},
PlotLegends -> SwatchLegend[{"y1", "y2"}]]
Now let's look into generating the flat form of y2
directly. You did provide definitions for the two functions for which you are giving FindInstance
, so I will use these two
f1[x_, y_] := Sin[x + 2 π y]
f2[x_, y_] := Cos[x + 2 π y]
I will use Map
in its operator form, /@
, to generate the list y2
. ItDoing so will make the code much simpler than your Do-loop.
N[FindInstance[f1[#, y] == f2[#, y] && 0 <= y <= 1, y][[1y]][[1, 1, 2]]]2]] & /@
x
{0.465845, 0.30669, 0.147535, 0.98838}
Note tha t I use the part specification [[1, 1, 2]]
to extract the numerical values for the list of instance found by FindInstance
. Were I to use the usual extraction method
y /. N[FindInstance[f1[#, y] == f2[#, y] && 0 <= y <= 1, y]] & /@ x
I would get
{{0.465845}, {0.30669}, {0.147535}, {0.98838}}
a list of the same shape as the one that you generate.