[Math] How to plot a smooth curve function from given points

bezier-curvegraphing-functions

I have several points, how can I plot a smooth curve that pass through those points?

Is there any function that I can create or formula that I can use to get all points in the curve?

I have read about bezier curves, but I don't really understand how to plot a graph from it because I don't think I need the Bezier specific parameters like its control points.

Anyone has any idea?

Here is my data example, they are used for a measurement in given time interval (time,value), I want to plot all points in the given time interval, let's say [0..400]:
value = [(10,30), (111,100), (171,128), (181,86), (201,42), (211,44), (281,39), (321,59), (341,20), (351,4), …]

Thanks

Best Answer

some options in R would be

t=seq(0,10,0.01)
y=sin(t)+rnorm(length(t))
plot(t,y,cex=0.1)

# puts a loess smoother through the points
lines(loess.smooth(t,y),col=2)

library(mgcv)
# puts a spline through the points - read Simon Woods work to learn more about this
g<-gam(y~s(t),data=data.frame(t=t,y=y))
lines(t,g$fitted.values,col=3)

and for your recently added data

t=1:400
y=rep(NA,length(t))
y[10]<-30
y[111]<-100
y[171]<-128
y[181]<-86
y[201]<-42
y[211]<-44
y[281]<-39
y[321]<-59
y[341]<-20
y[351]<-4
library(mgcv)

g<-gam(y~s(t),data=data.frame(t=t,y=y))
lm<-predict.gam(g,data.frame(t=t,y=y))

plot(t,y,cex=0.5,pch=16,ylim=c(min(lm),max(lm)))
lines(t,lm,col='red')
Related Question