Group Abstract Group Abstract

Message Boards Message Boards

0
|
12K Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Use FindFit with functions with integer input only?

Posted 9 years ago
POSTED BY: Yuen Mlv
4 Replies
Posted 9 years ago
POSTED BY: Yuen Mlv
Posted 9 years ago
POSTED BY: Alexey Popkov
Posted 9 years ago

Actually the fact that with non-integer y Mathematica supply non-integer x to your basis functions can be proven as simple as follows:

sin2[n_Integer] := Sin[n]^2
sin2[n_Real] := (Print["sin2[", n, "]"]; Sin[n]^2)
cos2[n_Integer] := Cos[n]^2
cos2[n_Real] := (Print["cos2[", n, "]"]; Cos[n]^2)

FindFit[{1., 1, 1, 1}, a sin2[x] + b cos2[x], {a, b}, x]

sin2[1.]

cos2[1.]

sin2[2.]

cos2[2.]

sin2[3.]

cos2[3.]

sin2[4.]

cos2[4.]

{a -> 1., b -> 1.}
POSTED BY: Alexey Popkov
Posted 9 years ago

As you can see from the Documentation for FindFit, it has the following Methods: "ConjugateGradient", "Gradient", "LevenbergMarquardt", "Newton", "NMinimize", and "QuasiNewton". With exception for NMinimize none of these supports fitting in integer domain. So you should recast your problem for NMinimize as follows:

sin2[n_Integer] := Sin[n]^2
cos2[n_Integer] := Cos[n]^2
NMinimize[{Total[Table[a sin2[x] + b cos2[x] - 1, {x, 1, 4}]^2]}, {a, b}, Integers]
{3.15853*10^-32, {a -> 1, b -> 1}}
POSTED BY: Alexey Popkov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard