-
Notifications
You must be signed in to change notification settings - Fork 2
/
15-vision-geometrica-de-vectores-en-R.R
128 lines (103 loc) · 2.77 KB
/
15-vision-geometrica-de-vectores-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
# UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO
# Facultad de Economía
# Taller III 2021-1
# Profesor: Cesar Hernández
# PRÁCTICA 6: VISIÓN GEOMÉTRICA DE VERTORES EN R
library(dplyr)
library(ggplot2)
# Vector cero
o<-0
p<-5
v<-o:p
plot(v,v,type = "l")
menosv<-(o:(-p))
plot(menosv,menosv,type = "l",axes = F)
axis(3)
axis(4)
box()
df1<-data.frame(v,menosv)
df1 %>%
ggplot() +
geom_line(aes(x=v, y=v), color="blue") +
geom_line(aes(x=menosv, y=menosv), color="red")
df1 %>%
ggplot() +
geom_line(aes(x=v, y=v), color="blue") +
geom_line(aes(x=menosv, y=menosv), color="red") +
geom_vline(xintercept = 0) +
geom_hline(yintercept = 0)
# Multiplicando por un escalar
t<-3
tv<-t*v
menostv<-(-t)*v
df2<-data.frame(tv,menostv)
df2 %>%
ggplot() +
geom_line(aes(x=tv, y=tv), color="green") +
geom_line(aes(x=menostv, y=menostv), color="orange") +
geom_vline(xintercept = 0) +
geom_hline(yintercept = 0)
comparacion<-data.frame(tv,menostv,v,menosv)
comparacion %>%
ggplot() +
geom_line(aes(x=tv, y=tv), color="green") +
geom_line(aes(x=menostv, y=menostv), color="orange") +
geom_line(aes(x=v, y=v), color="blue") +
geom_line(aes(x=menosv, y=menosv), color="red") +
geom_vline(xintercept = 0) +
geom_hline(yintercept = 0)
# Operaciones con vectores
p1<-4
p2<-16
v1<-seq(0,p1,0.5)
v2<-seq(0,p2,2)
dfv1v2<-data.frame(v1,v2)
dfv1v2 %>%
ggplot() +
geom_line(aes(x=v1, y=(-v1)), color="red") +
geom_line(aes(x=v2, y=v2), color="blue") +
geom_vline(xintercept = 0) +
geom_hline(yintercept = 0)
# Creamos r1 y r2
r1<-v1+p2
r11<-v1-p2
r2<-v2+p1
r22<-v2-p1
dfr1r2<-data.frame(r1,r11,r2,r22,v1,v2)
dfr1r2 %>%
ggplot() +
geom_line(aes(x=r1, y=(-r11)), color="red") +
geom_line(aes(x=r2, y=r22), color="blue") +
geom_vline(xintercept = 0) +
geom_hline(yintercept = 0)
grafica<- dfr1r2 %>%
ggplot() +
geom_line(aes(x=v1, y=(-v1)), color="red") +
geom_line(aes(x=v2, y=v2), color="blue") +
geom_line(aes(x=r1, y=(-r11)), color="red") +
geom_line(aes(x=r2, y=r22), color="blue") +
geom_vline(xintercept = 0) +
geom_hline(yintercept = 0)
grafica
grafica + geom_abline(slope = .60)
# Dibujando un polígono
vx<-0:5
tvx<-vx+5
dfx<-data.frame(vx,tvx)
dfx %>%
ggplot() +
geom_line(aes(x=vx, y=vx), color="red") +
geom_line(aes(x=vx, y=tvx), color="blue") +
vy<-rep(0,6)
tvy<-vy+5
dfxy<-data.frame(vx,vy,tvx,tvy)
dfxy %>%
ggplot() +
geom_line(aes(x=vy, y=vx), color="green") +
geom_line(aes(x=tvy, y=tvx), color="purple")
dfxy %>%
ggplot() +
geom_line(aes(x=vx, y=vx), color="red") +
geom_line(aes(x=vx, y=tvx), color="blue") +
geom_line(aes(x=vy, y=vx), color="green") +
geom_line(aes(x=tvy, y=tvx), color="purple")