Skip to main content
Addressed the root problem
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259
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"}]]

plot

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.

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"}]]

plot

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. It will the code much simpler than your Do-loop.

N[FindInstance[f1[#, y] == f2[#, y] && 0 <= y <= 1, y][[1, 1, 2]]] & /@

x

{0.465845, 0.30669, 0.147535, 0.98838}

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"}]]

plot

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. Doing so will make the code much simpler than your Do-loop.

N[FindInstance[f1[#, y] == f2[#, y] && 0 <= y <= 1, y]][[1, 1, 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.

Addressed the root problem
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259
x = {1, 2, 3, 4};
y1 = {3, 4, 5, 6};
y2 = {{5}, {6}, {8}, {9}};

YouTo 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"}]]

plot

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. It will the code much simpler than your Do-loop.

N[FindInstance[f1[#, y] == f2[#, y] && 0 <= y <= 1, y][[1, 1, 2]]] & /@

x

{0.465845, 0.30669, 0.147535, 0.98838}

x = {1, 2, 3, 4};
y1 = {3, 4, 5, 6};
y2 = {{5}, {6}, {8}, {9}};

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"}]]

plot

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"}]]

plot

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. It will the code much simpler than your Do-loop.

N[FindInstance[f1[#, y] == f2[#, y] && 0 <= y <= 1, y][[1, 1, 2]]] & /@

x

{0.465845, 0.30669, 0.147535, 0.98838}

Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

x = {1, 2, 3, 4};
y1 = {3, 4, 5, 6};
y2 = {{5}, {6}, {8}, {9}};

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"}]]

plot