-
Notifications
You must be signed in to change notification settings - Fork 2
/
12-derivadas-parciales-en-R.R
131 lines (85 loc) · 3.17 KB
/
12-derivadas-parciales-en-R.R
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO
# Facultad de Economía
# Matemáticas I 2021-1
# Profesor: Cesar Hernández
# PRÁCTICA : Derivadas parciales en R
library(Deriv)
library(ggplot2)
library(plot3D)
library(scatterplot3d)
library(grDevices)
# Obteniendo derivadas parciales
f <- function(x, y) x * y
Deriv(f)
# Obteniendo derivadas parciales de funciones trigonométricas
g <- function(x, y) sin(x) * cos(y)
Deriv(g)
# Derivando respecto de "x"
h <- function(x, y) x * y
Deriv(h,"x")
# Derivando respecto de "x"
i <- function(x, y) x * y
Deriv(i,"y")
# Derivando respecto de "y"
j <- function(x, y) sin(x) * cos(y)
Deriv(j,"x")
# Derivando respecto de "y"
k <- function(x, y) sin(x) * cos(y)
Deriv(k,"y")
# Sustituyendo valores para "x", "y" en la función derivada
l <- function(x, y) x * y
lprima <- Deriv(l)
lprima(3,4)
# Sustituyendo valores para "x", "y" en la función derivada
m <- function(x, y) sin(x) * cos(y)
mprima <- Deriv(m)
mprima(3,4)
# Graficando una función en 3D
n <- function(x, y) x * y
x <- seq(1,3,0.1)
y <- seq(1,3,0.1)
z <- n(x,y)
# Gráficas de densidad
df <- data.frame(x,y,z)
ggplot(df, aes(x = x, y = y)) +
geom_point() +
geom_density_2d()
ggplot(df, aes(x = x, y = y) ) +
stat_density_2d(aes(fill = ..level..), geom = "polygon")
ggplot(df, aes(x = x, y = y) ) +
stat_density_2d(aes(fill = ..density..), geom = "raster", contour = FALSE)
ggplot(df, aes(x = x, y = y) ) +
stat_density_2d(aes(fill = ..density..), geom = "raster", contour = FALSE) +
scale_fill_distiller(palette= "Spectral", direction=1)
# Estimación bidimensional de la densidad del núcleo
#library(MASS)
#den3d <- kde2d(x, y)
#image(den3d)
#persp(den3d, box=FALSE)
# Graficando con points3D
points3D (x, y, z)
points3D (x, y, z, phi = 0, bty = "g")
points3D (x, y, z, phi = 5, bty = "b2")
points3D (x, y, z, phi = 0, bty = "g", colkey = F)
points3D (x, y, z, phi = 0, bty = "g", pch = 4)
points3D (x, y, z, phi = 0, bty = "g", pch = "$")
points3D (x, y, z, phi = 0, bty = "g", pch = 10, col = topo.colors(21))
# Graficando con scatter3D
scatter3D(x, y, z)
scatter3D(x, y, z,ticktype = "detailed")
scatter3D(x, y, z, phi = 0, bty = "g", type = "l", ticktype = "detailed",
lwd = 4, col = topo.colors(50))
scatter3D(x, y, z, phi = 0, bty = "b2", type = "b", ticktype = "detailed",
pch = 20, cex = c(0.5, 1, 1.5))
scatter3D(x, y, z, phi = 0, bty = "g", type = "h", ticktype = "detailed")
# Graficando con scatterplot3D
scatterplot3d(x, y, z)
scatterplot3d(x, y, z, highlight.3d = TRUE, col.axis="blue", col.grid="lightblue",
main = "scatterplot3d - 1", pch=20)
scatterplot3d(x, y, z, highlight.3d = F, col.axis="green", col.grid="lightgreen",
main = "scatterplot3d - 2", pch=1)
scatterplot3d(x, y, z, pch = 5, xlim = c(0, 4), ylim = c(0, 4), zlim = c(0, 11),
main = "scatterplot3d - 3")
scatterplot3d(x, y, z, pch = 7, xlim = c(0, 4), ylim = c(0, 4), zlim = c(0, 11),
color = rainbow(21), col.axis ="red", col.grid ="orange",
main = "scatterplot3d - 4")