# Fitting Legendre polynomial - Integer constraints in Fitting functions

I have some data in the form of {theta,y} and I am trying to fit a Legendre polynomial to it, however I don't know how I can get it to vary the m and l parameters in integer increments as I don't know what shape it will be in, my guess looks like this:

Fit[data, a*LegendreP[l, m, Cos[theta]]+b, m, l, a, b]


where a and b are just constants to adjust.

I have never fitted using Mathematica before so I don't know if this is easy or impossible, thanks for any advice.

• correct cos(theta) ---> Cos[theta] ... and other syntax issues first Feb 14 '15 at 16:08
• Are you sure you don't want to fit to a sum of such polynomials? That's what people usually do.
– Jens
Feb 14 '15 at 18:23

f[a_, b_, l_, m_, t_] := a LegendreP[l, m, Cos[t]] + b;