Re: Can FindFit take two (or more) equations?
- To: mathgroup at smc.vnet.net
- Subject: [mg123565] Re: Can FindFit take two (or more) equations?
- From: Ray Koopman <koopman at sfu.ca>
- Date: Sun, 11 Dec 2011 03:48:17 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
You're right, I should have explained where the function came from. Thanks for clarifying it. ----- DrMajorBob <btreat1 at austin.rr.com> wrote: > Ray, > > You left it a BIT mysterious how you came up with the model > > i + ((1-i)b/x - i)*a^2/(x^2+b^2) > > Here's a clarification, although the model is arranged differently: > > Clear[a, b, i, x, f, g] > f[x_] = 1 - a^2/(x^2 + b^2); (* first fit function *) > > g[x_] = a^2*b/(x*(x^2 + b^2));(* second fit function *) > model = > i f[x] + (1 - i) g[x] > FindFit[Flatten[{{1, #1, #2}, {0, #1, #3}} & @@@ data, 1], model, {a, > b}, {i, x}] > > (a^2 b (1 - i))/(x (b^2 + x^2)) + i (1 - a^2/(b^2 + x^2)) > > {a -> 14.5228, b -> 2.36932} > > Bobby > > On Sat, 10 Dec 2011 06:31:05 -0600, Ray Koopman <koopman at sfu.ca> wrote: >> On Dec 9, 3:02 am, Luiz Melo <lm... at ufsj.edu.br> wrote: >>> Dear mathgroup >>> I have the following list of data: >>> >>> {{0.972, -45.7, 60.3}, {1.17, -39.7, 52.4}, {1.35, -34.1, 46.3}, >>> {1.55, -29.8, 40.0}, {1.73, -25.9, 34.6}, {1.91, -22.5, 30.6}, >>> {2.11, -19.6, 27.3}, {2.29, -17.4, 24.7}, {2.49, -15.8, 22.3}, >>> {2.67, -14.5, 20.6}, {2.86, -13.2, 19.2}, {3.05, -12.1,18.0}, >>> {3.24, -11.1, 16.9}, {3.43, -10.4, 15.7}, {3.62, -9.66, 14.5}, >>> {3.80, -9.07, 13.3}, {4.00, -8.35, 12.3}, {4.18, -7.73, 11.4}, >>> {4.38, -7.26, 10.6}, {4.56, -6.71, 9.82}, {4.74, -6.12, 9.20}, >>> {4.94, -5.61, 8.63}, {5.12, -5.09, 8.13}, {5.32, -4.59, 7.78}, >>> {5.50, -4.16, 7.46}, {5.68, -3.82, 7.12}, {5.88, -3.51, 6.87}, >>> {6.06, -3.26, 6.65}, {6.26, -2.99, 6.48}, {6.44, -2.72, 6.31}, >>> {6.62, -2.51, 6.16}, {6.82, -2.29, 6.02}, {7.00, -2.09, 5.88}, >>> {7.20, -1.97, 5.79}, {7.38, -1.78, 5.71}, {7.57, -1.62, 5.60}, >>> {7.76, -1.52, 5.58}, {7.95, -1.41, 5.56}, {8.14, -1.34, 5.50}, >>> {8.33, -1.36, 5.39}, {8.51, -1.38, 5.29}, {8.71, -1.40, 5.19}, >>> {8.89, -1.41, 5.02}, {9.09, -1.32, 4.84}, {9.27, -1.32, 4.62}, >>> {9.45, -1.26, 4.41}, {9.65, -1.20, 4.21}, {9.83, -1.19, 3.94}, >>> {10.0, -1.18, 3.69}} >>> >>> where the first column is, let's say, x, the second is y1 and the >>> third, y2. I would like to simultaneously fit the curve given by >>> the points y1 = y1(x) with the equation y1(x) = 1 - a^2/(x^2+b^2), >>> and the curve given by the points y2 = y2(x) with the equation >>> y2(x) = a^2*b/(x*(x^2+b^2)). >>> Can FindFit help us to find the parameters "a" and "b" >>> of the above equations? How? >>> >>> Thank you. >>> Luiz >> >> The usual way is to reorganize the data so that each y is on a >> different line, and to include an indicator that tells which y >> it is. Here the indicator is i, with value 1|0 for y1|y2. >> >> Clear[a,b,i,x]; >> FindFit[Flatten[{{1,#1,#2},{0,#1,#3}}& @@@ data, 1], >> i + ((1-i)b/x - i)*a^2/(x^2+b^2), {a,b}, {i,x}] >> >> {a -> 14.5228, b -> 2.36932}