Scipy curve fitting when summation is involved

Viewed 62

enter image description here

  • Above is the equation I want to fit on the data, by using Scipy.
  • I have the data points for y(t) and t and want to fit for 4 parameters : A, z, s & T.

I tried to fit it (below is the code) but, was confused a bit while defining the summation along with function.

```python
sigma = 0
for i in range(1,10000):
    add = (1/i)*np.sin(PI*i*z)*np.cos(2*PI*i*(x-s)/T)
    sigma = sigma + add

def func(x, A, z, T, s):
    return 1 - A*(z + (2/PI)*sigma)

param_bounds=([A_min, z_min, T_min, s_min],[A_max, z_max, T_max, s_max])
fit = curve_fit(func, x, y, sigma=yerr, bounds = param_bounds, absolute_sigma=True, method = 'trf')
```

I defined the summation part in for loop earlier than multiplied it to the defined function. Though the code is running without errors, but not give the correct answers. below is the output graph,

enter image description here

0 Answers
Related