4
$\begingroup$

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!

$\endgroup$
2
  • 1
    $\begingroup$ A lot easier if you show what f looks like. $\endgroup$ Commented Sep 7, 2012 at 7:44
  • $\begingroup$ 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... $\endgroup$ Commented Sep 7, 2012 at 8:14

1 Answer 1

6
$\begingroup$

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

            enter image description here

$\endgroup$
3
  • 2
    $\begingroup$ 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[]). $\endgroup$ Commented Sep 7, 2012 at 9:48
  • $\begingroup$ 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).. $\endgroup$ Commented Sep 14, 2012 at 9:18
  • $\begingroup$ @ridwandrusli we have no way of helping you more if you don't post your function (or better, your current code) $\endgroup$ Commented Sep 14, 2012 at 9:35

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.