Demonstration of the parameters of a straight line

Parikshit Sanyal
09 Sep 18

Introduction

A straight line is described by the equation

y = mx + c

Where m is the tangent of the line and c the intercept of y axis

The application

This applications inputs the two parameters as slider values, and draws the resultant line

Calculation

For any value x, y is calculated as y = mx + c; for example if m is 1 and c is -1

x <- seq(-1,1,0.01)
y <- x - 1
y
  [1] -2.00 -1.99 -1.98 -1.97 -1.96 -1.95 -1.94 -1.93 -1.92 -1.91 -1.90
 [12] -1.89 -1.88 -1.87 -1.86 -1.85 -1.84 -1.83 -1.82 -1.81 -1.80 -1.79
 [23] -1.78 -1.77 -1.76 -1.75 -1.74 -1.73 -1.72 -1.71 -1.70 -1.69 -1.68
 [34] -1.67 -1.66 -1.65 -1.64 -1.63 -1.62 -1.61 -1.60 -1.59 -1.58 -1.57
 [45] -1.56 -1.55 -1.54 -1.53 -1.52 -1.51 -1.50 -1.49 -1.48 -1.47 -1.46
 [56] -1.45 -1.44 -1.43 -1.42 -1.41 -1.40 -1.39 -1.38 -1.37 -1.36 -1.35
 [67] -1.34 -1.33 -1.32 -1.31 -1.30 -1.29 -1.28 -1.27 -1.26 -1.25 -1.24
 [78] -1.23 -1.22 -1.21 -1.20 -1.19 -1.18 -1.17 -1.16 -1.15 -1.14 -1.13
 [89] -1.12 -1.11 -1.10 -1.09 -1.08 -1.07 -1.06 -1.05 -1.04 -1.03 -1.02
[100] -1.01 -1.00 -0.99 -0.98 -0.97 -0.96 -0.95 -0.94 -0.93 -0.92 -0.91
[111] -0.90 -0.89 -0.88 -0.87 -0.86 -0.85 -0.84 -0.83 -0.82 -0.81 -0.80
[122] -0.79 -0.78 -0.77 -0.76 -0.75 -0.74 -0.73 -0.72 -0.71 -0.70 -0.69
[133] -0.68 -0.67 -0.66 -0.65 -0.64 -0.63 -0.62 -0.61 -0.60 -0.59 -0.58
[144] -0.57 -0.56 -0.55 -0.54 -0.53 -0.52 -0.51 -0.50 -0.49 -0.48 -0.47
[155] -0.46 -0.45 -0.44 -0.43 -0.42 -0.41 -0.40 -0.39 -0.38 -0.37 -0.36
[166] -0.35 -0.34 -0.33 -0.32 -0.31 -0.30 -0.29 -0.28 -0.27 -0.26 -0.25
[177] -0.24 -0.23 -0.22 -0.21 -0.20 -0.19 -0.18 -0.17 -0.16 -0.15 -0.14
[188] -0.13 -0.12 -0.11 -0.10 -0.09 -0.08 -0.07 -0.06 -0.05 -0.04 -0.03
[199] -0.02 -0.01  0.00

Plotting the line

The plot is generated from x,y pairs

plot(x,y,type='l')

plot of chunk unnamed-chunk-2