Polynomial_plot_Codes
Polynomial_plot_Codes
## Polynomial of degree 2 ( y = a + b x + c x )
2
## Plot y = a + b*x + c*(x^2) ; 0 < x < 3.0 for a=2.0, b=3, c=1.0
## R Code, using plot() function we execute as
x <- seq(0, 3.0, by=0.01)
y <- 2.0 - 3*x + 1.0*(x^2)
plot(x, y, type="l", lwd=2, col="blue")
2.0
1.5
1.0
y
0.5
0.0
5
4
3
2
-2 -1 0 1 2
x
## Using the curve() function
curve(2.0 + 0.5*x + 1.5*(x^2),from=-2.0, to=2.0, lwd=2, col="red")
## ----------------------------------------------------------
## Plot y = a + b*x + c*(x^2) ; -2.0 <x <2.0 for a=-10.0, b=-1.5, c=5.0
x <- seq(-2.0, 2.0, by=0.01)
y <- -10.0 - 1.5*x + 5.0*{x^2}
plot(x, y, type="l", lwd=2, col="blue")
10
5
y
0
-5
-10
-2 -1 0 1 2
## ***********************************************************
## Polynomial of degree 3 ( y = a + b x + c x + d x )
2 3
5
0
-5
-10
-2 -1 0 1 2
x
## ----------------------------------------------------------
## Plot y = a + b*x + c*(x^2) +d*(x^3) ; -2 < x < 2 for a=-10.0, b=-
1.5, c=5.0 and d=2.0
x <- seq(-2.0, 2.0, by=0.01)
y <- -10.0 - 1.5*x + 5.0*{x^2}+ 2.0*(x^3)
plot(x, y, type="l", lwd=2, col="blue")
20
15
10
y
5
0
-5
-10
-2 -1 0 1 2
## ----------------------------------------------------------
## Plot y = a + b*x + c*(x^2) +d*(x^3) ; -5 < x < 5 for a=4.0, b=3.0,
c=5.0 and d=2.0
x <- seq(-5.0, 5.0, by=0.01)
y <- 4.0 + 3.0*x + 5.0*{x^2}+ 2.0*(x^3)
plot(x, y, type="l", lwd=2, col="blue")
400
300
200
y
100
0
-100
-4 -2 0 2 4
x
## ***********************************************************
## Polynomial of degree 4 ( y = a + b x + c x + d x + e x )
2 3 4
0
-10
-20
-2 -1 0 1 2
## ----------------------------------------------------------
## Plot y = a + b*x + c*(x^2) +d*(x^3)+e*(x^4) ; -2 < x < 2
## for a=-12.0, b=-4.0, c=3.0, d=-2.0 and e=3.0
x <- seq(-2.0, 2.0, by=0.01)
y <- -12.0 -4.0*x + 3.0*{x^2}- 2.0*(x^3)+3*(x^4)
plot(x, y, type="l", lwd=2, col="blue")
60
40
y
20
0
-2 -1 0 1 2
x
## ***********************************************************
Ex: Plot y = x^3-6*x+11*x-6 ; 0 < x < 4
x <- seq(0, 4, by=0.01)
y <- -6 + 11*x -6*{x^2}+ 1.0*(x^3)
plot(x, y, type="l", lwd=2, col="red")
abline(h=0) # adds horizontal line
6
4
2
0
y
-2
-4
-6
0 1 2 3 4
## ----------------------------------------------------------
Ex: Plot y = x^4-10*(x^3) +35*(x^2)-50*x+24 ; 0.5 < x < 4.5
x <- seq(0.5, 4.5, by=0.01)
y <- 24.0 -50.0*x + 35.0*{x^2}- 10.0*(x^3)+1.0*(x^4)
plot(x, y, type="l", lwd=2, col="blue")
6
4
y
2
0
1 2 3 4