What is the most appropriate way to express the following in SymPy:
A sum over samples 'x[i]' with 'i' going from concrete 0 to symbolic 'N'. 'x[i]' itself shall be symbolic, i.e. always appear as variable.
The goal is to use these expressions in a system of linear equations.
Example (trivial least squares approx.):
Given a set of samples (x[i], y[i]) which are supposed to lie on a line given by 'y = m*x + a'. That is, the estimated line is determined by 'm' and 'a'. The error between the samples and the estimated line may be given by
error(m, a) = sum((m * x[i] + a - y[i]) ** 2, start_i=0, end_i=N)
Now, searching for the zero transitions in the derivatives 'd/dm error(m,a)' and 'd/da error(m,a)' delivers the minimal distance. How could I find the solution with sympy?
x[i]
andN
shall be abstract. How would your situation differ from solving a completely abstract linear equation system? Why do you need SymPy for this and what do you expect it to do for you? 2) If I misunderstood this somehow, why do the standard Pythonsum
orsympy.Sum
not work? — Ideally please give some example for the input, what you want to do with it, and what kind of result you would like to have. – Lewis