Mathematica, fitting an arbitrary number of parameters

  • Mathematica
  • Thread starter NeoDevin
  • Start date
  • #1
299
1

Main Question or Discussion Point

Let's say I have some data, as a function of a variable [itex]x[/itex]. I want to fit this to the real part of the function

[tex]\frac{A}{1-ix}\left(1+\sum_{n=1}^\infty\frac{c_n}{(1-ix)^n}\right)[/tex]

by numerically fitting the first [itex]N[/itex] of the [itex]c_n[/itex]'s ([itex]A[/itex] is fixed). I tried something like

Code:
A = 1; N = 100;
fit = FindFit[data, Re[A(1+Sum[c[k]/(1-i x)^k,{k,1,N}])], Table[c[k], {k,1,N}], x];
Plot[Re[A(1+Sum[c[k]/(1-i x)^k,{k,1,N}])]/.fit, {x,0,10}]
However, this way does not work. For the case [itex]N=5[/itex], I put in the summation explicitly, calling my parameters c1, c2, etc, and it produces different (better) results than the above code. This is not feasible if I want the first 100 or 1000 coefficients, so any help with the above method would be appreciated. Thanks in advance.
 

Answers and Replies

  • #2
299
1
Anybody?
 
  • #3
Redbelly98
Staff Emeritus
Science Advisor
Homework Helper
Insights Author
12,098
129
It looks like your code is missing the factor 1 / (1-ix)
 
  • #4
28,891
5,154
Also, in Mathematica the symbol N is protected, use n instead.
 
  • #5
299
1
It looks like your code is missing the factor 1 / (1-ix)
Yes, it is, but the original code wasn't. That was just me missing it when typing it into here.
Also, in Mathematica the symbol N is protected, use n instead.
That could be the problem, I'll check it later. Thanks for the replies.
 

Related Threads for: Mathematica, fitting an arbitrary number of parameters

Replies
1
Views
2K
Replies
3
Views
11K
Replies
1
Views
2K
Replies
2
Views
7K
Replies
2
Views
4K
Replies
4
Views
3K
Replies
0
Views
1K
Top