# curvefit: Parametric Curve Fit In pracma: Practical Numerical Math Functions

## Description

Polynomial fitting of parametrized points on 2D curves, also requiring to meet some points exactly.

## Usage

 `1` ```curvefit(u, x, y, n, U = NULL, V = NULL) ```

## Arguments

 `u` the parameter vector. `x, y` x-, y-coordinates for each parameter value. `n` order of the polynomials, the same in x- and y-dirction. `U` parameter values where points will be fixed. `V` matrix with two columns and `lemgth(U)` rows; first column contains the x-, the second the y-values of those points kept fixed.

## Details

This function will attempt to fit two polynomials to parametrized curve points using the linear least squares approach with linear equality constraints in `lsqlin`. The requirement to meet exactly some fixed points is interpreted as a linear equality constraint.

## Value

Returns a list with 4 components, `xp` and `yp` coordinates of the fitted points, and `px` and `py` the coefficients of the fitting polynomials in x- and y-direction.

## Note

In the same manner, derivatives/directions could be prescribed at certain points.

`circlefit`, `lsqlin`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40``` ```## Approximating half circle arc with small perturbations N <- 50 u <- linspace(0, pi, N) x <- cos(u) + 0.05 * randn(1, N) y <- sin(u) + 0.05 * randn(1, N) n <- 8 cfit1 <- curvefit(u, x, y, n) ## Not run: plot(x, y, col = "darkgray", pch = 19, asp = 1) xp <- cfit1\$xp; yp <- cfit1\$yp lines(xp, yp, col="blue") grid() ## End(Not run) ## Fix the end points at t = 0 and t = pi U <- c(0, pi) V <- matrix(c(1, 0, -1, 0), 2, 2, byrow = TRUE) cfit2 <- curvefit(u, x, y, n, U, V) ## Not run: xp <- cfit2\$xp; yp <- cfit2\$yp lines(xp, yp, col="red") ## End(Not run) ## Not run: ## Archimedian spiral n <- 8 u <- linspace(0, 3*pi, 50) a <- 1.0 x <- as.matrix(a*u*cos(u)) y <- as.matrix(a*u*sin(u)) plot(x, y, type = "p", pch = 19, col = "darkgray", asp = 1) lines(x, y, col = "darkgray", lwd = 3) cfit <- curvefit(u, x, y, n) px <- c(cfit\$px); py <- c(cfit\$py) v <- linspace(0, 3*pi, 200) xs <- polyval(px, v) ys <- polyval(py, v) lines(xs, ys, col = "navy") grid() ## End(Not run) ```

### Example output

```
```

pracma documentation built on Oct. 17, 2018, 3 a.m.