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:


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

Does anyone have any idea?

I use Mathematica 8.


1 Answer 1


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) *)

  • $\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
    Commented Mar 23, 2014 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
    Commented Mar 23, 2014 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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