2
$\begingroup$

I have to fit a non linear model to my data and I am trying to use NonlinearModelFit. The problem is that I have systematic errors, so the weights options is not a simple vector but a matrix.

To be clear: my chi squared is written as:

(diff)T*(weight)^(-1)*(diff)

Where diff is the difference between my model and the data (T means trasposed).

Does anyone have any idea?

I use Mathematica 8.

$\endgroup$
1
$\begingroup$

You could do the NonlinearModelFit yourself? Following the example in the documentation:

Starting with the data

 data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}, {6, 4}, {7, 5}};

Extracting the ys, and xs

 ys = Last /@ data;xs = First /@ data;

Defining some ad hoc weights

wghts = Table[Exp[-(i - j)^2/8.], {i, Length[ys]}, {j, Length[ys]}]

Let us define the corresponding χ2

  χ2 = (ys-Log[a + b xs^2]).wghts.(ys-Log[a + b xs^2]);

And carry out the optimization

NMinimize[{ χ2, a > 0, b > 0}, {a, b}]

(* {0.782788,{a->0.825214,b->1.59388}} *)

to be compared to the NonlinearModelFit solution

 NonlinearModelFit[data, Log[a + b x^2], {a, b}, x] // Normal

(* log(1.42633 x^2+1.50632) *)

$\endgroup$
  • $\begingroup$ Thank you for you answer, but I don't get your definition of the chi square. I am sorry to ask but: are you sure? $\endgroup$ – mattiav27 Mar 23 '14 at 19:49
  • $\begingroup$ @mattiav27 yes but if you wish I could write it as: (ys-Log[a + b xs^2]).wghts.(ys-Log[a + b xs^2]) $\endgroup$ – chris Mar 23 '14 at 19:55

Your Answer

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

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