1

I was trying NonLinearModelFit by mathematica.. The data should include something as

Exp[-ax]Sin[bx]......But I can't get the proper fitting curve(parameter)..

Original programs were listed below..

data = {{0, 0.8156862745098039`}, {5/21, 0.5163398692810458`}, {10/21,
 0.20784313725490197`}, {5/7, 0.052941176470588235`}, {20/21, 
0.0363921568627451`}, {25/21, 0.11776589423648247`}, {10/7, 
0.18943355119825708`}, {5/3, 0.1329847494553377`}, {40/21, 
0.04635294117647058`}, {15/7, 0.022294843863471313`}, {50/21, 
0.05026737967914438`}, {55/21, 0.08732806555458003`}, {20/7, 
0.08406234288587229`}, {65/21, 0.04240196078431373`}, {10/3, 
0.010288350634371396`}, {25/7, 0.005962384953981593`}, {80/21, 
0.0145602795573675`}, {85/21, 0.023162910023822612`}, {30/7, 
0.019077901430842606`}, {95/21, 0.007103825136612022`}, {100/21, 
0.002007843137254902`}, {5, 0.0046875`}, {110/21, 
0.009488550665021253`}, {115/21, 0.011350455675227838`}, {40/7, 
0.007381776239907728`}, {125/21, 0.0025227925565130507`}, {130/21,
 0.001340282948622487`}, {45/7, 0.002856171370282217`}, {20/3, 
0.004392156862745098`}, {145/21, 0.003963510537905002`}, {50/7, 
0.0024745727167872498`}, {155/21, 0.0011558307533539732`}, {160/
21, 0.0014921090387374463`}, {55/7, 0.0025759323337178008`}, {170/
21, 0.0030401151286202554`}, {25/3, 0.0023312550826782323`}, {60/
7, 0.0012677484787018255`}, {185/21, 
0.0015068990559186637`}, {190/21, 0.002007693029364856`}, {65/7, 
0.0024161323297091346`}, {200/21, 0.0024937154348919056`}, {205/
21, 0.0016575702445926822`}, {10, 0.0015728216420257944`}, {215/
21, 0.0020161737011188657`}, {220/21, 0.002557544757033248`}, {75/
7, 0.0030375155842683895`}, {230/21, 
0.0031632542519770337`}, {235/21, 0.002895576835385317`}, {80/7, 
0.0033217993079584776`}, {35/3, 0.0034982174688057044`}, {250/21, 
0.004`}, {85/7, 0.003390830016217013`}, {260/21, 
0.003701667582921019`}, {265/21, 0.004117647058823529`}, {90/7, 
0.004841442749939482`}, {275/21, 0.0046199301638463605`}, {40/3, 
0.004551820728291316`}, {95/7, 0.004470588235294118`}, {290/21, 
0.005930176948828312`}, {295/21, 0.005186590765338393`}, {100/7, 
0.004108309990662932`}, {305/21, 0.0024132730015082957`}, {310/21,
 0.0028011204481792717`}, {15, 0.`}};
ListLinePlot[data, PlotRange -> All]

enter image description here

Then I did the Fitting by

fit = NonlinearModelFit[data,0.8 Exp[-t*r] Sin[4.5 (r + b)] + d, {t, b, d}, r];

Anyway the result always not well fitted.. as follows:

enter image description here

I am sure the model should conclude something as

Exp[-ax]Sin[kx]

Should I modify the model or something? How can I get better fitted curves?

Any suggestions or helps are welcomed.

Cici
  • 65
  • 6
  • 2
    Tag this question with the appropriate language. I saw it, checked the tags, and thought "well... what are you even working with to begin with?". – mr.stobbe Jan 16 '15 at 08:43
  • 1
    Also, secondary thought, this right off the bat seems more appropriate at [statexchange](http://stats.stackexchange.com/). Move for migration. – mr.stobbe Jan 16 '15 at 08:45
  • Okay, I see by [this](http://stackoverflow.com/questions/27812393/detailed-calculation-of-rgb-to-graylevel-by-mathematica) that you are new to the stackexchange concept. It's fantastic that you're seeking advice from others but, tips. First, tag your question with at, the bare minimum, the language in question. If it's mathmatica, then that should be tagged. Second, mark the answer as an answer. After thanking them so much why didn't you mark their answer (in the previously linked question) as the answer? Mark it as the answer if that's what it is. (continued below). – mr.stobbe Jan 16 '15 at 09:41
  • 2
    Finally, continue to respond to your own question. If you figure something out, don't just abandon your own question. Tell people you figured it out and how you did it! Answering your own question is a good thing, especially if it's the correct answer. If someone asks a question or makes a comment, you should respond. Otherwise your question dies and all those seeking the same knowledge as you (remember, sites like this aren't just about you getting answers, but everyone else as well) will be at the same loss. – mr.stobbe Jan 16 '15 at 09:43
  • Thank U for all the suggestions.U R so great..I will follow all of them..I have to say I am fresh in this forum... – Cici Jan 16 '15 at 15:28
  • 1
    This appears to be not so much a programming question as a matter of finding the right fitting function. Do you have some physics reason to think it should fit that form? ( Looks more like `Exp[-r] ( a + b Sin[ c r ] )` to my eye ) – agentp Jan 16 '15 at 16:49
  • Aha~~~I think U R right..I am sure the fitting function should include something like Exp[-ax] & Sin[kx]..but it should be modified to some extent..I think U've already gave out more reasonable model for the curve..Thank U so much – Cici Jan 16 '15 at 17:06
  • 1
    Strongly related Wolfram community thread: "[Find Fit for Nonlinear Data](http://community.wolfram.com/groups/-/m/t/224105)". – Alexey Popkov Jun 06 '15 at 11:17

1 Answers1

1

This can be done easily with the Quantile regression with B-splines package by Anton Antonov (direct link to the M-file):

Needs["QuantileRegression`"]

qfunc = QuantileRegression[data, data[[;; , 1]], {0.5}, 
     InterpolationOrder -> 2][[1]]; // Quiet

Plot[qfunc[x], {x, Min[data[[All, 1]]], Max[data[[All, 1]]]}, 
 Frame -> True, PlotStyle -> Red, Prolog -> Point[data], 
 PlotLabel -> "Comparison of the model with original data", 
 Exclusions -> None, PlotRange -> All]
ListPlot[data[[;; , 2]] - qfunc /@ data[[;; , 1]], PlotRange -> All, 
 Filling -> Axis, 
 PlotLabel -> "Differences between the original data and the model"]

plot1 plot2

Alexey Popkov
  • 9,355
  • 4
  • 42
  • 93