iCAL Modern Calculus
with R and Python


Version 1.0 developed from May 2021 for Cal III by Dr. Samuel Shen, Distinguished Professor
San Diego State University, California, USA
https://shen.sdsu.edu
Email:


Chapter 6: Coordinates, Vectors, and Modeling a Curve

setwd('/Users/sshen/Calculus')
getwd() #Method to get personal working directory

R Code for Plotting a Blue Point

x1 = 2; x2 =3
plot(x1, x2, pch =16, col = 'blue')

x1 = c(2, 4, 3)
x2 = c(3, 7, -4)
plot(x1, x2, pch =16, col = 'blue',
     xlim =c(0,10), ylim =c(-5,10))

R Code for Fig. 6.2

setwd('/Users/sshen/Calculus')
getwd() #Method to get personal working directory
#Point moves on a circle
#Save the figure as fig0602.eps
#setEPS() 
#postscript("fig0602.eps", height = 5.4, width = 10)
#To save as png: png(file="fig0602.png",width=1000, height=540)

#Footprints of a point on a circle path
par(mfrow=c(1,2))
par(mar=c(4,4,2,0.2))
R = 3
R
## [1] 3
n = 41 #number of points
ome = 2 #omega
t = seq(0, 3, len=n)
x = R*cos(ome*t)
y = R*sin(ome*t)

#plot points on the circle 
plot(x, y, pch = 16, cex = 0.7,
     main = 'Footprints of a point moving along a circle',
     cex.main = 0.8, cex.lab = 1.4, cex.axis = 1.4)

#Plot the blue arrow with angle \theta
arrows(0, 0, x[5], y[5], col = 'blue', 
       length = 0.2, angle = 10)

#Plot the angle \theta
tangle = seq(0, 3/10, len=n)
xangle = 0.25*R*cos(ome*tangle)
yangle = 0.25*R*sin(ome*tangle)
lines(xangle, yangle, 
      col = 'blue', type = 'l', lwd = 0.9)

#Plot other lines
segments(0, 0, x[1], y[1], col = 'blue')
segments(0, 0, 0, 3, col = 'blue')
segments(x[5], 0, x[5], y[5], col = 'blue')
segments(0, y[5], x[5], y[5], col = 'blue')
points(x[5], y[5], col = 'blue',
       pch = 16)
text(x[5], -0.3, 'x',
     cex = 1.3, col = 'blue')
text( -0.3, y[5], 'y',
      cex = 1.3, col = 'blue')
text(x[5]/2, 0.3+y[5]/2, 'R',
     cex = 1.3, col = 'blue')
text(x[5]+0.3, y[5], 'P',
     cex = 1.3, col = 'blue')
text(-0.2, -0.2, 'O',
     cex = 1.3, col = 'blue')
text(1.5, 0.35, 
     bquote(theta == omega*t),
     cex = 1.3, col = 'blue')
text(1.5, 0.35, 
     bquote(theta == omega*t),
     cex = 1.3, col = 'blue')
text(0, -1, 
     bquote(x == R*cos(omega*t)),
     cex = 1.4, col = 'blue')
text(0, -1.7, 
     bquote(y == R*sin(omega*t)),
     cex = 1.4, col = 'blue')

#Firections of a moving point on a circle 
plot(x, y, pch = 16, cex = 0.7, cex.main = 0.8,
     cex.lab = 1.4, cex.axis = 1.4,
     main = 'Directions of a moving point on a circle')
s = seq(length(x)-30)
arrows(x[s], y[s], x[s+1], y[s+1], 
       col = 1:(length(s)-1),
       angle = 30, length = 0.1)
text(0, 1, 'Angular velocity = 2 radians/sec')
text(0, 0, 'Time goes from 0 to 1.5 sec')
text(0, -1, 'Angle goes from 0 to 3 radians')
text(0, -2, 'Point goes through a semi-circle')

#The coordinates of the first five points of Fig. 6.2
t[1:2]
## [1] 0.000 0.075
round(x[1:5], digits = 2)
## [1] 3.00 2.97 2.87 2.70 2.48
round(y[1:5], digits = 2)
## [1] 0.00 0.45 0.89 1.30 1.69

R Code for Fig. 6.3

par(mar=c(4,4,2,0.6))
n = 81
ome = 2
t = seq(0, 12, len=n)
x = 2*t*cos(ome*t) 
y = 2*t*sin(ome*t) 
plot(x, y, pch = 16, cex = 0.7, 
     cex.lab =1.3, cex.axis = 1.3,
     main = 'A point is spiraling out')
s = seq(length(x))
arrows(x[s], y[s], x[s+1], y[s+1], 
       col = 1:(length(s)-1),
       angle = 30, length = 0.1)

R Code for Fig. 6.4

par(mar=c(4,4,2,0.2))
n = 41
ome = 2
t = seq(0, 2*pi-0.15, len=n)
x = 2*sin(ome*t) + 5*sin(ome*t/2)
y = 2*cos(ome*t) + 5*cos(ome*t/2)
plot(x, y, pch = 16, cex = 0.7,
     cex.lab =1.3, cex.axis = 1.3,
     main = 'Heart-shape path of a point')
s = seq(length(x))
arrows(x[s], y[s], x[s+1], y[s+1], 
       col = 1:(length(s)-1),
       angle = 30, length = 0.1)

R Code for Fig. 6.5

#Model flower pedals 
#setwd('/Users/sshen/CalculusR')
#setEPS()
#postscript("fig0605.eps", height = 5.4, width = 10)

par(mfrow=c(1,2))
par(mar=c(4,4,2,0.2))
# eight petals 
a = 3
n = 1000
ome = 2
t = seq(0, 2*pi, len=n)
theta = ome*t
r = a*cos(4*theta)
x = r*cos(theta)
y = r*sin(theta)
plot(x, y,  type = 'l', lwd = 4, col = 'pink',
     main = 'An eight-petal rose')

# infinitely many petals
n = 10000
ome = 2
t = seq(0, 40*pi, len=n)
theta = ome*t
a = sqrt(2)
r = a*cos(pi*theta)
x = r*cos(theta)
y = r*sin(theta)
plot(x, y,  type = 'l', lwd = 1, col = 'red',
     main = 'Infinitely many petals')

#dev.off()

#Infinitely many petals with different color
n = 10000
ome = 2
t = seq(0, 40*pi, len=n)
theta = ome*t
a = sqrt(2)
r = a*cos(pi*theta)
x = r*cos(theta)
y = r*sin(theta)
plot(x, y,  type = 'l', lwd = 1, col = 'red',
     xlab ='', ylab = '',
     xaxt = 'n', yaxt = 'n',
     main = '')
points(x, y, col = sqrt(1:n), pch = 2, cex = 0.3)

#Hypotrochoid
n = 401
t = seq(0, 6*pi, len=n)
x = 2*cos(t) + 5*cos(2*t/3)
y = 2*sin(t) - 5*sin(2*t/3)
plot(x, y,  type = 'l', lwd = 1, col = 'red',
     main = 'Hypotrochoid')
s = seq(length(x))
arrows(x[s], y[s], x[s+1], y[s+1], 
       col = 1:(length(s)-1),
       angle = 30, length = 0.1)

#Epicycloid
n = 401
t = seq(0, 2*pi, len=n)
x = 4*cos(t) - cos(4*t)
y = 4*sin(t) - sin(4*t)
plot(x, y,  type = 'l', lwd = 1, col = 'red',
     main = 'Hypotrochoid')
s = seq(length(x))
arrows(x[s], y[s], x[s+1], y[s+1], 
       col = 1:(length(s)-1),
       angle = 30, length = 0.1)


#Star-curve
n = 401
t = seq(0, 2*pi, len=n)
x = 4*cos(t)^3 
y = 4*sin(t)^3
plot(x, y,  type = 'l', lwd = 1, col = 'red',
     main = 'Hypotrochoid')
s = seq(length(x))
arrows(x[s], y[s], x[s+1], y[s+1], 
       col = 1:(length(s)-1),
       angle = 30, length = 0.1)

#Coin money 2
n = 28001
t = seq(0, 110*pi, len=n)
x = 4*(sin(pi*t) + cos(t)^3)
y = 4*(cos(pi*t) + sin(t)^3)
plot(0,0,  type = 'l', lwd = 1,
     xlim = c(-8, 8), ylim = c(-8, 8),
     xlab ='', ylab = '',
     xaxt = 'n', yaxt = 'n',
     main = '')
