Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2378 > unrolled thread

Summation of imported data

Started byThomas <imadorkous@gmail.com>
First post2011-05-14 07:15 +0000
Last post2011-05-15 11:06 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Summation of imported data Thomas <imadorkous@gmail.com> - 2011-05-14 07:15 +0000
    Re: Summation of imported data Peter <petsie@dordos.net> - 2011-05-15 11:06 +0000

#2378 — Summation of imported data

FromThomas <imadorkous@gmail.com>
Date2011-05-14 07:15 +0000
SubjectSummation of imported data
Message-ID<iqla6j$a10$1@smc.vnet.net>
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!

[toc] | [next] | [standalone]


#2400

FromPeter <petsie@dordos.net>
Date2011-05-15 11:06 +0000
Message-ID<iqoc39$mal$1@smc.vnet.net>
In reply to#2378
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web