Mathematica, fitting an arbitrary number of parameters

Click For Summary

Discussion Overview

The discussion revolves around fitting a mathematical model to data using Mathematica, specifically focusing on fitting an arbitrary number of parameters in a complex function involving a series expansion. The scope includes technical explanations and potential corrections to the code provided by the original poster.

Discussion Character

  • Technical explanation, Debate/contested

Main Points Raised

  • The original poster seeks assistance with fitting a function that includes an infinite series of parameters, specifically the coefficients c_n, while keeping A fixed.
  • Some participants suggest that the original code may be missing a crucial factor of 1 / (1-ix), which could affect the fitting results.
  • Another participant points out that the symbol N is protected in Mathematica, recommending the use of n instead to avoid potential issues.
  • The original poster acknowledges the missing factor but clarifies that it was an oversight in the transcription of the code, not in the original implementation.
  • The original poster expresses gratitude for the feedback and indicates they will check the suggestions later.

Areas of Agreement / Disagreement

Participants have identified potential issues with the original code, but there is no consensus on the effectiveness of the proposed corrections or whether they will resolve the fitting problem.

Contextual Notes

The discussion highlights the challenges of fitting models with a large number of parameters and the importance of correctly implementing mathematical functions in code. There are unresolved aspects regarding the impact of the suggested changes on the fitting process.

NeoDevin
Messages
334
Reaction score
2
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.
 
Physics news on Phys.org
Anybody?
 
It looks like your code is missing the factor 1 / (1-ix)
 
Also, in Mathematica the symbol N is protected, use n instead.
 
Redbelly98 said:
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.
DaleSpam said:
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
9K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
Replies
6
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K