|
Contents | Previous | Next | Subchapters |
| Syntax |
p = polyfit(x, y, n) |
| See Also | lagrange , cubespl |
N 2
----- | n 1 |
> | y - p * x - ... - p * x - p |
----- | i 1 i n i n+1 |
i = 1
where N is the length of the vectors x
and y.
The arguments x and y are integer,
real, double-precision or complex vectors with the same length.
The argument n is scalar and equal to an integer value.
The returned value p is a row vector with
the type that results from coercion
between the
type of x and y
(unless they are both integer in which case the return value is double
precision).
[-pi , +pi].
The example plots the data values with the symbol + an
the fitted curve with a solid line (see the image below).
clear
x = PI * (seq(21) - 11) / 10d0
y = sin(x)
n = 3
p = polyfit(x, y, n)
v = polyval(p, x)
gplot(x, y, "plus")
gplot(x, v, "solid")