# NSolve with numerical function

I would like to solve numerically an equation which involves a numerical function constructed by fitting some data:

data := {{0, 1}, {1, 1}, {.2, 3}, {.4, 5}, {.6, 2}};
try[x_?NumberQ, y_?NumberQ] := (auy = y;
solution = FindFit[data, A (aux - auy) + B Exp[aux - auy], {A, B}, aux];
myFit[aux_?NumberQ] = (A (aux - auy) + B Exp[aux - auy]) /.
solution; Return[myFit[x]])

NSolve[y - try[1, y] == 0, y]


I tried with this code but it does not function (various errors). Does anyone know how to help me?

-
Did you even try to test call your try function? What happens when you type try[1, y] ? does not return anything? This is really strange that no body seems to do any testing of anything any more. – Nasser Dec 5 '13 at 11:55
I tried try[1,2] and it works. try[1,y] has not to return an output since it need numerical parameters to work. What I want is a way to solve the problem I described, i.e. using NSolve to solve the equation which involve a function numerically determined by a fit. My code obviously does not work, that's why I asked help. Does anyone knows how to solve my issue? I hope I clarified my post! – user9994 Dec 5 '13 at 12:44
I modified a little the example code above, now it should be more clear. – user9994 Dec 5 '13 at 13:40
Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dr. belisarius Dec 5 '13 at 15:34

data = {{0, 1}, {1, 1}, {.2, 3}, {.4, 5}, {.6, 2}};
try[x_?NumericQ, y_?NumericQ, data_] := (A (x - y) + B Exp[x - y]) /.
FindFit[data, A (xx - y) + B Exp[xx - y], {A, B}, xx]

FindRoot[y - try[1, y, data] == 0, {y, 1}]

(*
{y -> 1.78209}
*)

-
ok, this helps a lot: FindRoot is what I need. But I have to scal a big range of "y", right? Maybe with a Do[ ] statement. is there someway to optimize it?. Thank you for your help belisarius! – user9994 Dec 5 '13 at 15:17
Sorry, I don't understand your sentence But I have to scal a big range of "y", right?. Can you explain it further for me, please? – Dr. belisarius Dec 5 '13 at 15:37
I am really sorry, I had to write "scan" and not "scal". What I meant is that I have to search for solution in a range of ys to find more than one solution. – user9994 Dec 5 '13 at 16:34
@user9994 FindRoot should take care of that. Just try to give it a good initial guess – Dr. belisarius Dec 5 '13 at 16:45
But if I suspect the existence of different solutions I have to repeat the FindRoot with different intial guesses right? – user9994 Dec 5 '13 at 17:11