I have a problem where I am using FindRoot a gazillion times over a grid of parameters. I need to allow the starting values to vary a bit with the parameters to get it to converge. Here is a simple example in the spirit of my much bigger problem:
f[a_] := x /. FindRoot[x^2 - 1 == a, {x, a - 1, a + 1}]
NIntegrate[f[z], {z, 0, 5}]
NIntegrate actually gives an answer (I think it's even right), but it also gives the following errors:
FindRoot::srect: Value -1.+z in search specification {x,z-1,z+1} is not a number or array of numbers. >>
ReplaceAll::reps: {FindRoot[x^2-1==z,{x,z-1,z+1}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>
It looks like it doesn't like treating the starting values for x as variables. For some reason, the actual numbers between 0 and 5 in the integral are not being passed to the starting values in FindRoot. Any suggestions?
Comments
Post a Comment