I am CS major, taking Computational Numerical Analysis course. Instructor gave us freedom of choice, we were allowed to use anything or any computer language we picked, I picked Mathematica.This is my 3rd day with the program.
I am writing a simple procedure to calculate the Least-Square $m^\text{th}$ Degree Polynomials based on data sample. Algorithm is somewhat simple: http://www.efunda.com/math/leastsquares/lstsqrmdcurve.cfm
This is how far I got:
y_sample = {0, 1, 2, 3, 4, 5, 6, 7, 8}
x_sample = {0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8}(*Some sample data*)
f[x_] = Sum[Subscript[a, i] x^i, {i, 0, 4}](*generating polynomial, in this case, degree of 4*)
Sum[(y_sample[[i]] - f[x_sample[[i]]])^2, {i, 0, 4}]
Last line of code should roughly correspond to
$$ \Pi = \sum^n_{i = 1}\left[y_i - f(x_i)\right]^2 = \sum^n_{i=1}\left[y_i- (a_0 + a_1 x_i + a_2 x_i^2 + \ldots + a_m x_i^m)\right]^2 = \text{min} $$
List of problems and questions, I am facing:
- Executing code above, produces number of errors that I don't mean much to me.
- How do I differentiate in respect to all $\mathbb{a}_n$
- Differentiation should produce number of linear equations, how do I set the results of differentiation to zero and solve for unknown coefficients.
- Outputs are enormously long, is there a way to suppress some outputs !
Blank
,BlankSequence
,BlankNullSequence
! $\endgroup$