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 got a problem in my program with NonlinearModelFit:

datan = Take[data, {1, 350}, {1, 1}];
mn =  939.565;

hbarc = 2*(197.33)^2;

datak = Sqrt[mn*datan/hbarc];

datadephasage = Take[data, {1, 350}, {2, 2}];

datanew = Join[datak, datadephasage, 2]

nlm1 = NonlinearModelFit[datanew, ((-ArcTan[x/a]*180/Pi) - (ArcTan[x/b]*180/Pi) -(ArcTan[x/c]*180/Pi) - (ArcTan[x/d]*180/Pi) - (ArcTan[x/e]*180/Pi)), {a, b, c, d, e}, x];

I get the error in the title of my post.

If you wan to test my values,

datanew = {{0., 0.}, {0.0109839, 14.551}, {0.0155335, 20.5526}, {0.0190246, 
  23.7734}, {0.0219677, 26.9133}, {0.0245607, 29.7561}, {0.0269049, 
  32.0505}, {0.0290606, 33.9131}, {0.0310671, 35.5476}, {0.0329516, 
  37.0554}, {0.034734, 38.4352}, {0.0364294, 39.6848}, {0.0380492, 
  40.8166}, {0.0396029, 41.8463}, {0.0410979, 42.7896}, {0.0425403, 
  43.6624}, {0.0439355, 44.4783}, {0.0452876, 45.2432}, {0.0466006, 
  45.9605}, {0.0478776, 46.6338}, {0.0491214, 47.2669}, {0.0503344, 
  47.8631}, {0.0515189, 48.4255}, {0.0526768, 48.9567}, {0.0538097, 
  49.4595}, {0.0549193, 49.9368}, {0.056007, 50.3911}, {0.0570739, 
  50.8239}, {0.0581212, 51.2366}, {0.0591499, 51.6305}, {0.0601611, 
  52.0069}, {0.0611556, 52.3671}, {0.0621341, 52.712}, {0.0630975, 
  53.0425}, {0.0640464, 53.3596}, {0.0649814, 53.6641}, {0.0659032, 
  53.9569}, {0.0668123, 54.2386}, {0.0677091, 54.5098}, {0.0685942, 
  54.771}, {0.0694681, 55.0228}, {0.0703311, 55.2658}, {0.0711836, 
  55.5003}, {0.072026, 55.7268}, {0.0728587, 55.9457}, {0.073682, 
  56.1574}, {0.0744962, 56.3622}, {0.0753016, 56.5605}, {0.0760985, 
  56.7525}, {0.0768871, 56.9385}, {0.0776677, 57.1188}, {0.0784405, 
  57.2937}, {0.0792058, 57.4634}, {0.0799638, 57.6281}, {0.0807146, 
  57.788}, {0.0814585, 57.9434}, {0.0821957, 58.0943}, {0.0829264, 
  58.241}, {0.0836506, 58.3837}, {0.0843687, 58.5225}, {0.0850807, 
  58.6575}, {0.0857868, 58.7889}, {0.0864871, 58.9168}, {0.0871817, 
  59.0414}, {0.0878709, 59.1628}, {0.0885548, 59.2811}, {0.0892334, 
  59.3964}, {0.0899068, 59.5088}, {0.0905753, 59.6183}, {0.0912389, 
  59.7252}, {0.0918976, 59.8295}, {0.0925517, 59.9313}, {0.0932012, 
  60.0306}, {0.0938462, 60.1276}, {0.0944868, 60.2222}, {0.0951231, 
  60.3147}, {0.0957551, 60.405}, {0.096383, 60.4933}, {0.0970069, 
  60.5795}, {0.0976268, 60.6638}, {0.0982427, 60.7462}, {0.0988548, 
  60.8267}, {0.0994632, 60.9055}, {0.100068, 60.9825}, {0.100669, 
  61.0579}, {0.101266, 61.1316}, {0.10186, 61.2037}, {0.102451, 
  61.2743}, {0.103038, 61.3434}, {0.103622, 61.411}, {0.104202, 
  61.4772}, {0.104779, 61.542}, {0.105354, 61.6054}, {0.105925, 
  61.6676}, {0.106493, 61.7285}, {0.107058, 61.7881}, {0.107619, 
  61.8465}, {0.108179, 61.9037}, {0.108735, 61.9598}, {0.109288, 
  62.0148}, {0.109839, 62.0686}, {0.110387, 62.1214}, {0.110932, 
  62.1732}, {0.111474, 62.2239}, {0.112014, 62.2737}, {0.112551, 
  62.3224}, {0.113086, 62.3703}, {0.113618, 62.4171}, {0.114148, 
  62.4631}, {0.114675, 62.5082}, {0.1152, 62.5525}, {0.115722, 
  62.5959}, {0.116242, 62.6384}, {0.11676, 62.6802}, {0.117276, 
  62.7212}, {0.117789, 62.7614}, {0.1183, 62.8008}, {0.118809, 
  62.8395}, {0.119315, 62.8775}, {0.11982, 62.9148}, {0.120322, 
  62.9514}, {0.120823, 62.9873}, {0.121321, 63.0226}, {0.121817, 
  63.0572}, {0.122311, 63.0911}, {0.122803, 63.1245}, {0.123294, 
  63.1572}, {0.123782, 63.1893}, {0.124268, 63.2209}, {0.124753, 
  63.2518}, {0.125235, 63.2822}, {0.125716, 63.3121}, {0.126195, 
  63.3414}, {0.126672, 63.3702}, {0.127147, 63.3984}, {0.127621, 
  63.4262}, {0.128093, 63.4534}, {0.128563, 63.4802}, {0.129031, 
  63.5064}, {0.129498, 63.5322}, {0.129963, 63.5575}, {0.130426, 
  63.5824}, {0.130888, 63.6068}, {0.131348, 63.6308}, {0.131806, 
  63.6544}, {0.132263, 63.6775}, {0.132719, 63.7002}, {0.133172, 
  63.7225}, {0.133625, 63.7444}, {0.134075, 63.7659}, {0.134524, 
  63.787}, {0.134972, 63.8078}, {0.135418, 63.8281}, {0.135863, 
  63.8481}, {0.136306, 63.8677}, {0.136748, 63.887}, {0.137188, 
  63.9059}, {0.137627, 63.9245}, {0.138065, 63.9428}, {0.138501, 
  63.9607}, {0.138936, 63.9783}, {0.13937, 63.9955}, {0.139802, 
  64.0125}, {0.140233, 64.0291}, {0.140662, 64.0454}, {0.14109, 
  64.0615}, {0.141517, 64.0772}, {0.141943, 64.0926}, {0.142367, 
  64.1078}, {0.14279, 64.1227}, {0.143212, 64.1372}, {0.143633, 
  64.1516}, {0.144052, 64.1656}, {0.14447, 64.1794}, {0.144887, 
  64.1929}, {0.145303, 64.2062}, {0.145717, 64.2192}, {0.146131, 
  64.232}, {0.146543, 64.2445}, {0.146954, 64.2568}, {0.147364, 
  64.2688}, {0.147773, 64.2806}, {0.14818, 64.2922}, {0.148587, 
  64.3036}, {0.148992, 64.3147}, {0.149397, 64.3256}, {0.1498, 
  64.3363}, {0.150202, 64.3468}, {0.150603, 64.357}, {0.151003, 
  64.3671}, {0.151402, 64.3769}, {0.1518, 64.3866}, {0.152197, 
  64.396}, {0.152593, 64.4053}, {0.152988, 64.4143}, {0.153381, 
  64.4232}, {0.153774, 64.4319}, {0.154166, 64.4404}, {0.154557, 
  64.4487}, {0.154947, 64.4568}, {0.155335, 64.4648}, {0.155723, 
  64.4725}, {0.15611, 64.4801}, {0.156496, 64.4876}, {0.156881, 
  64.4948}, {0.157265, 64.5019}, {0.157648, 64.5089}, {0.15803, 
  64.5157}, {0.158412, 64.5223}, {0.158792, 64.5287}, {0.159171, 
  64.535}, {0.15955, 64.5412}, {0.159928, 64.5472}, {0.160304, 
  64.553}, {0.16068, 64.5587}, {0.161055, 64.5643}, {0.161429, 
  64.5697}, {0.161802, 64.575}, {0.162175, 64.5801}, {0.162546, 
  64.5851}, {0.162917, 64.59}, {0.163287, 64.5947}, {0.163656, 
  64.5993}, {0.164024, 64.6038}, {0.164391, 64.6081}, {0.164758, 
  64.6123}, {0.165124, 64.6164}, {0.165489, 64.6203}, {0.165853, 
  64.6242}, {0.166216, 64.6279}, {0.166579, 64.6315}, {0.16694, 
  64.635}, {0.167301, 64.6383}, {0.167661, 64.6416}, {0.168021, 
  64.6447}, {0.16838, 64.6477}, {0.168737, 64.6506}, {0.169094, 
  64.6534}, {0.169451, 64.6561}, {0.169806, 64.6587}, {0.170161, 
  64.6612}, {0.170515, 64.6635}, {0.170869, 64.6658}, {0.171222, 
  64.668}, {0.171574, 64.67}, {0.171925, 64.672}, {0.172275, 
  64.6739}, {0.172625, 64.6756}, {0.172974, 64.6773}, {0.173323, 
  64.6789}, {0.17367, 64.6804}, {0.174017, 64.6818}, {0.174363, 
  64.6831}, {0.174709, 64.6843}, {0.175054, 64.6854}, {0.175398, 
  64.6864}, {0.175742, 64.6874}, {0.176085, 64.6883}, {0.176427, 
  64.689}, {0.176769, 64.6897}, {0.17711, 64.6903}, {0.17745, 
  64.6908}, {0.177789, 64.6913}, {0.178128, 64.6916}, {0.178467, 
  64.6919}, {0.178804, 64.6921}, {0.179141, 64.6923}, {0.179478, 
  64.6923}, {0.179814, 64.6923}, {0.180149, 64.6922}, {0.180483, 
  64.692}, {0.180817, 64.6917}, {0.181151, 64.6914}, {0.181483, 
  64.691}, {0.181815, 64.6906}, {0.182147, 64.69}, {0.182478, 
  64.6894}, {0.182808, 64.6887}, {0.183138, 64.688}, {0.183467, 
  64.6872}, {0.183795, 64.6863}, {0.184123, 64.6854}, {0.184451, 
  64.6844}, {0.184777, 64.6833}, {0.185103, 64.6821}, {0.185429, 
  64.6809}, {0.185754, 64.6797}, {0.186079, 64.6783}, {0.186402, 
  64.677}, {0.186726, 64.6755}, {0.187049, 64.674}, {0.187371, 
  64.6724}, {0.187692, 64.6708}, {0.188014, 64.6691}, {0.188334, 
  64.6674}, {0.188654, 64.6656}, {0.188974, 64.6637}, {0.189293, 
  64.6618}, {0.189611, 64.6599}, {0.189929, 64.6579}, {0.190246, 
  64.6558}, {0.190563, 64.6537}, {0.190879, 64.6515}, {0.191195, 
  64.6492}, {0.19151, 64.647}, {0.191825, 64.6446}, {0.192139, 
  64.6423}, {0.192453, 64.6398}, {0.192766, 64.6373}, {0.193079, 
  64.6348}, {0.193391, 64.6322}, {0.193703, 64.6296}, {0.194014, 
  64.6269}, {0.194324, 64.6242}, {0.194635, 64.6214}, {0.194944, 
  64.6186}, {0.195254, 64.6158}, {0.195562, 64.6128}, {0.19587, 
  64.6099}, {0.196178, 64.6069}, {0.196485, 64.6039}, {0.196792, 
  64.6008}, {0.197098, 64.5977}, {0.197404, 64.5945}, {0.19771, 
  64.5913}, {0.198014, 64.588}, {0.198319, 64.5847}, {0.198623, 
  64.5814}, {0.198926, 64.578}, {0.199229, 64.5746}, {0.199532, 
  64.5712}, {0.199834, 64.5677}, {0.200136, 64.5641}, {0.200437, 
  64.5606}, {0.200738, 64.557}, {0.201038, 64.5533}, {0.201338, 
  64.5496}, {0.201637, 64.5459}, {0.201936, 64.5421}, {0.202234, 
  64.5384}, {0.202533, 64.5345}, {0.20283, 64.5307}, {0.203127, 
  64.5268}, {0.203424, 64.5228}, {0.20372, 64.5189}, {0.204016, 
  64.5149}, {0.204312, 64.5108}, {0.204607, 64.5067}, {0.204901, 
  64.5026}, {0.205196, 64.4985}}

