Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
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? –  mattiav27 Mar 23 at 19:49
    
@mattiav27 yes but if you wish I could write it as: (ys-Log[a + b xs^2]).wghts.(ys-Log[a + b xs^2]) –  chris Mar 23 at 19:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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