# Plotting NSolve solution with a range for a parameter

How can I plot the values of the solution to NSolve: {t1,t2,t3,t4} by connected lines, while each line shows these 4 values for a specific value of the parameter a? (the x-axis to be labelled as {t1,t2,t3,t4} and the y-axis showing their values, and legend showing the parameter values (a) of each line)

 aa=Table[NSolve[{eq1==0,eq2==0,eq3==0,
eq4==0},{t1,t2,t3,t4}],{a,0,3,0.5}]


Thanks

Edited: I have used @Alucard's suggestion, but it seems it doesn't recognize the values of the parameter a (even if I write the equations in NSolve in f[_x] instead of having them written separately before f[_x]), How can I define the values of the parameter (a) for this function?

For the labels, Is there a way to show just the first one (a=0) and the sixth one (a=0.5) on the curves, instead of all labels?

gamma4 = .4;
gamma3 = .284;
gamma2 = .265;
gamma1 = .484;
z3 = 10000;
z2 = 32000;
z1 = 75000;
zbar4 = 4800;
zbar3 = 20050;
zbar2 = 46200;
zbar1 = 138100;
h4 = .301;
h3 = .404;
h2 = .25;
h1 = .045;
p1 = 3.89;
p2 = 4.92;
p3 = 5.22;
p4 = 5.39;
g1 = 0;
g2 = 0.44;
g3 = 0.88;
g4 = 1.76;

Clear[set]
set = a -> # & /@ Range[0, 2, 0.2];

eq1 = (\[Tau]1/(1 - \[Tau]1)) - ((1 -
g1 - (g2 a p2 + g3 a p3 + g4 a p4)) (zbar1 -
z1)/((1 - ((g1 a p1/\[Tau]1) + g2 a p2 + g3 a p3 +
g4 a p4)) zbar1 gamma1));
Print["0=", eq1];

eq2 = (\[Tau]2/(1 - \[Tau]2)) - (((1 -
g2 - (g1 a p1 + g3 a p3 + g4 a p4)) h2 (zbar2 - z2) + (1 -
g1 - (g2 a p2 + g3 a p3 + g4 a p4)) h1 (z1 -
z2))/((1 - (g1 a p1 + (g2 a p2/\[Tau]2) + g3 a p3 +
g4 a p4)) (zbar2 h2 gamma2)));
Print["0=", eq2];

eq3 = (\[Tau]3/(1 - \[Tau]3)) - (((1 -
g3 - (g1 a p1 + g2 a p2 + g4 a p4)) h3 (zbar3 -
z3) + ((1 - g2 - (g1 a p1 + g3 a p3 + g4 a p4)) h2 + (1 -
g1 - (g2 a p2 + g3 a p3 + g4 a p4)) h1) (z2 -
z3))/((1 - (g1 a p1 + g2 a p2 + (g3 a p3/\[Tau]3) +
g4 a p4)) zbar3 h3 gamma3));
Print["0=", eq3];

eq4 = (\[Tau]4/(1 - \[Tau]4)) - (((1 -
g4 - (g1 a p1 + g2 a p2 +
g3 a p3)) h4 (zbar4) + ((1 -
g3 - (g1 a p1 + g2 a p2 + g4 a p4)) h3 + (1 -
g2 - (g1 a p1 + g3 a p3 + g4 a p4)) h2 + (1 -
g1 - (g2 a p2 + g3 a p3 +
g4 a p4)) h1) z3)/((1 - (g1 a p1 + g2 a p2 +
g3 a p3 + (g4 a p4/\[Tau]4))) zbar4*h4*gamma4));
Print["0=", eq4];

f[x_] := Module[{v},
v = Table[{\[Tau]4, \[Tau]3, \[Tau]2, \[Tau]1} /.
NSolve[{eq1 == 0, eq2 == 0, eq3 == 0,
eq4 == 0 && \[Tau]1 > 0 && \[Tau]2 > 0 && \[Tau]3 >
0 && \[Tau]4 > 0}, {\[Tau]1, \[Tau]2, \[Tau]3, \[Tau]4}] /.
x[[i]], {i, 1, Length[x], 1}];
v = Flatten[v, 1];
mR = Labeled[
ListLinePlot[v, GridLines -> {None, {1}},
GridLinesStyle ->
Directive[
AbsoluteThickness[3/2] ColorData[97,
2] Method -> {"GridLinesInFront" -> True}],
PlotLabel -> Style["MTR- Rawlsian", FontSize -> 18],
PlotRange -> {0, 1.05}, PlotLegends -> Values@x,
PlotMarkers -> {Automatic, 10},
Ticks -> {{{1, zbar4}, {2, zbar3}, {3, zbar2}, {4, zbar1}}, {0.2,
0.4, 0.6, 0.8, 0.9, 1}},
TicksStyle -> {Directive[Red, 12], Directive[Red, 8]},
ImageSize -> {800, 300}], "Income Brackets"]]

f[set]

• You need a list of rules, not one rule for lists: You can either write {p1->0,p2->...} or Thread[{p1,p2,...}->{0,0,...}] Aug 23, 2017 at 20:01
• For the second question: You first need to decide how you want to plot it - plotting values in a 4D parameter space is a bit difficult. If you just want to plot those two points, take a look at ListPlot Aug 23, 2017 at 20:03
• The code that you posted indicates a syntax error: "Too few arguments given for Table" In addition to the other problems, why would you expect it to work with a basic syntax error? Aug 23, 2017 at 23:02
• Thanks Bob! I have corrected the syntax. Now I just want to plot the solutions, with a connected line and the parameter values shown as the legend. Aug 24, 2017 at 0:30

Since you did not provide equations i used fake linear equations

Clear[set]
set = a ->  # & /@ Range[0, 3, 0.5];

f[x_] := Module[{v},
v = Table[{t1, t2, t3, t4} /.
NSolve[{t1 - 1 + a == 0, t2 - 2 + 2 a == 0, t3 - 3 + 3 a == 0,
t4 - 4 + 4 a == 0}, {t1, t2, t3, t4}] /. x[[i]], {i, 1,
Length[x], 1}];
v = Flatten[v, 1];
Labeled[
ListLinePlot[v, PlotLegends -> Values@x,
PlotMarkers -> {Automatic, 10},
Ticks -> {{{1, t1}, {2, t2}, {3, t3}, {4, t4}}, Flatten@v},
TicksStyle -> {Directive[Red, 12], Directive[Red, 8]},
ImageSize -> {600, 300}], "exampletext"]

]

f[set]


• Thanks Alucard! Is there a way that I can add labels to some of the lines, showing the parameter value of that line? Aug 25, 2017 at 21:11
• PlotLabels -> Values@x will do the job, but I want the labels for just two of the lines not all of them. Aug 25, 2017 at 21:22
• @Hossein you can use Take[Values@x,n] to take the first n lines. You can sort the equations or the pair {v,x} to obtain only the lines you want, thought i don't know if there is a different method Aug 26, 2017 at 0:40
• @Hossein ok try PlotLabels-> {None,Values@x[[2]],"re"} Aug 26, 2017 at 1:31