s = seq(length(x))
arrows(x[s], y[s], x[s+1], y[s+1], 
       col = sqrt(1:(length(s)-1)),
       angle = 30, length = 0.2)

#Coin money 2
n = 28001
t = seq(0, 110*pi, len=n)
x = 4*(sin(pi*t) + cos(t)^3)
y = 4*(cos(pi*t) + sin(t)^3)
plot(0,0,  type = 'l', lwd = 1,
     xlim = c(-8, 8), ylim = c(-8, 8),
     xlab ='', ylab = '',
     xaxt = 'n', yaxt = 'n',
     main = '')
s = seq(length(x))
arrows(x[s], y[s], x[s+1], y[s+1], 
       col = 1:(length(s)-1),
       angle = 30, length = 0.15)

#n = 4001
t = seq(0, 110*pi, len=n)
x = 4*(sin(pi*t) + cos(t)^3)
y = 4*(cos(pi*t) + sin(t)^3)
plot(x, y,  type = 'l', lwd = 1, 
     main = 'Coin')
points(x, y, col = 1:n, pch = 3, cex = 0.4)


#Descarte leaf
t = seq(-10, 10, len = 202)
a = 5
x = 3*a*t/(1+t^3)
y = 3*a*t^2/(1+t^3)
plot(x, y, type = 'l', col = 'blue',
     xlim = c(-10, 10), 
     ylim = c(-20, 10))
grid()
arrows(0, -20, 0, 10, 
       length = 0.2, angle = 8)
arrows(-10, 0, 10, 0, 
       length = 0.2, angle = 8)
s = seq(length(x))
arrows(x[s], y[s], x[s+1], y[s+1], 
       col = 1:(length(s)-1),
       angle = 30, length = 0.1)

R Code for Fig. 6.7

#Vector OP
plot(3,4, pch = 16, col = 'red', cex = 2,
     xlim = c(-1, 5), ylim = c(-1, 5), bty = 'n',
     xlab ='', ylab = '', xaxt ='n', yaxt = 'n')
arrows(0, 0, 3, 4, lwd=3, angle = 6,
       length = 0.6)
arrows(-1, 0, 4, 0, angle = 5)
arrows(0, -1, 0, 5, angle = 5)
arrows(0, 0, 0, 1, lwd = 4, angle = 9, length = 0.15)
arrows(0, 0, 1, 0, lwd = 4, angle = 9, length = 0.15)
segments(3, 0, 3, 4, lty = 3)
segments(0, 4, 3, 4, lty = 3)
text(-0.2, -0.2, 'O', cex = 1.3)
text(3.2, 4.4, col = 'red', cex = 1.2,
     expression(P(x[1], x[2])))
text(0.5, 0.3, expression(theta), cex = 1.3)
text(1, -0.3, 'i', cex = 1.3, font = 2)
text(-0.3, 1, 'j', cex = 1.3, font = 2)
text(3.8, -0.3, 'x', cex = 1.2)
text(-0.2, 4.8, 'y', cex = 1.2)

R Command of Entering Data

x = c(1.4, -2.6, 0.9, -3.7, 4.1, 3.2, 5.0)
x
## [1]  1.4 -2.6  0.9 -3.7  4.1  3.2  5.0

R Code for Vector Addition and Subtraction

u = c(3, 4)
v = c(-2.5,1.5)
x = u + v
y = u - v
x
## [1] 0.5 5.5
y
## [1] 5.5 2.5

R Code for Fig. 6.8

#Addition and subtraction of two vectors
u = c(3, 4)
v = c(-2.5,1.5)
o = c(0, 0)
x = u + v
y = u - v
plot(0,0, pch = 16, cex = 0.4,
     xlab = '', ylab = '', 
     xlim =c(-3,6), ylim = c(-3,6))
grid()
arrows(o[1],o[2], u[1],u[2], angle =10)
arrows(o[1],o[2], v[1],v[2], angle =10, col = 'blue')
arrows(o[1],o[2], -v[1],-v[2], 
       lty = 2, angle =10, col = 'blue')
arrows(o[1],o[2], x[1],x[2], angle =10, col = 'red')
arrows(o[1],o[2], y[1],y[2], angle =10, col = 'purple')
segments(u[1],u[2], x[1],x[2], lty = 3, col = 'blue')
segments(v[1],v[2], x[1],x[2], lty = 3)
segments(y[1],y[2], u[1],u[2], lty = 2, col = 'blue')
segments(-v[1], -v[2], y[1],y[2], lty = 2, col = 'blue')
arrows(-3, 0, 6,0, angle = 6)
arrows(0, -3, 0, 6, angle = 6)
text(u[1]+ 0.3, u[2] + 0.3, 'u', font=2)
text(v[1]- 0.3, v[2] + 0.3, 'v', col = 'blue', font=2)
text(-v[1], -v[2] - 0.3, '-v', col = 'blue', font=2)
text(x[1]+0.2, x[2] + 0.3, 'u + v', col = 'red', font=2)
text(y[1]+0.3, y[2] - 0.3, 'u - v', col = 'purple', font=2)
text(-0.3, - 0.3, 'O', cex = 1.2)
text(6, - 0.3, 'x', cex = 1.2)
text(- 0.4, 6,  'y', cex = 1.2)

#2 dim vector u = (3, 4)
#3-dim vector v = (2, 5, -1)
#n-dim vector w = (2, 4, 2, 1, ..., 6), n components

R Code for Fig. 6.10

#Colorado temperature and elevation
#x is elevation data
x= c(1671.5, 1635.6, 2097.0, 1295.4, 1822.7, 2396.9, 2763.0, 1284.7,
     1525.2, 1328.6, 1378.9, 2323.8, 2757.8, 1033.3, 1105.5, 1185.7,
     2343.9, 1764.5, 1271.0, 2347.3, 2094.0, 2643.2, 1837.9, 1121.7)

y= c(22.064, 23.591, 18.464, 23.995, 20.645, 17.175, 13.582, 24.635,
     22.178, 24.002, 23.952, 16.613, 13.588, 25.645, 25.625, 25.828,
     17.626, 22.433, 24.539, 17.364, 17.327, 15.413, 22.174, 24.549)
y
##  [1] 22.064 23.591 18.464 23.995 20.645 17.175 13.582 24.635 22.178 24.002
## [11] 23.952 16.613 13.588 25.645 25.625 25.828 17.626 22.433 24.539 17.364
## [21] 17.327 15.413 22.174 24.549
length(y)
## [1] 24
cor(x,y)
## [1] -0.9813858
mean(x)
## [1] 1792.879
mean(y)
## [1] 20.95863
var(x)
## [1] 312374.1
var(y)
## [1] 15.81033
sd(y) #var = sd^2
## [1] 3.97622
cbind(x,y)
##            x      y
##  [1,] 1671.5 22.064
##  [2,] 1635.6 23.591
##  [3,] 2097.0 18.464
##  [4,] 1295.4 23.995
##  [5,] 1822.7 20.645
##  [6,] 2396.9 17.175
##  [7,] 2763.0 13.582
##  [8,] 1284.7 24.635
##  [9,] 1525.2 22.178
## [10,] 1328.6 24.002
## [11,] 1378.9 23.952
## [12,] 2323.8 16.613
## [13,] 2757.8 13.588
## [14,] 1033.3 25.645
## [15,] 1105.5 25.625
## [16,] 1185.7 25.828
## [17,] 2343.9 17.626
## [18,] 1764.5 22.433
## [19,] 1271.0 24.539
## [20,] 2347.3 17.364
## [21,] 2094.0 17.327
## [22,] 2643.2 15.413
## [23,] 1837.9 22.174
## [24,] 1121.7 24.549
par(mar=c(4.5,4.5,2.5,0.5))
plot(x,y, 
     xlab="Elevation [m]",
     ylab="Temperature [deg C]",
     main="Colorado Elevation and July Tmean: 1981-2010 Average",
     cex.lab=1.5, cex.axis=1.5)
