2
$\begingroup$

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?

thank you in advance!

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$ Commented Dec 5, 2013 at 11:55
  • $\begingroup$ 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! $\endgroup$ Commented Dec 5, 2013 at 12:44
  • $\begingroup$ I modified a little the example code above, now it should be more clear. $\endgroup$ Commented Dec 5, 2013 at 13:40
  • $\begingroup$ 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! $\endgroup$ Commented Dec 5, 2013 at 15:34

1 Answer 1

2
$\begingroup$
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} *) 
$\endgroup$
8
  • $\begingroup$ 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! $\endgroup$ Commented Dec 5, 2013 at 15:17
  • $\begingroup$ 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? $\endgroup$ Commented Dec 5, 2013 at 15:37
  • $\begingroup$ 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. $\endgroup$ Commented Dec 5, 2013 at 16:34
  • $\begingroup$ @user9994 FindRoot should take care of that. Just try to give it a good initial guess $\endgroup$ Commented Dec 5, 2013 at 16:45
  • $\begingroup$ But if I suspect the existence of different solutions I have to repeat the FindRoot with different intial guesses right? $\endgroup$ Commented Dec 5, 2013 at 17:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.