I know from Matlab (another program) that some good parameter {a, b, c, d, e} I search with the "NonlinearModelFit tool" are {-0.04,-0.75,4.16,0.61,2.04}.

But can you please tell me why I cannot find something in Mathematica?

Thank you for your time and sorry for my bad english :)

Like this

nlm2 = NonlinearModelFit[
datanew, -(ArcTan[x/a] + ArcTan[x/b] + ArcTan[x/c] + ArcTan[x/d] + 
ArcTan[x/e]) 180/Pi, {a, {b, 2.04}, {c, -0.043717}, d, e}, x]

And then like this

nlm2[{ "BestFit", "BestFitParameters", "ParameterTable", "RSquared", 
"AdjustedRSquared", "AIC", "BIC"}]

the section BestFitParameters of the output give me good results.

but it is because I knew some values (2.04 and -0.04) before from MATLAB so how can I do this with only Mathematica?

share|improve this question
    
Did you try to just increase the number of allowed iterations using the option MaxIterations? For example: nlm1 = NonlinearModelFit[datanew, ((-ArcTan[x/a]*180/Pi) - (ArcTan[x/b]*180/Pi) -(ArcTan[x/c]*180/Pi) - (ArcTan[x/d]*180/Pi) - (ArcTan[x/e]*180/Pi)), {a, b, c, d, e}, x,MaxIterations->200]; –  celtschk Oct 5 '12 at 7:13