reg = lm(y ~ x) #lm means linear model
reg # y = a + b*x
## 
## Call:
## lm(formula = y ~ x)
## 
## Coefficients:
## (Intercept)            x  
##   33.476300    -0.006982
summary(reg)
## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.52923 -0.60674 -0.08437  0.40181  1.53427 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 33.4763004  0.5460279   61.31   <2e-16 ***
## x           -0.0069819  0.0002913  -23.97   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7808 on 22 degrees of freedom
## Multiple R-squared:  0.9631, Adjusted R-squared:  0.9614 
## F-statistic: 574.5 on 1 and 22 DF,  p-value: < 2.2e-16
abline(reg, lwd=3, col = 'red')
text(2100, 25.5, "Temperature lapse rate: 7.0 deg C/1.0km", 
     cex=1.5)
text(2350, 24, "y= 33.48 - 0.0070 x", cex=1.5)
text(2350, 22.5,"R-squared = 0.96", cex=1.5)

R Code for Fig. 6.12

#Polar expression of a complex number z
#setwd("~/calculus")
#setEPS()
#postscript("fig0612.eps", height=7, width=7)
par(mar = c(0,0,0,0))
r=10
bb=1.5*r
t=seq(0, 2*pi, length=200)
x=r*cos(t)
y=r*sin(t)
plot(x,y,type="l", lwd=3, asp=1, 
     xlim=c(-bb + 3, bb + 3),ylim=c(-bb + 5, bb + 3),
     xaxt="n",yaxt="n",ann=FALSE,bty="n")
aa=2*r
x1=r*cos(pi/3)
y1=r*sin(pi/3)
arrows(c(-aa+8, 0), c(0, -aa+8), c(aa-3,0), c(0, aa-2), 
       length=0.1, code=2, lwd=1)
arrows(0,0,0.98*x1,0.98*y1, col= 'blue',
       length=0.15,code=2, lwd=2, angle=15)
t2=seq(0,pi/3,length=10)
x2=0.22*r*cos(t2)
y2=0.22*r*sin(t2)
lines(x2,y2, type="l", col = 'blue')
points(x1,y1, pch=19, cex= 1.5, col = 'blue')
segments(x1,0, x1,y1, col = 'blue', lwd = 2)
segments(x1,0, 0,0, col = 'blue', lwd = 2)
text(1.1*r,0.1*r, "r", cex=1.3)
text(-0.1*r, 1.1*r, "i r", cex=1.5)
text(1.2*x1,1.13*y1, "(x,y)", cex=1.3)
text(0.3*r,-0.1*r, expression(paste('r', cos,theta)), 
     cex=1.3, col = 'blue')
text(1.2*x1, 0.5*y1, expression(paste('r', sin,theta)), 
     cex=1.3, col = 'blue', srt = 270)
text(0.37*x1, 0.5*y1, "r", 
     cex=1.3, col = 'blue')
text(1.55*r,-0.1*r, "Real Axis", cex=1.3)
text(0.1*r, 1.5*r, "Imaginary Axis", cex=1.3, srt=270)
text(-0.1*r, -0.1*r, "0", cex=1.5)
text(0.3*r*cos(pi/6),0.3*r*sin(pi/6), 
     expression(paste(theta)), 
     cex=1.3, col = 'blue')
text(1.85 * x1, 1.95 * y1, 
     expression(paste(x, " = r", cos, theta, ", ", y, 
                      " = r", sin, theta)), cex=1.5)
text(1.4*x1,1.75*y1, 
     expression(z == x + i * y), cex=1.5)
text(1.3*x1,1.55*y1, 
     expression(paste('z = r', e^{i*theta})), cex=1.5)
text(1.74*x1,1.35*y1, 
     expression(paste(e^{i*theta},"= ", 
                      "r cos",theta,"+ i r sin",theta)), 
     cex=1.5)

#dev.off()

Cross Product and Dot Product

# R Program illustrating cross product of two vectors 
# Import the required library 
#install.packages('pracma')
library(pracma) 
# Taking two vectors 
a = c(3, 5, 4) 
b = c(2, 7, 5) 
# Calculating cross product using cross() 
cross(a, b)
## [1] -3 -7 11
dot(a,b)
## [1] 61
t = c(1,1)
norm(t, '2')
## [1] 1.414214

R Code for Fig. 6.13

#Circular motion of a point
ome = 1
R = 3
t = seq(0, 4*pi, len = 81)
x = R*cos(ome*t)
y = R*sin(ome*t)
par(mar = c(2,2,2,0.2))
plot(x, y, type = 'l', 
     xlim = c(-4,4), ylim = c(-4,4),
     xlab = '', ylab = '', cex.axis = 1.1,
     main = 'Circular motion of a point')
arrows(-3.5, 0, 3.8, 0, angle = 9)
arrows(0, -3.5, 0, 3.8, angle = 9)
s = seq(length(x)-10)
arrows(x[s], y[s], x[s+1], y[s+1], 
       col = 1:(length(s)-1),
       angle = 30, length = 0.1)
points(x[15], y[15], pch =16, cex = 2, col = 'red') 
arrows(0,0, x[15], y[15], lwd = 1.5,
       angle = 20, len = 0.2, col = 'red')
arrows(x[15], y[15], 0.7*x[15], 0.7*y[15], 
       lwd = 6, length = 0.1)
arrows(x[15], y[15], 0.3*x[15], 0.3*y[15], 
       lwd = 2, length = 0.1, col = 'blue')
text(-0.4, -0.3, 'O', cex = 1.5)
text(x[15] - 0.3, y[15] + 0.3, 'r', 
     font = 2, col = 'red', cex = 1.5)
text(0.7*x[15]-0.1, 0.7*y[15] - 0.3, 'a', 
     font = 2, col = 'black', cex = 1.5)
text(0.3*x[15]-0.1, 0.3*y[15] - 0.3, 'F', 
     font = 2, col = 'blue', cex = 1.5)
text(3.6, -0.3, 'x', cex = 1.3)
text(-0.3, 3.6, 'y', cex = 1.3)

Symbolic Calculation of Derivatives

Example 6.4

x = expression(R*cos(ome*t),'t')
y = expression(R*sin(ome*t),'t')
D(x,'t')
## -(R * (sin(ome * t) * ome))
D(y,'t')
## R * (cos(ome * t) * ome)
x = c(1,4,6)
y = c(-2, 3.8, 1.0)
plot(x,y)
reg = lm(y ~ x)
abline(reg, col= 'red')

sd(x)
## [1] 2.516611
var(x)
## [1] 6.333333

R Code for Fig. 6.15

