Re: Fitting a function to a list (newbie)
- To: mathgroup at smc.vnet.net
- Subject: [mg21860] Re: [mg21851] Fitting a function to a list (newbie)
- From: BobHanlon at aol.com
- Date: Wed, 2 Feb 2000 22:54:17 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
f[x_] := 10. + 7.*Sin[3.x + 1.5] data = Table[{x = Random[], f[x]}, {10}] // Sort; Needs["Statistics`NonlinearFit`"] Clear[x, a, b, c, d]; NonlinearFit[data, a + b*Sin[c*x + d], x, {a, b, c, d}] 10. + 7. Sin[20.4911 - 3. x] {a, b, c, d} /. (BestFitParameters /. NonlinearRegress[data, a + b*Sin[c*x + d], x, {a, b, c, d}]) {10., 7., -3., 20.4911} In general, the parameters will have to be adjusted because of the periodic nature of the Sin function. Bob Hanlon In a message dated 1/30/2000 8:05:53 PM, mathprof at bigfoot.com writes: >I'm new to Mathematica 4.0, so I apologize if this question is overly >trivial (and please let me know if there's a place for trivial >question). > >I have a list that I'd like to fit to the function: > >A + B*Sin[C*x+D] > >In other words, I'd like to find the (approximate numeric) values of >A,B,C,D that yield the best fit to my data. > >I tried using Fit[], but it only applies to linear combinations of >functions, and couldn't optomize the values of C and D. > >For this specific problem, I'm guessing some sort of Fourier transform >might work, but I'm interested in a more general solution -- for example >if Sin[] were replaced with a more complicated function. >