.. highlightlang:: us .. index:: polyfit .. _polyfit: polyfit ======= .. us.tag polyfit NOTREADYENGLISH Interpolation New5502 :ref:`polyfit` finds the coefficients of a polynomial of degree *N* using the least squares method. .. function:: p = polyfit(x, y, N) .. us.return **Return Value** *p* is a vector with *N* + 1 polynomial coefficients in descending powers: :math:`P(x) = p_1x^n + p_2x^{n-1}+ \dotsb + p_{n}x + p_{n+1}` .. us.params **Parameters** .. uparam:: x *x* is a vector with x coordinates. .. uparam:: y *y* is a vector with y coordinates. Same number of elements as *x*. .. uparam:: N *N* is the degree of the polynomial. *N* >= 0 and *N* <= len(x)-1. .. us.example **Example** :: def test_polyfit() { x = 0:0.1:3; y = erf(x); print p = polyfit(x, y, 3); h1 = plot(x, y) y2 = polyval(p, x); h2 = plot(x, y2, h1[2]) XYSetProps(h2[3], "curve-color='red'"); } test_polyfit() .. us.history **History** .. list-table:: :header-rows: 1 * - Version - Description * - R2013.2 - Documented. .. seealso:: :ref:`overview-mathematic`, :ref:`polyval` :sub:`id-204970`