# Select one among multiple solutions that satisfies a certain condition and 3D Plot it with varying simulation values

My function is as follows:

$$f(x)=ax^5+bx^4+cx^3+dx^2+ex+g=0$$

Since it does not generate an analytical solution, I tried to do a simulation exercise as follows.

Simulation values: $$a=-2$$, $$b=3$$, $$c=5$$, $$g=3.5$$.

And for $$0\leqslant d\leqslant 1$$ and $$0\leqslant e\leqslant 1$$, among five different solutions, I would like to pick the one that is real and positive, and 3DPlot it against $$d$$ and $$e$$.

My Mathematica code is as follows:

Plot3D[x/.sol=Select[{Solve[ax^5+bx^4+cx^3+dx^2+ex+f==0,x]},#>0&,1],{d,0,1},{e,0,1}]


And the result I get is this:

Any help would be greatly appreciated!

This may be close to what you want.

a = -2;
b = 3;
c = 5;
g = 3.5;

tab = Table[
x /. Solve[a x^5 + b x^4 + c x^3 + d x^2 + e x + g == 0, x,
Reals][[1]], {d, 0, 1, .1}, {e, 0, 1, .1}];

ListPlot3D[tab, DataRange -> {{0, 1}, {0, 1}}, AxesLabel -> {d, e}]


• Thanks so much! It seems that 'real number' is the only condition here. Do you know how to add 'positive number' as an additional condition? That is, just in case I use a different set of simulation values and have some solutions being positive and some negative, I would like to select and plot the solution that is real and positive. – ppp Mar 27 '19 at 3:17
With[{a = -2, b = 3, c = 5, g = 35/10},
sol = Solve[{a x^5 + b x^4 + c x^3 + d x^2 + e x + g == 0, 0 <= d <= 1, 0 <= e <= 1}, x, Reals]
]

Plot3D[
Evaluate[x /. sol],
{d, 0, 1}, {e, 0, 1}
]


• Thanks so much! It seems that 'real number' is the only condition here. Do you know how to add 'positive number' as an additional condition? That is, just in case I use a different set of simulation values and have some solutions being positive and some negative, I would like to select and plot the solution that is real and positive. – ppp Mar 27 '19 at 3:19
• @ppp you can always try to add that condition inside Solve, I.e. x > 0, in which case you need not specify the Reals domain, because it is implied by that condition. – MarcoB Mar 27 '19 at 3:42
• Thanks so much! It really helps! I will try and report how it worked soon! – ppp Mar 27 '19 at 17:57