# How to use solution of NSolve as a list and them plot?

I am solving a set of equations with one of the parameters Rload as a list. After I solve it, how do I calculate power of each Rload using the formula power=(X-Y)*Rload, and then plot power vs Rload?

NSolve[{-(310 - X)/0.1 + (X - Y)/20 + 0.09128^2*X*(X - Y)/(5 + Rload) -
(Y - 300)/10 - (X - Y)/20 - 0.09128^2*Y*(X - Y)/(5 + Rload) -

{#, sol[Sequence @@ #]} & /@ values // Flatten[#, 1] &


• Are you trying to obtain NSolve output for all Rload in the range of 1 to 20? If so, use Table. I do not understand the second block of code, and sol is undefined. Dec 29, 2021 at 20:00

I have additionally assumed that X > 0 and Y > 0

eqns = {
-(310 - X)/0.1 + (X - Y)/20 + 0.09128^2*X*(X - Y)/(5 + Rload) -
(Y - 300)/10 - (X - Y)/20 - 0.09128^2*Y*(X - Y)/(5 + Rload) -
Rload > 0, X > 0, Y > 0}// Rationalize[#, 0] &;

sol = NSolve[eqns, {X, Y}];

Length@sol

(* 2 *)


The two solutions cover different segments of the range of Rload

Plot[Evaluate[(X - Y)*Rload /. sol], {Rload, 0, 20},
Frame -> True,
FrameLabel -> (Style[#, 14] & /@ {Rload, Power}),
PlotLegends -> Placed[Automatic, {.8, .3}]]


• Thank you! It works. Do you know why the solution is separated in 2 segments?
– H Li
Dec 29, 2021 at 22:03
• Because the solution has multiple complex branches and the real result switches between the branches. Dec 29, 2021 at 22:19

After I solve it, how do I calculate power of each Rload ...

r = Range[1, 20, 1]


Let's say you have solved and have {r,x,y} as a list of 3-tuples called vals, then:

vals={{1, 309.918, 308.202}, {2, 309.92, 308.001}, {3, 309.922,
307.815}, {4, 309.923, 307.644}, {5, 309.925, 307.485}, {6, 309.926,
307.337}, {7, 309.928, 307.199}, {8, 309.929, 307.071}, {9, 309.93,
306.95}, {10, 309.931, 306.838}, {11, 309.933, 306.732}, {12,
309.934, 306.632}, {13, 309.934, 306.538}, {14, 309.935,
306.449}, {15, 309.936, 306.364}, {16, 309.937, 306.285}, {17,
309.938, 306.209}, {18, 309.939, 306.137}, {19, 309.939,
306.069}, {20, 309.94, 306.003}};


use a pure function to create {r,power} pairs.

power = {#[[1]], #[[1]] (#[[2]] - #[[3]])} & /@ vals

{{1, 1.71529}, {2, 3.83787}, {3, 6.31944}, {4, 9.119}, {5,
12.2016}, {6, 15.5371}, {7, 19.0997}, {8, 22.8667}, {9,
26.8185}, {10, 30.938}, {11, 35.2099}, {12, 39.6209}, {13,
44.1591}, {14, 48.8139}, {15, 53.5761}, {16, 58.437}, {17,
63.3893}, {18, 68.4259}, {19, 73.5408}, {20, 78.7284}}

ListLinePlot[power
, Frame -> True
, GridLines -> Automatic