1 Answer 1

Perhaps you have too many parameters:

model = -(ArcTan[x/c] + ArcTan[x/d] + ArcTan[x/e]) 180/Pi; 
nlm1 = FindFit[datanew, {model}, {c, d, e}, x];
Show[ListPlot[datanew, PlotStyle -> Red], Plot[model /. nlm1, {x, 0, .2}], PlotRange -> All]

{c -> 0.704089, d -> -0.0400201, e -> -6.58175}

Mathematica graphics

Edit

With your full dataset post at ideone:

nlm1 = FindFit[datanew, {model}, {a, b, c, d, e}, x];
Show[ListPlot[datanew, PlotStyle -> {Red, PointSize[.001]}], 
     Plot[model /. nlm1, {x, 0, 2}], PlotRange -> All]

Mathematica graphics

Edit

Run this command to load the evaluating notebook, including the data

 NotebookPut@ImportString[Uncompress@FromCharacterCode@Flatten@ImageData[Import@
             "http://i.stack.imgur.com/XR9A2.png","Byte"],"NB"]
share|improve this answer
    
Less is more +1 –  Matariki Oct 5 '12 at 1:29
    
Thank for your help , but the data I gave you are just the first values of a very long list and I cannot make it work. Any other sugestion? –  Maxime de prins Oct 5 '12 at 3:01
    
@Maximedeprins Upload your dataset to ideone.com (for example) –  belisarius Oct 5 '12 at 3:30
    
ideone.com/GpvH0 for the first part of datanew –  Maxime de prins Oct 5 '12 at 3:48
    
and ideone.com/vnXmm for the segond part, be carfull went you join them. thank again –  Maxime de prins Oct 5 '12 at 3:49

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.