How to fit data to a convolution equation:

m1data = Import["http://pastebin.com/raw/GckJAgpY", "Table"];
m2data = Import["http://pastebin.com/raw/5HvwSg7i", "Table"];
ListLinePlot[{m1data,m2data},PlotRange-> All]

enter image description here

Objective function:

m2[t] == m1[t] + a1*Integrate[m1[tau]*Exp[-a2 (t - tau)], {tau, 0, t}]

Is it possible to estimate a1 and a2 from the data?

  • $\begingroup$ You mean without proposing a model for m1data? $\endgroup$ – Dr. belisarius Dec 31 '15 at 2:26
  • $\begingroup$ @Dr.belisarius not sure, we have input and output data, can it be possible. I will try to add the model for m1data. $\endgroup$ – Johan Dec 31 '15 at 2:32
  • $\begingroup$ Do you mean m1[tau] or m1[t] ? If the former, do you not need to give the definition of m1[tau] in the solution of the ODE ? $\endgroup$ – JimB Dec 31 '15 at 4:53
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Dr. belisarius Dec 31 '15 at 5:15

I wasn't sure how to set it up with the standard fit functions, so I just rolled my own least squares. (It probably can be done, but I had an inkling I might want to have greater control over the computation. I hope it helps.)

I start by defining m1 and m2 on your data:

Clear[m1, m2];
(m1[t_] /; t == First@# = Last@#) & /@ m1data;
(m2[t_] /; t == First@# = Last@#) & /@ m2data;

Then I defined the convolution, using the trapezoid rule and based on a consisted delta t of 0.1 in both data sets.

SetAttributes[ni, Listable];
ni[0. | 0, _] := 0.;
mem : ni[t_?NumericQ, a2_?NumericQ] := mem = Quiet[
   NIntegrate[m1[tau]*Exp[-a2 (t - tau)], {tau, 0, t}, 
    Method -> {"TrapezoidalRule", "Points" -> 1 + Round[t/0.1]}, 
    MaxRecursion -> 0],

The objective function is the sum of squares of the residuals the solution to your ODE. This is to be minimized.

obj = m2[t] - (m1[t] + a1*ni[t, a2]) /. {m1[t] -> m1data[[All, 2]], 
     m2[t] -> m2data[[All, 2]], t -> m1data[[All, 1]]} // #.# &;

The value for a1 is consistent, but the model is not very sensitive to a2. It's always a big value, which suggests only t = tau is contributing much to the convolution.

FindMinimum[obj, {{a1, -1.}, {a2, 100}}]
(*  {1.20002, {a1 -> -20.173, a2 -> 266.816}}  *)

FindMinimum[obj, {{a1, -13.}, {a2, 1550}}]
(*  {1.20002, {a1 -> -20.173, a2 -> 1550.}}  *)

FindMinimum[obj, {{a1, -20.}, {a2, 50}}]
(*  {1.20002, {a1 -> -20.173, a2 -> 2250.22}}  *)

FindMinimum[obj2, {{a1, -53.}, {a2, 4500}}]
(*  {1.20002, {a1 -> -20.173, a2 -> 4500.}}  *)

Note: The trapezoid rule in NIntegrate uses Romberg quadrature. If you turn it off, then a1 is consistently -13.4487 and a2 is very large just as before.


Your Answer

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

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