Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently trying to fit Planck's law (B[λ, T]) to measurements, thereby determining Planck's constant.

I have a list of triplets containing wavelength, temperature and measured intensity and a list of triplets with their errors, like:

datalist  = {{λ1, T1, B1}, {λ2, T2, B2}, ...}    
errorlist = {{σλ1, σT1, σB1}, {σλ2, σT2, σB2}, ...}

Although NonlinearModelFit can fit functions of the type R2 → R, it seems to only accept a one dimensional list as Weights. This is what I tried:

NonlinearModelFit[datalist, B[λ, T], {{h, hlit}}, {λ,T}, Weights -> (errorlist)^-2]

I could of course propagate the partial uncertainties to create one uncertainty for each triplet, thereby have a one dimensional Weights list instead, but it seems a bit unethic.

Would it be possible to fit Planck's curve to my measurements without having to combine the errors first?

Edit: Here's the exact error message that I get:

NonlinearModelFit::wts: The value of option Weights -> {{100.,100.,2500.},{11.1111,25.,25.},{11.1111,2.77778,11.1111}} should be a list of real numbers or a pure function. >>

(I used this data and function as an example:

share|improve this question
please post a link to your data and error? – chris Jun 5 '13 at 20:32
Hi chris, I've included the error message and some example data in the original post. (I'm actually fitting the ratio of two Planck functions, so included an example function to keep things simple.) – Blue Jun 5 '13 at 21:27
it seems this works: NonlinearModelFit[datalist, F[x, y], {{a, 2}}, {x, y} , Weights -> Last/@(errorlist)] but may be you want errors in x and y as well? – chris Jun 5 '13 at 21:30
Yes, i would like to include all the uncertainties. If plotted, it would look like every data point is surrounded by a cube, instead of a line normal to the λT-plane. – Blue Jun 5 '13 at 21:56
What I have done in the past is simply to multiply the reciprocal variances in the abscissa and the ordinate together and use that as a weight. Of course, that is not strictly correct, but it will be a reasonable approximation if the residuals are small. If you want it done strictly correctly (i.e. through total least squares), NonlinearModelFit can't help you--you'll have to code it yourself. – Oleksandr R. Jun 6 '13 at 4:10

Your Answer


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

Browse other questions tagged or ask your own question.