MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Summation of imported data

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118914] Re: Summation of imported data
  • From: Peter <petsie at dordos.net>
  • Date: Sun, 15 May 2011 07:06:16 -0400 (EDT)
  • References: <iqla6j$a10$1@smc.vnet.net>

Am 14.05.2011 09:15, schrieb Thomas:
> I know what I want to do but I dont know how to implement it onto Mathematica.
>
> What I am trying to do is create an objective function that I can get a good fit to my data points.
>
> The function I want to minimize is:
>   Cstardiff[t_, De_, dprime_] := 1 - 2 dprime Sqrt[t De/Pi]
>
> I have two imported data sets, time1 and con1 that are in lists
>
> So I want to do a summation from i=1 to 63, (because there is 63 terms for each imported data set), and my summation function would be:
> (con1(i) - Cstardiff[time1(i), De_, 1])^2
>
> If anyone can help me with this that would greatly appreciated!
>
Hi Thomas,

I'll construct example data:

In[6]:= time=Range[63]*2Pi/63.;
con1=1-2*1.01*Sqrt[time * 3.21/Pi]+RandomReal[{-.01,.01},63];
In[3]:= ListPlot[Transpose@{time,con1}]
(* omitted *)

In[8]:= Cstardiff[t_,De_,dprime_]:=1-2 dprime Sqrt[t De/Pi]

as most numeric functions thread over lists, there is no need for a loop:

In[16]:= errsum=Total[(con1-Cstardiff[time,De,1])^2]//ExpandAll
Out[16]= 838.347 -926.534 Sqrt[De]+256. De

now you can find the best De:

In[17]:= Minimize[{errsum,De>0},De]
Out[17]= {0.00205585,{De->3.27478}}

and your function becomes:

In[18]:= Cstardiff[t,De,1]/.%[[2]]
Out[18]= 1-2.04196 Sqrt[t]

with built-in functions:

In[19]:= NonlinearModelFit[Transpose@{time,con1},
    Cstardiff[t,De,1],{De},t]//Normal
Out[19]= 1-2.04196 Sqrt[t]

hth,
Peter


  • Prev by Date: Re: Maintaining the order of terms when adding symbolic expressions
  • Next by Date: Re: Implicit Plot with parameter
  • Previous by thread: Re: Summation of imported data
  • Next by thread: Seeing a solution of a differential equation as it run, using EvaluationMonitor