# Selecting polynomial roots and plotting against parameters

An implicit function $f(x,k)=0$ is quadratic in $x$ and contains one parameter $k$ which I must vary. Using `Solve`, I get two real solutions for each specific $k$: $x_1$ and $x_2$, of which I must choose the one that lies within $[0, 0.5]$. I must do this for a continuum of parameters $k$ between, say, $0$ and $1$. I then must plot the relevant $x$ solution against the parameter $k$ in a smooth curve.

Note: I also tried the unglorious method i.e. if $k$ took discrete values, I thought I could manually select say 30 points and interpolate. But any curve fitting command I tried, using various polynomial and exponential expansions, could not give me smooth curve?

Of course I hope to learn the elegant method, but under time pressure anything that gives me a smooth curve is welcome!

-

1
A lot easier if you show what `f` looks like. – b.gatessucks Sep 7 '12 at 7:44
Well, `FindRoot[]` supports the option of root bracketing; if all you want is an approximate root, it should be fine. Otherwise, since you say it's quadratic in $x$, one could always manipulate the quadratic formula... – J. M.♦ Sep 7 '12 at 8:14

## 1 Answer

As J. M. says, `FindRoot` allows two options: either root bracketing, or the simpler choice of starting with an initial approximation for the root that is close enough. Since you said your root is unique in the [0,0.5] interval, and your function is smooth, you can expect that a starting value of 0.25 will usually give you the root you're looking for.

````f[x_] := Expand[(x - 0.5*Sin[k^2])*(x - 3*k - 1)]
Plot[x /. FindRoot[f[x], {x, 0.25}], {k, 0, 1}]
````

-

2
Additionally, as a guarantee that the iteration never veers off the brackets you have set up, use Brent's method (i.e. append the option setting `Method -> "Brent"` to `FindRoot[]`). – J. M.♦ Sep 7 '12 at 9:48
Thank you, it works. Only thing is, when desireable solutions x*(k) approach 0 as parameter k is changed towards one end of the parameter range, the solution becomes discontinuous ..although i know there does exist a finite, smooth x(k).. – user2297 Sep 14 '12 at 9:18
@ridwandrusli we have no way of helping you more if you don't post your function (or better, your current code) – F'x Sep 14 '12 at 9:35
lang-mma
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 14, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.8993709087371826, "perplexity_flag": "middle"}