ome = 2*pi
R = 3
t = seq(0, 1, len = 101)
t
##   [1] 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14
##  [16] 0.15 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29
##  [31] 0.30 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.40 0.41 0.42 0.43 0.44
##  [46] 0.45 0.46 0.47 0.48 0.49 0.50 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59
##  [61] 0.60 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.70 0.71 0.72 0.73 0.74
##  [76] 0.75 0.76 0.77 0.78 0.79 0.80 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89
##  [91] 0.90 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00
x = R*cos(ome*t)
x
##   [1]  3.000000e+00  2.994080e+00  2.976344e+00  2.946862e+00  2.905749e+00
##   [6]  2.853170e+00  2.789329e+00  2.714481e+00  2.628920e+00  2.532984e+00
##  [11]  2.427051e+00  2.311540e+00  2.186906e+00  2.053641e+00  1.912272e+00
##  [16]  1.763356e+00  1.607480e+00  1.445261e+00  1.277338e+00  1.104374e+00
##  [21]  9.270510e-01  7.460697e-01  5.621439e-01  3.759997e-01  1.883716e-01
##  [26]  1.836970e-16 -1.883716e-01 -3.759997e-01 -5.621439e-01 -7.460697e-01
##  [31] -9.270510e-01 -1.104374e+00 -1.277338e+00 -1.445261e+00 -1.607480e+00
##  [36] -1.763356e+00 -1.912272e+00 -2.053641e+00 -2.186906e+00 -2.311540e+00
##  [41] -2.427051e+00 -2.532984e+00 -2.628920e+00 -2.714481e+00 -2.789329e+00
##  [46] -2.853170e+00 -2.905749e+00 -2.946862e+00 -2.976344e+00 -2.994080e+00
##  [51] -3.000000e+00 -2.994080e+00 -2.976344e+00 -2.946862e+00 -2.905749e+00
##  [56] -2.853170e+00 -2.789329e+00 -2.714481e+00 -2.628920e+00 -2.532984e+00
##  [61] -2.427051e+00 -2.311540e+00 -2.186906e+00 -2.053641e+00 -1.912272e+00
##  [66] -1.763356e+00 -1.607480e+00 -1.445261e+00 -1.277338e+00 -1.104374e+00
##  [71] -9.270510e-01 -7.460697e-01 -5.621439e-01 -3.759997e-01 -1.883716e-01
##  [76] -5.510911e-16  1.883716e-01  3.759997e-01  5.621439e-01  7.460697e-01
##  [81]  9.270510e-01  1.104374e+00  1.277338e+00  1.445261e+00  1.607480e+00
##  [86]  1.763356e+00  1.912272e+00  2.053641e+00  2.186906e+00  2.311540e+00
##  [91]  2.427051e+00  2.532984e+00  2.628920e+00  2.714481e+00  2.789329e+00
##  [96]  2.853170e+00  2.905749e+00  2.946862e+00  2.976344e+00  2.994080e+00
## [101]  3.000000e+00
y = R*sin(ome*t)
y
##   [1]  0.000000e+00  1.883716e-01  3.759997e-01  5.621439e-01  7.460697e-01
##   [6]  9.270510e-01  1.104374e+00  1.277338e+00  1.445261e+00  1.607480e+00
##  [11]  1.763356e+00  1.912272e+00  2.053641e+00  2.186906e+00  2.311540e+00
##  [16]  2.427051e+00  2.532984e+00  2.628920e+00  2.714481e+00  2.789329e+00
##  [21]  2.853170e+00  2.905749e+00  2.946862e+00  2.976344e+00  2.994080e+00
##  [26]  3.000000e+00  2.994080e+00  2.976344e+00  2.946862e+00  2.905749e+00
##  [31]  2.853170e+00  2.789329e+00  2.714481e+00  2.628920e+00  2.532984e+00
##  [36]  2.427051e+00  2.311540e+00  2.186906e+00  2.053641e+00  1.912272e+00
##  [41]  1.763356e+00  1.607480e+00  1.445261e+00  1.277338e+00  1.104374e+00
##  [46]  9.270510e-01  7.460697e-01  5.621439e-01  3.759997e-01  1.883716e-01
##  [51]  3.673940e-16 -1.883716e-01 -3.759997e-01 -5.621439e-01 -7.460697e-01
##  [56] -9.270510e-01 -1.104374e+00 -1.277338e+00 -1.445261e+00 -1.607480e+00
##  [61] -1.763356e+00 -1.912272e+00 -2.053641e+00 -2.186906e+00 -2.311540e+00
##  [66] -2.427051e+00 -2.532984e+00 -2.628920e+00 -2.714481e+00 -2.789329e+00
##  [71] -2.853170e+00 -2.905749e+00 -2.946862e+00 -2.976344e+00 -2.994080e+00
##  [76] -3.000000e+00 -2.994080e+00 -2.976344e+00 -2.946862e+00 -2.905749e+00
##  [81] -2.853170e+00 -2.789329e+00 -2.714481e+00 -2.628920e+00 -2.532984e+00
##  [86] -2.427051e+00 -2.311540e+00 -2.186906e+00 -2.053641e+00 -1.912272e+00
##  [91] -1.763356e+00 -1.607480e+00 -1.445261e+00 -1.277338e+00 -1.104374e+00
##  [96] -9.270510e-01 -7.460697e-01 -5.621439e-01 -3.759997e-01 -1.883716e-01
## [101] -7.347881e-16
par(mar = c(2,2,2,0.2))
plot(x,y, pch = 16, type = 'o')

plot(x, y, type = 'l', 
     xlim = c(-4,4), ylim = c(-4,4),
     xlab = '', ylab = '', cex.axis = 1.1)
arrows(-3.5, 0, 3.8, 0, angle = 9)
arrows(0, -3.5, 0, 3.8, angle = 9)
points(3*sqrt(2)/2, 3*sqrt(2)/2, 
       pch =16, col = 'red', cex = 0.5)

 tau = seq(-1,1, len =11)
tau
##  [1] -1.0 -0.8 -0.6 -0.4 -0.2  0.0  0.2  0.4  0.6  0.8  1.0
xt = 3*sqrt(2)/2 * (1 - tau)
xt
##  [1] 4.2426407 3.8183766 3.3941125 2.9698485 2.5455844 2.1213203 1.6970563
##  [8] 1.2727922 0.8485281 0.4242641 0.0000000
yt = 3*sqrt(2)/2 * (1 + tau)
yt
##  [1] 0.0000000 0.4242641 0.8485281 1.2727922 1.6970563 2.1213203 2.5455844
##  [8] 2.9698485 3.3941125 3.8183766 4.2426407
plot(xt,yt)

tau = seq(-1,1, len =11)
tau
##  [1] -1.0 -0.8 -0.6 -0.4 -0.2  0.0  0.2  0.4  0.6  0.8  1.0
xt = 3*sqrt(2)/2  - (3*sqrt(2)/2)*(tau - 1/8)
xt
##  [1] 4.5078057 4.0835417 3.6592776 3.2350135 2.8107495 2.3864854 1.9622213
##  [8] 1.5379572 1.1136932 0.6894291 0.2651650
yt = 3*sqrt(2)/2  + (3*sqrt(2)/2)* (tau - 1/8)
yt
##  [1] -0.2651650  0.1590990  0.5833631  1.0076272  1.4318912  1.8561553
##  [7]  2.2804194  2.7046834  3.1289475  3.5532116  3.9774756
plot(xt,yt)

ome = 2*pi
R = 3
t = seq(0, 1, len = 101)
t
##   [1] 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14
##  [16] 0.15 0.16 0.17 0.18 0.19 0.20 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29
##  [31] 0.30 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.40 0.41 0.42 0.43 0.44
##  [46] 0.45 0.46 0.47 0.48 0.49 0.50 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59
##  [61] 0.60 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.70 0.71 0.72 0.73 0.74
##  [76] 0.75 0.76 0.77 0.78 0.79 0.80 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89
##  [91] 0.90 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1.00
x = R*cos(ome*t)
x
##   [1]  3.000000e+00  2.994080e+00  2.976344e+00  2.946862e+00  2.905749e+00
##   [6]  2.853170e+00  2.789329e+00  2.714481e+00  2.628920e+00  2.532984e+00
##  [11]  2.427051e+00  2.311540e+00  2.186906e+00  2.053641e+00  1.912272e+00
##  [16]  1.763356e+00  1.607480e+00  1.445261e+00  1.277338e+00  1.104374e+00
##  [21]  9.270510e-01  7.460697e-01  5.621439e-01  3.759997e-01  1.883716e-01
##  [26]  1.836970e-16 -1.883716e-01 -3.759997e-01 -5.621439e-01 -7.460697e-01
##  [31] -9.270510e-01 -1.104374e+00 -1.277338e+00 -1.445261e+00 -1.607480e+00
##  [36] -1.763356e+00 -1.912272e+00 -2.053641e+00 -2.186906e+00 -2.311540e+00
##  [41] -2.427051e+00 -2.532984e+00 -2.628920e+00 -2.714481e+00 -2.789329e+00
##  [46] -2.853170e+00 -2.905749e+00 -2.946862e+00 -2.976344e+00 -2.994080e+00
##  [51] -3.000000e+00 -2.994080e+00 -2.976344e+00 -2.946862e+00 -2.905749e+00
##  [56] -2.853170e+00 -2.789329e+00 -2.714481e+00 -2.628920e+00 -2.532984e+00
##  [61] -2.427051e+00 -2.311540e+00 -2.186906e+00 -2.053641e+00 -1.912272e+00
##  [66] -1.763356e+00 -1.607480e+00 -1.445261e+00 -1.277338e+00 -1.104374e+00
##  [71] -9.270510e-01 -7.460697e-01 -5.621439e-01 -3.759997e-01 -1.883716e-01
##  [76] -5.510911e-16  1.883716e-01  3.759997e-01  5.621439e-01  7.460697e-01
##  [81]  9.270510e-01  1.104374e+00  1.277338e+00  1.445261e+00  1.607480e+00
##  [86]  1.763356e+00  1.912272e+00  2.053641e+00  2.186906e+00  2.311540e+00
##  [91]  2.427051e+00  2.532984e+00  2.628920e+00  2.714481e+00  2.789329e+00
##  [96]  2.853170e+00  2.905749e+00  2.946862e+00  2.976344e+00  2.994080e+00
## [101]  3.000000e+00
y = R*sin(ome*t)
y
##   [1]  0.000000e+00  1.883716e-01  3.759997e-01  5.621439e-01  7.460697e-01
##   [6]  9.270510e-01  1.104374e+00  1.277338e+00  1.445261e+00  1.607480e+00
##  [11]  1.763356e+00  1.912272e+00  2.053641e+00  2.186906e+00  2.311540e+00
##  [16]  2.427051e+00  2.532984e+00  2.628920e+00  2.714481e+00  2.789329e+00
##  [21]  2.853170e+00  2.905749e+00  2.946862e+00  2.976344e+00  2.994080e+00
##  [26]  3.000000e+00  2.994080e+00  2.976344e+00  2.946862e+00  2.905749e+00
##  [31]  2.853170e+00  2.789329e+00  2.714481e+00  2.628920e+00  2.532984e+00
##  [36]  2.427051e+00  2.311540e+00  2.186906e+00  2.053641e+00  1.912272e+00
##  [41]  1.763356e+00  1.607480e+00  1.445261e+00  1.277338e+00  1.104374e+00
##  [46]  9.270510e-01  7.460697e-01  5.621439e-01  3.759997e-01  1.883716e-01
##  [51]  3.673940e-16 -1.883716e-01 -3.759997e-01 -5.621439e-01 -7.460697e-01
##  [56] -9.270510e-01 -1.104374e+00 -1.277338e+00 -1.445261e+00 -1.607480e+00
##  [61] -1.763356e+00 -1.912272e+00 -2.053641e+00 -2.186906e+00 -2.311540e+00
##  [66] -2.427051e+00 -2.532984e+00 -2.628920e+00 -2.714481e+00 -2.789329e+00
##  [71] -2.853170e+00 -2.905749e+00 -2.946862e+00 -2.976344e+00 -2.994080e+00
##  [76] -3.000000e+00 -2.994080e+00 -2.976344e+00 -2.946862e+00 -2.905749e+00
##  [81] -2.853170e+00 -2.789329e+00 -2.714481e+00 -2.628920e+00 -2.532984e+00
##  [86] -2.427051e+00 -2.311540e+00 -2.186906e+00 -2.053641e+00 -1.912272e+00
##  [91] -1.763356e+00 -1.607480e+00 -1.445261e+00 -1.277338e+00 -1.104374e+00
##  [96] -9.270510e-01 -7.460697e-01 -5.621439e-01 -3.759997e-01 -1.883716e-01
## [101] -7.347881e-16
par(mar = c(2,2,2,0.2))
plot(x,y, pch = 16, type = 'o')

