1
$\begingroup$

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:

enter image description here

Any help would be greatly appreciated!

$\endgroup$
0
$\begingroup$

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

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – ppp Mar 27 '19 at 3:17
0
$\begingroup$
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}
]

Mathematica graphics

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – ppp Mar 27 '19 at 3:19
  • $\begingroup$ @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. $\endgroup$ – MarcoB Mar 27 '19 at 3:42
  • $\begingroup$ Thanks so much! It really helps! I will try and report how it worked soon! $\endgroup$ – ppp Mar 27 '19 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.