1
$\begingroup$

It became quite clear after running this a few times that my syntax is wrong, but I can't parse out why. Anybody know of a better way to write this?

myFit = 
  FindFit[XData, a PDF[CauchyDistribution[CONST, b], x], {{a, 100}, {b, 100}}, x];

a = myFit[[All, 2]][[1]]
b = myFit[[All, 2]][[2]]

I'm fitting a cauchy distribution function to some data which gives the list of rules:

{a -> **, b -> **}

But when I try to set the variables a and b to the values from the rules, it starts freaking out. Can I do this? I know about the evaluation idea of /., but I haven't been able to figure out how to use that to obtain variables with these values.

This gives a recursion depth exceeded message and takes up a lot of space, running away for reasons I don't quite understand.

$\endgroup$
  • $\begingroup$ Fit is a built-in function; use fit. It's safest to use always names starting with a lowercase letter for user-defined commands/variables/etc. $\endgroup$ – corey979 Oct 6 '16 at 20:48
  • $\begingroup$ thanks I fixed that. It was called lorentzFit in my code but I switched it for ease of reading. changed to myFit $\endgroup$ – chase Oct 6 '16 at 20:52
  • $\begingroup$ I think you might want FindDistributionParameters, but without a minimal working example not much can be told. Please provide CONST and (at least exemplary) XData. $\endgroup$ – corey979 Oct 6 '16 at 20:59
  • $\begingroup$ To use the rules without setting the values of the variables. f[a,b] /. rules To assign the values to the variables: Clear[a, b]; {a, b} = {a, b} /. rules or use Clear[a, b]; rules /. Rule -> Set $\endgroup$ – Bob Hanlon Oct 6 '16 at 21:49
  • $\begingroup$ actually what you did is just fine (not the best approach but it works). I suppose it "freaks out" if you try to re evaluate FindFit after giving a,b values. You can put Clear[a,b] before FindFit to take care of that. $\endgroup$ – george2079 Oct 7 '16 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.