plot(x, y, type = 'l', 
     xlim = c(-4,4), ylim = c(-4,4),
     xlab = '', ylab = '', cex.axis = 1.1)
arrows(-3.5, 0, 3.8, 0, angle = 9)
arrows(0, -3.5, 0, 3.8, angle = 9)
points(3*sqrt(2)/2, 3*sqrt(2)/2, 
       pch =16, col = 'red', cex = 0.5)
tau = seq(-1,1, len =11)  

tau
##  [1] -1.0 -0.8 -0.6 -0.4 -0.2  0.0  0.2  0.4  0.6  0.8  1.0
xt = 3*sqrt(2)/2 * (1 - tau)
xt
##  [1] 4.2426407 3.8183766 3.3941125 2.9698485 2.5455844 2.1213203 1.6970563
##  [8] 1.2727922 0.8485281 0.4242641 0.0000000
yt = 3*sqrt(2)/2 * (1 + tau)
yt
##  [1] 0.0000000 0.4242641 0.8485281 1.2727922 1.6970563 2.1213203 2.5455844
##  [8] 2.9698485 3.3941125 3.8183766 4.2426407
points(xt, yt, pch = 16, type = 'l', col = 'blue')
text(-0.4, -0.3, 'O', cex = 1.5)
text(3.6, -0.3, 'x', cex = 1.3)
text(-0.3, 3.6, 'y', cex = 1.3)

R Code for Fig. 6.16

#Helix and its tangent line
#install.packages("plot3D")
library("plot3D")
R = 3
ome = 2*pi
c=1
t = seq(0, 3.11, len = 1000)
x = R*cos(ome*t)
y = R*sin(ome*t)
z = c*t
t0 = 1.863
tau = seq(-0.15, 0.15, len =300)
xt = R*cos(ome*t0) - R*ome*sin(ome*t0)*tau
yt = R*sin(ome*t0) + R*ome*cos(ome*t0)*tau
zt = c*t0 + c*tau
par(mar = c(1,2,0.4,0.0))
scatter3D(c(x,xt), c(y,yt), c(z,zt), pch ='-', 
          cex =0.6, col = 'blue', colvar = NULL,
          ticktype = "detailed",
          xlim =c(-3,3), ylim =c(-3,3), zlim=c(0,3))

#Another way
#install.packages('lattice')
library(lattice)
R = 3
ome = 2*pi
c = 1
t<-seq(0, 6*pi, length.out=100)
cloud(z~x+y,data.frame(x=R*cos(t),y=R*sin(t), z=c*t),
      type="l", col = 'purple')

#
#
library(lattice)
R = 3
ome = 2*pi
c = 2
t<-seq(0, 3, length.out=1000)
cloud(z~x+y,data.frame(x=R*cos(ome*t),y=R*sin(ome*t), z=c*t),
      type="l", col = 'purple')

3*sqrt(36*pi^2 + 1)
## [1] 56.62819

R Code for Fig. 6.19(a)

#For k = pi
par(mar=c(0,0,0,0))
n = 10000
a = 3
ome = 2
k = pi
t = seq(0, 30*pi , len=n)
theta = ome*t
r = a*cos(k* theta )
x = r*cos( theta )
y = r*sin( theta )
plot (x, y, type = 'l', lwd = 1, col = 'red ',
      frame.plot=FALSE,
      xaxt = 'n', yaxt = 'n',
      xlab = '', ylab= '')
s = 1:(n+1)
arrows (x[s], y[s], x[s+1], y[s+1],
        col = 1:( length (s)-1),
        angle = 30, length = 0.14)

R Code for Fig. 6.19(b)

#The same as above by a different k
par(mar=c(0,0,0,0))
n = 10000
a = 3
ome = 2
k = sqrt(2) #different k
t = seq(0, 30*pi , len=n)
theta = ome*t
r = a*cos(k* theta )
x = r*cos( theta )
y = r*sin( theta )
plot (x, y, type = 'l', lwd = 1, col = 'red ',
      frame.plot=FALSE,
      xaxt = 'n', yaxt = 'n',
      xlab = '', ylab= '')
s = 1:(n+1)
arrows (x[s], y[s], x[s+1], y[s+1],
        col = 1:( length (s)-1),
        angle = 30, length = 0.14)

R Code for Fig. 6.20(a)

par(mar=c(0,0,0,0))
n = 6000
R = 100
r = 2/3
p = 70
ome = 1
t = seq(0, 30*pi , len=n)
theta = ome*t
x = (R - r)*cos( theta ) + p*cos((R - r)*theta/r)
y = (R - r)*sin( theta ) - p*sin((R - r)*theta/r)
plot (x, y, type = 'l', lwd = 1, col = 'pink',
      frame.plot=FALSE,
      xaxt = 'n', yaxt = 'n',
      xlab = '', ylab= '')
s = 1:(n-1)
arrows (x[s], y[s], x[s+1], y[s+1],
        col = 1:length(s),
        angle = 30, length = 0.14)

R Code for Fig. 6.20(b)

par(mar=c(0,0,0,0))
n = 10000
R = 22
r = 10*2/3
p = -9
ome = sqrt(5)
t = seq(0, 190*pi , len=n)
theta = ome*t
x = (R - r)*cos( theta ) + p*cos((R - r)*theta/r)
y = (R - r)*sin( theta ) - p*sin((R - r)*theta/r)
plot (x, y, type = 'l', lwd = 1, col = 'red',
      frame.plot=FALSE,
      xaxt = 'n', yaxt = 'n',
      xlab = '', ylab= '')
s = 1:(n+1)
arrows (x[s], y[s], x[s+1], y[s+1],
        col = 1:( length(s)-1),
        angle = 30, length = 0.14)

Compute the Length of the Curve

n = 401

