0
$\begingroup$

I have the following data which come from complex values but I have turned them into a 3D list

data = {{69.99953177570718`, 
0, -0.025744522093134253`}, {70.03297636805105`, 
0, -0.026096022893112664`}, {70.06642096039491`, 
0, -0.026491061585247853`}, {70.09986555273878`, 
0, -0.026870692405461784`}, {70.13331014508263`, 
0, -0.02725614247496281`}, {70.1667547374265`, 
0, -0.027651243861032286`}, {70.20019932977037`, 
0, -0.028084182760182538`}, {70.23364392211423`, 
0, -0.028528431525461015`}, {70.2670885144581`, 
0, -0.028948119236125947`}, {70.30053310680195`, 
0, -0.029381449064487798`}, {70.33397769914582`, 
0, -0.029802753837463378`}, {70.36742229148969`, 
0, -0.030267356415362847`}, {70.40086688383354`, 
0, -0.030768764283591758`}, {70.43431147617741`, 
0, -0.031262221983811025`}, {70.46775606852128`, 
0, -0.03175982310211329`}, {70.50120066086514`, 
0, -0.03225522326209402`}, {70.534645253209`, 
0, -0.03275672584260585`}, {70.56808984555286`, 
0, -0.03325512457159114`}, {70.60153443789673`, 
0, -0.03372124821795243`}, {70.6349790302406`, 
0, -0.0341742820098873`}, {70.66842362258446`, 
0, -0.034599405662390254`}, {70.70186821492833`, 
0, -0.03502086601578594`}, {70.7353128072722`, 
0, -0.03539387086013573`}, {70.76875739961605`, 
0, -0.03576022066067873`}, {70.80220199195992`, 
0, -0.036108296265796896`}, {70.83564658430377`, 
0, -0.036450148645763854`}, {70.86909117664764`, 
0, -0.03677894087261283`}, {70.90253576899151`, 
0, -0.03707076179036538`}, {70.93598036133537`, 
0, -0.03731001371656823`}, {70.96942495367924`, 
0, -0.037513065830907265`}, {71.0028695460231`, 
0, -0.03760681446309537`}, {71.03631413836696`, 
0, -0.037590868543063226`}, {71.06975873071083`, 
0, -0.03747858610374989`}, {71.10320332305469`, 
0, -0.0372736444255608`}, {71.13664791539856`, 
0, -0.03691592629456697`}, {71.17009250774242`, 
0, -0.03639088134489841`}, {71.20353710008628`, 
0, -0.03562782922682178`}, {71.23698169243015`, 
0, -0.0345728751364805`}, {71.270426284774`, 
0, -0.03321297349349256`}, {71.30387087711787`, 
0, -0.031516158794925975`}, {71.33731546946174`, 
0, -0.029391353028545175`}, {71.3707600618056`, 
0, -0.026739532863029894`}, {71.40420465414947`, 
0, -0.023474626625219878`}, {71.43764924649334`, 
0, -0.01942997008360923`}, {71.47109383883719`, 
0, -0.014572865166130464`}, {71.50453843118106`, 
0, -0.00876559398825993`}, {71.53798302352492`, 
0, -0.001949574004205181`}, {71.57142761586879`, 0, 
0.005953186737091857`}, {71.60487220821265`, 0, 
0.015092297643819462`}, {71.63831680055651`, 0, 
0.025611602375525292`}, {71.67176139290038`, 0, 
0.03779879272233194`}, {71.70520598524425`, 0, 
0.0519083958385179`}, {71.7386505775881`, 0, 
0.06815168175009662`}, {71.77209516993197`, 0, 
0.08663358931191116`}, {71.80553976227583`, 0, 
0.10732377820717295`}, {71.8389843546197`, 0, 
0.1299793515309767`}, {71.87242894696357`, 0, 
0.15390543292520428`}, {71.90587353930742`, 0, 
0.17772313546181254`}, {71.93931813165129`, 0, 
0.19880627818104268`}, {71.97276272399515`, 0, 
0.2133221766286071`}, {72.00620731633902`, 0, 
0.21656269284420898`}, {72.03965190868288`, 0, 
0.20540376906789018`}, {72.07309650102674`, 0, 
0.18170469732075528`}, {72.10654109337061`, 0, 
0.15273127649767282`}, {72.13998568571448`, 0, 
0.12616656524741818`}, {72.17343027805833`, 0, 
0.1056268951951019`}, {72.2068748704022`, 0, 
0.0910770660612257`}, {72.24031946274606`, 0, 
0.08104256372824307`}, {72.27376405508993`, 0, 
0.07403145064564912`}, {72.3072086474338`, 0, 
0.06898281792642444`}, {72.34065323977765`, 0, 
0.06515666556591491`}, {72.37409783212152`, 0, 
0.06207133049604567`}, {72.40754242446539`, 0, 
0.05941846705274501`}, {72.44098701680925`, 0, 
0.054771663890863395`}, {72.50787620149697`, 0, 
0.05256106407058292`}, {69.99953177570718`, 1, 
0.022747336936228612`}, {70.03297636805105`, 1, 
0.02330714609813221`}, {70.06642096039491`, 1, 
0.023890436011812385`}, {70.09986555273878`, 1, 
0.024502395119754314`}, {70.13331014508263`, 1, 
0.025155835565032095`}, {70.1667547374265`, 1, 
0.025819370635910426`}, {70.20019932977037`, 1, 
0.026527924232202897`}, {70.23364392211423`, 1, 
0.02724742536397416`}, {70.2670885144581`, 1, 
0.028050787168216927`}, {70.30053310680195`, 1, 
0.028886605414891343`}, {70.33397769914582`, 1, 
0.02973162804929779`}, {70.36742229148969`, 1, 
0.030637572737203106`}, {70.40086688383354`, 1, 
0.031573365242774015`}, {70.43431147617741`, 1, 
0.03259943987952048`}, {70.46775606852128`, 1, 
0.03368356989872898`}, {70.50120066086514`, 1, 
0.0348401846591094`}, {70.534645253209`, 1, 
0.03606479621946189`}, {70.56808984555286`, 1, 
0.03736980054666022`}, {70.60153443789673`, 1, 
0.03875170684773081`}, {70.6349790302406`, 1, 
0.04022543685884824`}, {70.66842362258446`, 1, 
0.041769841925792583`}, {70.70186821492833`, 1, 
0.04340012503834182`}, {70.7353128072722`, 1, 
0.04511267091238128`}, {70.76875739961605`, 1, 
0.04688700545182254`}, {70.80220199195992`, 1, 
0.04877243669761336`}, {70.83564658430377`, 1, 
0.05075188457710807`}, {70.86909117664764`, 1, 
0.052876090958610025`}, {70.90253576899151`, 1, 
0.05513007523529589`}, {70.93598036133537`, 1, 
0.057540555477338585`}, {70.96942495367924`, 1, 
0.060124692609713065`}, {71.0028695460231`, 1, 
0.06292063738909433`}, {71.03631413836696`, 1, 
0.065860030813157`}, {71.06975873071083`, 1, 
0.06896172020070988`}, {71.10320332305469`, 1, 
0.07228473388164294`}, {71.13664791539856`, 1, 
0.0758711420584936`}, {71.17009250774242`, 1, 
0.07967950866581495`}, {71.20353710008628`, 1, 
0.08379078880382645`}, {71.23698169243015`, 1, 
0.08815404761051107`}, {71.270426284774`, 1, 
0.09278269656908347`}, {71.30387087711787`, 1, 
0.09771474138236494`}, {71.33731546946174`, 1, 
0.10296230637603751`}, {71.3707600618056`, 1, 
0.10849663556359272`}, {71.40420465414947`, 1, 
0.11436941344597638`}, {71.43764924649334`, 1, 
0.12044996812755461`}, {71.47109383883719`, 1, 
0.12668683915038279`}, {71.50453843118106`, 1, 
0.13303125730031395`}, {71.53798302352492`, 1, 
0.13935700284203958`}, {71.57142761586879`, 1, 
0.1455789057471541`}, {71.60487220821265`, 1, 
0.15162113764026355`}, {71.63831680055651`, 1, 
0.15739522346193952`}, {71.67176139290038`, 1, 
0.1626655708780882`}, {71.70520598524425`, 1, 
0.16711121737806825`}, {71.7386505775881`, 1, 
0.17018715715752225`}, {71.77209516993197`, 1, 
0.17123786438400365`}, {71.80553976227583`, 1, 
0.1694135841124713`}, {71.8389843546197`, 1, 
0.16365822375910047`}, {71.87242894696357`, 1, 
0.15259558014603813`}, {71.90587353930742`, 1, 
0.13479173712907516`}, {71.93931813165129`, 1, 
0.10903234595051295`}, {71.97276272399515`, 1, 
0.0752851545505797`}, {72.00620731633902`, 1, 
0.036027850250854365`}, {72.03965190868288`, 
1, -0.002568255489183948`}, {72.07309650102674`, 
1, -0.03249636392137085`}, {72.10654109337061`, 
1, -0.04896947881038323`}, {72.13998568571448`, 
1, -0.05356835059591255`}, {72.17343027805833`, 
1, -0.0512069020634594`}, {72.2068748704022`, 
1, -0.04616103378440534`}, {72.24031946274606`, 
1, -0.04080912989267955`}, {72.27376405508993`, 
1, -0.036114354028818074`}, {72.3072086474338`, 
1, -0.03229986317971496`}, {72.34065323977765`, 
1, -0.029373869772167445`}, {72.37409783212152`, 
1, -0.027195053221098844`}, {72.40754242446539`, 
1, -0.025619743360851256`}, {72.44098701680925`, 
1, -0.024460634510870854`}, {72.47443160915311`, 
1, -0.023636063490023798`}, {72.50787620149697`, 
1, -0.023030174222614226`}}

