You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`polyfit(x::AbstractVector, y::AbstractVector)`: Fit a polynomial of degree `n` through the points specified by `x` and `y` where `n <= length(x) - 1` using least squares fit.
444
+
`polyfit(x, y, n=length(x)-1, sym=:x )`: Fit a polynomial of degree
445
+
`n` through the points specified by `x` and `y` where `n <= length(x)
446
+
- 1` using least squares fit. When `n=length(x)-1` (the default), the
447
+
interpolating polynomial is returned. The optional fourth argument can
448
+
be used to pass the symbol for the returned polynomial.
445
449
446
450
Example:
447
451
@@ -453,55 +457,14 @@ polyfit(xs, ys, 2)
453
457
454
458
Original by [ggggggggg](https://github.com/Keno/Polynomials.jl/issues/19)
455
459
"""
456
-
functionpolyfit(x, y, n)
460
+
functionpolyfit(x, y, n::Int=length(x)-1, sym::Symbol=:x)
457
461
length(x) ==length(y) ||throw(DomainError)
458
-
n <=length(x) -1||throw(DomainError)
462
+
1<=n <=length(x) -1||throw(DomainError)
459
463
460
464
A = [ float(x[i])^p for i =1:length(x), p =0:n ]
461
-
Poly(A \ y)
462
-
end
463
-
464
-
## Find interpolating polynomial through the points
465
-
"""
466
-
467
-
* `polyinterpolate(x, y)`: Return interpolating polynomial of degree `n-1` or less.
468
-
469
-
Example
470
-
471
-
```
472
-
xs = linspace(0, pi, 3)
473
-
ys = map(sin, xs)
474
-
polyinterpolate(xs, ys)
475
-
```
476
-
477
-
This uses [Algorithm 1](http://www.ams.org/journals/mcom/1970-24-109/S0025-5718-1970-0258240-X/S0025-5718-1970-0258240-X.pdf) of Krogh, *Efficient Algorithms for Polynomial Interpolation and Numerical Differentiation*.
0 commit comments