t = seq(0, 1, len = n)
t
##   [1] 0.0000 0.0025 0.0050 0.0075 0.0100 0.0125 0.0150 0.0175 0.0200 0.0225
##  [11] 0.0250 0.0275 0.0300 0.0325 0.0350 0.0375 0.0400 0.0425 0.0450 0.0475
##  [21] 0.0500 0.0525 0.0550 0.0575 0.0600 0.0625 0.0650 0.0675 0.0700 0.0725
##  [31] 0.0750 0.0775 0.0800 0.0825 0.0850 0.0875 0.0900 0.0925 0.0950 0.0975
##  [41] 0.1000 0.1025 0.1050 0.1075 0.1100 0.1125 0.1150 0.1175 0.1200 0.1225
##  [51] 0.1250 0.1275 0.1300 0.1325 0.1350 0.1375 0.1400 0.1425 0.1450 0.1475
##  [61] 0.1500 0.1525 0.1550 0.1575 0.1600 0.1625 0.1650 0.1675 0.1700 0.1725
##  [71] 0.1750 0.1775 0.1800 0.1825 0.1850 0.1875 0.1900 0.1925 0.1950 0.1975
##  [81] 0.2000 0.2025 0.2050 0.2075 0.2100 0.2125 0.2150 0.2175 0.2200 0.2225
##  [91] 0.2250 0.2275 0.2300 0.2325 0.2350 0.2375 0.2400 0.2425 0.2450 0.2475
## [101] 0.2500 0.2525 0.2550 0.2575 0.2600 0.2625 0.2650 0.2675 0.2700 0.2725
## [111] 0.2750 0.2775 0.2800 0.2825 0.2850 0.2875 0.2900 0.2925 0.2950 0.2975
## [121] 0.3000 0.3025 0.3050 0.3075 0.3100 0.3125 0.3150 0.3175 0.3200 0.3225
## [131] 0.3250 0.3275 0.3300 0.3325 0.3350 0.3375 0.3400 0.3425 0.3450 0.3475
## [141] 0.3500 0.3525 0.3550 0.3575 0.3600 0.3625 0.3650 0.3675 0.3700 0.3725
## [151] 0.3750 0.3775 0.3800 0.3825 0.3850 0.3875 0.3900 0.3925 0.3950 0.3975
## [161] 0.4000 0.4025 0.4050 0.4075 0.4100 0.4125 0.4150 0.4175 0.4200 0.4225
## [171] 0.4250 0.4275 0.4300 0.4325 0.4350 0.4375 0.4400 0.4425 0.4450 0.4475
## [181] 0.4500 0.4525 0.4550 0.4575 0.4600 0.4625 0.4650 0.4675 0.4700 0.4725
## [191] 0.4750 0.4775 0.4800 0.4825 0.4850 0.4875 0.4900 0.4925 0.4950 0.4975
## [201] 0.5000 0.5025 0.5050 0.5075 0.5100 0.5125 0.5150 0.5175 0.5200 0.5225
## [211] 0.5250 0.5275 0.5300 0.5325 0.5350 0.5375 0.5400 0.5425 0.5450 0.5475
## [221] 0.5500 0.5525 0.5550 0.5575 0.5600 0.5625 0.5650 0.5675 0.5700 0.5725
## [231] 0.5750 0.5775 0.5800 0.5825 0.5850 0.5875 0.5900 0.5925 0.5950 0.5975
## [241] 0.6000 0.6025 0.6050 0.6075 0.6100 0.6125 0.6150 0.6175 0.6200 0.6225
## [251] 0.6250 0.6275 0.6300 0.6325 0.6350 0.6375 0.6400 0.6425 0.6450 0.6475
## [261] 0.6500 0.6525 0.6550 0.6575 0.6600 0.6625 0.6650 0.6675 0.6700 0.6725
## [271] 0.6750 0.6775 0.6800 0.6825 0.6850 0.6875 0.6900 0.6925 0.6950 0.6975
## [281] 0.7000 0.7025 0.7050 0.7075 0.7100 0.7125 0.7150 0.7175 0.7200 0.7225
## [291] 0.7250 0.7275 0.7300 0.7325 0.7350 0.7375 0.7400 0.7425 0.7450 0.7475
## [301] 0.7500 0.7525 0.7550 0.7575 0.7600 0.7625 0.7650 0.7675 0.7700 0.7725
## [311] 0.7750 0.7775 0.7800 0.7825 0.7850 0.7875 0.7900 0.7925 0.7950 0.7975
## [321] 0.8000 0.8025 0.8050 0.8075 0.8100 0.8125 0.8150 0.8175 0.8200 0.8225
## [331] 0.8250 0.8275 0.8300 0.8325 0.8350 0.8375 0.8400 0.8425 0.8450 0.8475
## [341] 0.8500 0.8525 0.8550 0.8575 0.8600 0.8625 0.8650 0.8675 0.8700 0.8725
## [351] 0.8750 0.8775 0.8800 0.8825 0.8850 0.8875 0.8900 0.8925 0.8950 0.8975
## [361] 0.9000 0.9025 0.9050 0.9075 0.9100 0.9125 0.9150 0.9175 0.9200 0.9225
## [371] 0.9250 0.9275 0.9300 0.9325 0.9350 0.9375 0.9400 0.9425 0.9450 0.9475
## [381] 0.9500 0.9525 0.9550 0.9575 0.9600 0.9625 0.9650 0.9675 0.9700 0.9725
## [391] 0.9750 0.9775 0.9800 0.9825 0.9850 0.9875 0.9900 0.9925 0.9950 0.9975
## [401] 1.0000
x = 2*cos(2*pi*t)
x
##   [1]  2.000000e+00  1.999753e+00  1.999013e+00  1.997780e+00  1.996053e+00
##   [6]  1.993835e+00  1.991124e+00  1.987922e+00  1.984229e+00  1.980047e+00
##  [11]  1.975377e+00  1.970219e+00  1.964575e+00  1.958446e+00  1.951834e+00
##  [16]  1.944740e+00  1.937166e+00  1.929115e+00  1.920587e+00  1.911586e+00
##  [21]  1.902113e+00  1.892171e+00  1.881762e+00  1.870888e+00  1.859553e+00
##  [26]  1.847759e+00  1.835509e+00  1.822807e+00  1.809654e+00  1.796055e+00
##  [31]  1.782013e+00  1.767531e+00  1.752613e+00  1.737263e+00  1.721484e+00
##  [36]  1.705280e+00  1.688656e+00  1.671615e+00  1.654161e+00  1.636299e+00
##  [41]  1.618034e+00  1.599369e+00  1.580310e+00  1.560861e+00  1.541026e+00
##  [46]  1.520812e+00  1.500222e+00  1.479262e+00  1.457937e+00  1.436253e+00
##  [51]  1.414214e+00  1.391826e+00  1.369094e+00  1.346025e+00  1.322624e+00
##  [56]  1.298896e+00  1.274848e+00  1.250485e+00  1.225814e+00  1.200840e+00
##  [61]  1.175571e+00  1.150011e+00  1.124167e+00  1.098046e+00  1.071654e+00
##  [66]  1.044997e+00  1.018083e+00  9.909173e-01  9.635073e-01  9.358596e-01
##  [71]  9.079810e-01  8.798783e-01  8.515586e-01  8.230287e-01  7.942958e-01
##  [76]  7.653669e-01  7.362491e-01  7.069497e-01  6.774758e-01  6.478348e-01
##  [81]  6.180340e-01  5.880807e-01  5.579822e-01  5.277461e-01  4.973798e-01
##  [86]  4.668907e-01  4.362865e-01  4.055746e-01  3.747626e-01  3.438582e-01
##  [91]  3.128689e-01  2.818025e-01  2.506665e-01  2.194686e-01  1.882166e-01
##  [96]  1.569182e-01  1.255810e-01  9.421290e-02  6.282152e-02  3.141463e-02
## [101]  1.224647e-16 -3.141463e-02 -6.282152e-02 -9.421290e-02 -1.255810e-01
## [106] -1.569182e-01 -1.882166e-01 -2.194686e-01 -2.506665e-01 -2.818025e-01
## [111] -3.128689e-01 -3.438582e-01 -3.747626e-01 -4.055746e-01 -4.362865e-01
## [116] -4.668907e-01 -4.973798e-01 -5.277461e-01 -5.579822e-01 -5.880807e-01
## [121] -6.180340e-01 -6.478348e-01 -6.774758e-01 -7.069497e-01 -7.362491e-01
## [126] -7.653669e-01 -7.942958e-01 -8.230287e-01 -8.515586e-01 -8.798783e-01
## [131] -9.079810e-01 -9.358596e-01 -9.635073e-01 -9.909173e-01 -1.018083e+00
## [136] -1.044997e+00 -1.071654e+00 -1.098046e+00 -1.124167e+00 -1.150011e+00
## [141] -1.175571e+00 -1.200840e+00 -1.225814e+00 -1.250485e+00 -1.274848e+00
## [146] -1.298896e+00 -1.322624e+00 -1.346025e+00 -1.369094e+00 -1.391826e+00
## [151] -1.414214e+00 -1.436253e+00 -1.457937e+00 -1.479262e+00 -1.500222e+00
## [156] -1.520812e+00 -1.541026e+00 -1.560861e+00 -1.580310e+00 -1.599369e+00
## [161] -1.618034e+00 -1.636299e+00 -1.654161e+00 -1.671615e+00 -1.688656e+00
## [166] -1.705280e+00 -1.721484e+00 -1.737263e+00 -1.752613e+00 -1.767531e+00
## [171] -1.782013e+00 -1.796055e+00 -1.809654e+00 -1.822807e+00 -1.835509e+00
## [176] -1.847759e+00 -1.859553e+00 -1.870888e+00 -1.881762e+00 -1.892171e+00
## [181] -1.902113e+00 -1.911586e+00 -1.920587e+00 -1.929115e+00 -1.937166e+00
## [186] -1.944740e+00 -1.951834e+00 -1.958446e+00 -1.964575e+00 -1.970219e+00
## [191] -1.975377e+00 -1.980047e+00 -1.984229e+00 -1.987922e+00 -1.991124e+00
## [196] -1.993835e+00 -1.996053e+00 -1.997780e+00 -1.999013e+00 -1.999753e+00
## [201] -2.000000e+00 -1.999753e+00 -1.999013e+00 -1.997780e+00 -1.996053e+00
## [206] -1.993835e+00 -1.991124e+00 -1.987922e+00 -1.984229e+00 -1.980047e+00
## [211] -1.975377e+00 -1.970219e+00 -1.964575e+00 -1.958446e+00 -1.951834e+00
## [216] -1.944740e+00 -1.937166e+00 -1.929115e+00 -1.920587e+00 -1.911586e+00
## [221] -1.902113e+00 -1.892171e+00 -1.881762e+00 -1.870888e+00 -1.859553e+00
## [226] -1.847759e+00 -1.835509e+00 -1.822807e+00 -1.809654e+00 -1.796055e+00
## [231] -1.782013e+00 -1.767531e+00 -1.752613e+00 -1.737263e+00 -1.721484e+00
## [236] -1.705280e+00 -1.688656e+00 -1.671615e+00 -1.654161e+00 -1.636299e+00
## [241] -1.618034e+00 -1.599369e+00 -1.580310e+00 -1.560861e+00 -1.541026e+00
## [246] -1.520812e+00 -1.500222e+00 -1.479262e+00 -1.457937e+00 -1.436253e+00
## [251] -1.414214e+00 -1.391826e+00 -1.369094e+00 -1.346025e+00 -1.322624e+00
## [256] -1.298896e+00 -1.274848e+00 -1.250485e+00 -1.225814e+00 -1.200840e+00
## [261] -1.175571e+00 -1.150011e+00 -1.124167e+00 -1.098046e+00 -1.071654e+00
## [266] -1.044997e+00 -1.018083e+00 -9.909173e-01 -9.635073e-01 -9.358596e-01
## [271] -9.079810e-01 -8.798783e-01 -8.515586e-01 -8.230287e-01 -7.942958e-01
## [276] -7.653669e-01 -7.362491e-01 -7.069497e-01 -6.774758e-01 -6.478348e-01
## [281] -6.180340e-01 -5.880807e-01 -5.579822e-01 -5.277461e-01 -4.973798e-01
## [286] -4.668907e-01 -4.362865e-01 -4.055746e-01 -3.747626e-01 -3.438582e-01
## [291] -3.128689e-01 -2.818025e-01 -2.506665e-01 -2.194686e-01 -1.882166e-01
## [296] -1.569182e-01 -1.255810e-01 -9.421290e-02 -6.282152e-02 -3.141463e-02
## [301] -3.673940e-16  3.141463e-02  6.282152e-02  9.421290e-02  1.255810e-01
## [306]  1.569182e-01  1.882166e-01  2.194686e-01  2.506665e-01  2.818025e-01
## [311]  3.128689e-01  3.438582e-01  3.747626e-01  4.055746e-01  4.362865e-01
## [316]  4.668907e-01  4.973798e-01  5.277461e-01  5.579822e-01  5.880807e-01
## [321]  6.180340e-01  6.478348e-01  6.774758e-01  7.069497e-01  7.362491e-01
## [326]  7.653669e-01  7.942958e-01  8.230287e-01  8.515586e-01  8.798783e-01
## [331]  9.079810e-01  9.358596e-01  9.635073e-01  9.909173e-01  1.018083e+00
## [336]  1.044997e+00  1.071654e+00  1.098046e+00  1.124167e+00  1.150011e+00
## [341]  1.175571e+00  1.200840e+00  1.225814e+00  1.250485e+00  1.274848e+00
## [346]  1.298896e+00  1.322624e+00  1.346025e+00  1.369094e+00  1.391826e+00
## [351]  1.414214e+00  1.436253e+00  1.457937e+00  1.479262e+00  1.500222e+00
## [356]  1.520812e+00  1.541026e+00  1.560861e+00  1.580310e+00  1.599369e+00
## [361]  1.618034e+00  1.636299e+00  1.654161e+00  1.671615e+00  1.688656e+00
## [366]  1.705280e+00  1.721484e+00  1.737263e+00  1.752613e+00  1.767531e+00
## [371]  1.782013e+00  1.796055e+00  1.809654e+00  1.822807e+00  1.835509e+00
## [376]  1.847759e+00  1.859553e+00  1.870888e+00  1.881762e+00  1.892171e+00
## [381]  1.902113e+00  1.911586e+00  1.920587e+00  1.929115e+00  1.937166e+00
## [386]  1.944740e+00  1.951834e+00  1.958446e+00  1.964575e+00  1.970219e+00
## [391]  1.975377e+00  1.980047e+00  1.984229e+00  1.987922e+00  1.991124e+00
## [396]  1.993835e+00  1.996053e+00  1.997780e+00  1.999013e+00  1.999753e+00
## [401]  2.000000e+00
dx = x[5] - x[4]
dx
## [1] -0.001726293
y = 2*sin(2*pi*t)
y
##   [1]  0.000000e+00  3.141463e-02  6.282152e-02  9.421290e-02  1.255810e-01
##   [6]  1.569182e-01  1.882166e-01  2.194686e-01  2.506665e-01  2.818025e-01
##  [11]  3.128689e-01  3.438582e-01  3.747626e-01  4.055746e-01  4.362865e-01
##  [16]  4.668907e-01  4.973798e-01  5.277461e-01  5.579822e-01  5.880807e-01
##  [21]  6.180340e-01  6.478348e-01  6.774758e-01  7.069497e-01  7.362491e-01
##  [26]  7.653669e-01  7.942958e-01  8.230287e-01  8.515586e-01  8.798783e-01
##  [31]  9.079810e-01  9.358596e-01  9.635073e-01  9.909173e-01  1.018083e+00
##  [36]  1.044997e+00  1.071654e+00  1.098046e+00  1.124167e+00  1.150011e+00
##  [41]  1.175571e+00  1.200840e+00  1.225814e+00  1.250485e+00  1.274848e+00
##  [46]  1.298896e+00  1.322624e+00  1.346025e+00  1.369094e+00  1.391826e+00
##  [51]  1.414214e+00  1.436253e+00  1.457937e+00  1.479262e+00  1.500222e+00
##  [56]  1.520812e+00  1.541026e+00  1.560861e+00  1.580310e+00  1.599369e+00
##  [61]  1.618034e+00  1.636299e+00  1.654161e+00  1.671615e+00  1.688656e+00
##  [66]  1.705280e+00  1.721484e+00  1.737263e+00  1.752613e+00  1.767531e+00
##  [71]  1.782013e+00  1.796055e+00  1.809654e+00  1.822807e+00  1.835509e+00
##  [76]  1.847759e+00  1.859553e+00  1.870888e+00  1.881762e+00  1.892171e+00
##  [81]  1.902113e+00  1.911586e+00  1.920587e+00  1.929115e+00  1.937166e+00
##  [86]  1.944740e+00  1.951834e+00  1.958446e+00  1.964575e+00  1.970219e+00
##  [91]  1.975377e+00  1.980047e+00  1.984229e+00  1.987922e+00  1.991124e+00
##  [96]  1.993835e+00  1.996053e+00  1.997780e+00  1.999013e+00  1.999753e+00
## [101]  2.000000e+00  1.999753e+00  1.999013e+00  1.997780e+00  1.996053e+00
## [106]  1.993835e+00  1.991124e+00  1.987922e+00  1.984229e+00  1.980047e+00
## [111]  1.975377e+00  1.970219e+00  1.964575e+00  1.958446e+00  1.951834e+00
## [116]  1.944740e+00  1.937166e+00  1.929115e+00  1.920587e+00  1.911586e+00
## [121]  1.902113e+00  1.892171e+00  1.881762e+00  1.870888e+00  1.859553e+00
## [126]  1.847759e+00  1.835509e+00  1.822807e+00  1.809654e+00  1.796055e+00
## [131]  1.782013e+00  1.767531e+00  1.752613e+00  1.737263e+00  1.721484e+00
## [136]  1.705280e+00  1.688656e+00  1.671615e+00  1.654161e+00  1.636299e+00
## [141]  1.618034e+00  1.599369e+00  1.580310e+00  1.560861e+00  1.541026e+00
## [146]  1.520812e+00  1.500222e+00  1.479262e+00  1.457937e+00  1.436253e+00
## [151]  1.414214e+00  1.391826e+00  1.369094e+00  1.346025e+00  1.322624e+00
## [156]  1.298896e+00  1.274848e+00  1.250485e+00  1.225814e+00  1.200840e+00
## [161]  1.175571e+00  1.150011e+00  1.124167e+00  1.098046e+00  1.071654e+00
## [166]  1.044997e+00  1.018083e+00  9.909173e-01  9.635073e-01  9.358596e-01
## [171]  9.079810e-01  8.798783e-01  8.515586e-01  8.230287e-01  7.942958e-01
## [176]  7.653669e-01  7.362491e-01  7.069497e-01  6.774758e-01  6.478348e-01
## [181]  6.180340e-01  5.880807e-01  5.579822e-01  5.277461e-01  4.973798e-01
## [186]  4.668907e-01  4.362865e-01  4.055746e-01  3.747626e-01  3.438582e-01
## [191]  3.128689e-01  2.818025e-01  2.506665e-01  2.194686e-01  1.882166e-01
## [196]  1.569182e-01  1.255810e-01  9.421290e-02  6.282152e-02  3.141463e-02
## [201]  2.449294e-16 -3.141463e-02 -6.282152e-02 -9.421290e-02 -1.255810e-01
## [206] -1.569182e-01 -1.882166e-01 -2.194686e-01 -2.506665e-01 -2.818025e-01
## [211] -3.128689e-01 -3.438582e-01 -3.747626e-01 -4.055746e-01 -4.362865e-01
## [216] -4.668907e-01 -4.973798e-01 -5.277461e-01 -5.579822e-01 -5.880807e-01
## [221] -6.180340e-01 -6.478348e-01 -6.774758e-01 -7.069497e-01 -7.362491e-01
## [226] -7.653669e-01 -7.942958e-01 -8.230287e-01 -8.515586e-01 -8.798783e-01
## [231] -9.079810e-01 -9.358596e-01 -9.635073e-01 -9.909173e-01 -1.018083e+00
## [236] -1.044997e+00 -1.071654e+00 -1.098046e+00 -1.124167e+00 -1.150011e+00
## [241] -1.175571e+00 -1.200840e+00 -1.225814e+00 -1.250485e+00 -1.274848e+00
## [246] -1.298896e+00 -1.322624e+00 -1.346025e+00 -1.369094e+00 -1.391826e+00
## [251] -1.414214e+00 -1.436253e+00 -1.457937e+00 -1.479262e+00 -1.500222e+00
## [256] -1.520812e+00 -1.541026e+00 -1.560861e+00 -1.580310e+00 -1.599369e+00
## [261] -1.618034e+00 -1.636299e+00 -1.654161e+00 -1.671615e+00 -1.688656e+00
## [266] -1.705280e+00 -1.721484e+00 -1.737263e+00 -1.752613e+00 -1.767531e+00
## [271] -1.782013e+00 -1.796055e+00 -1.809654e+00 -1.822807e+00 -1.835509e+00
## [276] -1.847759e+00 -1.859553e+00 -1.870888e+00 -1.881762e+00 -1.892171e+00
## [281] -1.902113e+00 -1.911586e+00 -1.920587e+00 -1.929115e+00 -1.937166e+00
## [286] -1.944740e+00 -1.951834e+00 -1.958446e+00 -1.964575e+00 -1.970219e+00
## [291] -1.975377e+00 -1.980047e+00 -1.984229e+00 -1.987922e+00 -1.991124e+00
## [296] -1.993835e+00 -1.996053e+00 -1.997780e+00 -1.999013e+00 -1.999753e+00
## [301] -2.000000e+00 -1.999753e+00 -1.999013e+00 -1.997780e+00 -1.996053e+00
## [306] -1.993835e+00 -1.991124e+00 -1.987922e+00 -1.984229e+00 -1.980047e+00
## [311] -1.975377e+00 -1.970219e+00 -1.964575e+00 -1.958446e+00 -1.951834e+00
## [316] -1.944740e+00 -1.937166e+00 -1.929115e+00 -1.920587e+00 -1.911586e+00
## [321] -1.902113e+00 -1.892171e+00 -1.881762e+00 -1.870888e+00 -1.859553e+00
## [326] -1.847759e+00 -1.835509e+00 -1.822807e+00 -1.809654e+00 -1.796055e+00
## [331] -1.782013e+00 -1.767531e+00 -1.752613e+00 -1.737263e+00 -1.721484e+00
## [336] -1.705280e+00 -1.688656e+00 -1.671615e+00 -1.654161e+00 -1.636299e+00
## [341] -1.618034e+00 -1.599369e+00 -1.580310e+00 -1.560861e+00 -1.541026e+00
## [346] -1.520812e+00 -1.500222e+00 -1.479262e+00 -1.457937e+00 -1.436253e+00
## [351] -1.414214e+00 -1.391826e+00 -1.369094e+00 -1.346025e+00 -1.322624e+00
## [356] -1.298896e+00 -1.274848e+00 -1.250485e+00 -1.225814e+00 -1.200840e+00
## [361] -1.175571e+00 -1.150011e+00 -1.124167e+00 -1.098046e+00 -1.071654e+00
## [366] -1.044997e+00 -1.018083e+00 -9.909173e-01 -9.635073e-01 -9.358596e-01
## [371] -9.079810e-01 -8.798783e-01 -8.515586e-01 -8.230287e-01 -7.942958e-01
## [376] -7.653669e-01 -7.362491e-01 -7.069497e-01 -6.774758e-01 -6.478348e-01
## [381] -6.180340e-01 -5.880807e-01 -5.579822e-01 -5.277461e-01 -4.973798e-01
## [386] -4.668907e-01 -4.362865e-01 -4.055746e-01 -3.747626e-01 -3.438582e-01
## [391] -3.128689e-01 -2.818025e-01 -2.506665e-01 -2.194686e-01 -1.882166e-01
## [396] -1.569182e-01 -1.255810e-01 -9.421290e-02 -6.282152e-02 -3.141463e-02
## [401] -4.898587e-16
L = 0
for(i in 1:(n-1)){
  L = L + sqrt((x[i+1] - x[i])^2 + (y[i+1] - y[i])^2)
}
L
## [1] 12.56624
2*pi*2
## [1] 12.56637
x[n]
## [1] 2
n
## [1] 401
length(x)
## [1] 401
x[n+1]
## [1] NA

Curvature

x = seq(-3, 3, len = 100)
y = x^2
plot(x, y, type = 'l')

kappa = 2/(1 + 4*x^2)^(3/2)
plot(x, kappa, type = 'l', col = 'red')

t = seq(0, 2*pi, len = 200)
x = cos(t); y = sin(2*t)
plot(x, y, type = 'l')

t = seq(-50, 50, len = 200)
plot(t^2, t^3, type = 'l')