I have an expensive model which I wish to fit to this data. I have put a print in the module so that I can see what values NonlinearModelFit is trying.

ClearAll[model];
model[x0_?NumberQ, v0_?NumberQ, r_?NumberQ, z_?NumberQ] := Module[
{sr = 5000, nn = 149501, n1 = 2094, n2 = 2169, sol, x, t, acc, a, 
ff, fun},
Print[{x0, v0, r, z}];
sol = NDSolve[{x''[t] + 2 z 2 \[Pi] r x'[t] + (2 \[Pi] r)^2 x[t] == 
  0, x[0] == x0, x'[0] == v0}, {x''[t]}, {t, 0, nn/sr}];
  acc = Head[x''[t] /. First[sol]];
  a = Fourier[Table[acc[t], {t, 0, (nn - 1)/sr, 1/sr}], 
 FourierParameters -> {-1, -1}][[n1 ;; n2]];

 ff = Table[N[(n - 1) sr/nn], {n, n1, n2, 1}];

 fun = Quiet@
 Interpolation[
 Flatten[Table[{{{ff[[n]], 0}, Re[a[[n]]]}, {{ff[[n]], 1}, 
     Im[a[[n]]]}}, {n, Length[ff]}], 1]];
 fun
 ]

If I plot the data and the model I can see that they are similar but that the model needs tuning.

Show[ListPlot3D[data], 
 Plot3D[Evaluate[model[-0.0001, 0.000001, 71.97, 0.003][x, y]], {x, 
 data[[1, 1]], data[[-1, 1]]}, {y, 0, 1}]]

Mathematica graphics

Now I try NonlinearModelFit hoping it will find good values but I can see from my print statement it just keeps going with the starting values. Why is it not hunting for good values? Thanks for your assistance.

ans = NonlinearModelFit[data, 
 model[x0, v0, r, z][x, y],
 {{x0, -0.0001}, {v0, 0.000001}, {r, 71.97}, {z, 0.003}}, {x, y}]
$\endgroup$
  • $\begingroup$ your model doesn't work for me at all..(returns a interpolating function that is essentially zero everywhere ). You may want to check if what you posted is correct. $\endgroup$ – george2079 Feb 2 '15 at 17:11
  • $\begingroup$ @george2079 Thanks for looking. I have just copied the post into a new notebook and it works fine for me. I am using version 10. Typing model[-0.0001, 0.000001, 71.97, 0.003][70, 1] returns 0.0269218 as well as the output from the Print statement. What version are you using? Although I don't think there are any special version 10 commands. $\endgroup$ – Hugh Feb 2 '15 at 21:25
  • $\begingroup$ v 9 here. NDSolve throws an accuracy warning. $\endgroup$ – george2079 Feb 2 '15 at 22:30
  • $\begingroup$ @george2079 I went back to v9 and got a Maximum number of 10000 steps reached. I then increased the MaxSteps to 50000 and I could plot the model. The fit still does not hunt for values. Don't know what all this implies. Can you make a guess? Thanks $\endgroup$ – Hugh Feb 2 '15 at 23:05

Your Answer

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

Browse other questions tagged or ask your own question.