Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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!

share|improve this question
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 1

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

share|improve this answer
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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