Re: FindFit power law problem
- To: mathgroup at smc.vnet.net
- Subject: [mg117035] Re: FindFit power law problem
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Tue, 8 Mar 2011 05:35:43 -0500 (EST)
data = {{1004, 0.003977}, {9970, 0.006494}, {100000, 0.012921}, {1001000, .059795}}; Clear[f] f[x_] = a x^b /. FindFit[data, a x^b, {a, b}, x] 0.0000145749 x^0.601807 Clear[g, h] g[x_] = Fit[Log[10, data], {1, x}, x] h[x_] = 10^g@Log[10, x] -3.64936 + 0.383174 x 0.000224203 x^0.383174 Show[ListPlot@data, Plot[{f@x, h@x}, {x, 10004, 1001000}, PlotStyle -> {Blue, Red}]] The power Fit (in Blue) looks better than the Log-Log fit in Red, don't you think? Here are the same two functions with the log-log transformation: Show[ListPlot@Log[10, data], Plot[{Log[10, f[10^x]], g@x}, {x, Log[10, 10004], Log[10, 1001000]}, PlotStyle -> {Blue, Red}]] Even on that scale, the blue line looks better. Perhaps if you used a quadratic fit to the log-log data, you'd be more satisfied. And maybe not. Bobby On Mon, 07 Mar 2011 04:48:40 -0600, Greg Childers <jgchilders at mailaps.org> wrote: > Hi, > > I'm having a problem with FindFit and a power law problem. Here's the > data: > > data = {{1004, 0.003977}, {9970, 0.006494}, {100000, 0.012921}, > {1001000, .059795}} > > I'm wanting to fit it to a function of the form y = a x^b, and determine > the best value of b. When entered into Excel, it returns the exponent b > = 0.383. However, Mathematica gives > > FindFit[data, a x^b, {a, b}, x] > {a->0.0000145749, b->0.601807} > > A graph of these values overlaid on the original data simply didn't look > right. Another way to find the exponent b is to take the log of both > sides and do a linear fit: > > Fit[Log[10, data], {1, x}, x] > -3.64936 + 0.383174 x > > And sure enough the exponent is 0.383 in agreement with Excel. Why does > FindFit give a different value? > > Greg > -- DrMajorBob at yahoo.com