Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Fitting experimental data

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85544] Re: Fitting experimental data
  • From: "Kevin J. McCann" <Kevin.McCann at umbc.edu>
  • Date: Wed, 13 Feb 2008 04:28:42 -0500 (EST)
  • Organization: University System of Maryland
  • References: <fopb53$bhu$1@smc.vnet.net>

Here is the way I usually do this for a particular example. I generally 
roll my own least-squares fit:

points={{23400.,273.2},{6800.0,298.2},{2400.0,323.2}};
(*Plot the data points,but don't show the plot*)
p1=ListPlot[points,PlotStyle->{Red,PointSize[0.025]}];


(*The function that I wish to fit*)
f[B_,Ro_,x_]:=B/Log[x/Ro]

(*The LSQ fit function.*)
(*Note that you can plot this for a range of B and Ro values*)
lsFit[B_,Ro_]:=Plus@@Apply[Abs[f[B,Ro,#1]-#2]^2&,points,1]

(*Finally,fit the data by finding the minimum*)
(* The output comes in two parts. The first is *)
(* the sum of the squares; the second, the best fit parameters *)
sol=FindMinimum[lsFit[B,Ro],{B,1},{Ro,1}]

(* g[R] is the fitting function with the best fit parameters *)
g[x_]=f[B,Ro,x]/.sol[[2]];

(*Plot the fit along with the original data points*)
Plot[g[R],{R,1000,25000},PlotStyle->{Blue,AbsoluteThickness[2]},\
Epilog->p1[[1]],Frame->True,
	FrameStyle->AbsoluteThickness[2],
	GridLines->Automatic,
BaseStyle->{FontFamily->"Arial",FontSize->12,FontWeight->Bold},\
FrameLabel->{"R","g(R)"},PlotLabel->"LSQ Demo"
]


Hope this helps,

Kevin

Ausman, Kevin wrote:
> I am trying to fit experimental data (a list of {x,y} points) with a 
> model that produces a similar list of points. It seems that FindMinimum 
> with a Levenberg Marquardt method makes the most sense; unfortunately, I 
> can't seem to get it to work.
> 
> soln=FindMinimum[Sum[(xptData[[i,2]]-(simulatedData[xaxis,testInstFunc,
> k1auto,a1initauto])[[i]])^2,{i,1,Length[xaxis]}],{{k1auto,0.04},{a1initauto,0.9}}]
> 
> In this example, xptData is the list of experimental data. simulatedData 
> returns just the y axis as a list (assuming the same x axis), and the 
> resulting list, as you might imagine, depends on k1auto and a1initauto. 
> However, this results in a number of errors, I think because it tries to 
> evaluate simulatedData for the general case rather than for specific 
> instances of k1auto and a1initauto. simulatedData requires the use of 
> ListConvolve, NDSolve, and a number of other functions that seem to 
> preclude a general solution rather than a specific solution.
> 
> Does anyone have any thoughts on how to overcome this problem? Thanks!
> 
> Kevin Ausman
> ausman at okstate.edu

-- 

Kevin J. McCann
Research Associate Professor
JCET/Physics
Physics Building
University of Maryland, Baltimore County
1000 Hilltop Circle
Baltimore, MD 21250


  • Prev by Date: Re: Reduce in Ver 6
  • Next by Date: Re: Sphere through 4 points
  • Previous by thread: Re: Fitting experimental data
  • Next by thread: RE: Fitting experimental data