Re: Fitting a function to a list (newbie)

• To: mathgroup at smc.vnet.net
• Subject: [mg21898] Re: Fitting a function to a list (newbie)
• From: Daniel Duque Campayo <campayo at phys.washington.edu>
• Date: Wed, 2 Feb 2000 22:55:04 -0500 (EST)
• Organization: University of Washington
• References: <872jej\$civ@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```mathprof at bigfoot.com wrote:
>
> I'm new to Mathematica 4.0..
>
> 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.

Fit performs a least-squares approximation; this method only works for
linear combinations of funcions, so the problem is not really
Mathematica, it's more that you're task is not so trivial. You want a
"Non-linear fitting". You could a) have a look at some numerics book
(say, "Numerical Recipes") and program it yourself b) get a special
program for data analysis and visualization which has nl fitting
(xmgrace for unix -which is free- has it, I guess Origin for Windows
should have it also) c) do it on Mathematica using some package or try
to do it yourself. For example, you could construct a function which is
the square of the difference between your data and your sin, with some
initial guesses for A,B,C and D, then try to FindMinimum of the thing on
A,B,C,D. That should work.

Regards

Daniel

```

• Prev by Date: Re: NDSolve and numeric-only computation
• Next by Date: Creating Raster Image Animation
• Previous by thread: Re: Fitting a function to a list (newbie)
• Next by thread: Re: Fitting a function to a list (newbie)