enviarmetodospredictivos
DESCRIPTION
facilTRANSCRIPT
![Page 1: ENVIARMETODOSPREDICTIVOS](https://reader035.vdocuments.pub/reader035/viewer/2022072002/563db94a550346aa9a9be2a0/html5/thumbnails/1.jpg)
UNIVERSIDAD NACIONAL DEL ALTIPLANO
FACULTAD DE INGENIERIA MECANICA ELECTRICA, ELECTRONICA Y SISTEMAS
ESCUELA PROFESIONAL INGENIERIA DE SISTEMAS
TALLER DE DESARROLLO DE APLICACIONES
PRÁCTICA R CON FUNCIONES
ESTUDIANTE: Santos Miguel Choque sarmiento
CODIGO: 135257
![Page 2: ENVIARMETODOSPREDICTIVOS](https://reader035.vdocuments.pub/reader035/viewer/2022072002/563db94a550346aa9a9be2a0/html5/thumbnails/2.jpg)
PREGUNTA 01
factorial = function(n)
{
if(n == 1 || n == 0)
{ return (1) }
if(n > 0)
{ return (n * factorial(n-1)) }
else { return ("NO EXISTE EL FACTORIAL NEGATIVO")}
}
x = factorial(-1)
x
PREGUNTA 02
res=0
c=0
c2=0
nc=0
a=0
n=0
primos<-function(a,n){
for(c in a:n){
for(c2 in 1:c){
res=c%%c2
if(res==0)
{
nc=nc+1
}
}
if(nc==2){
print(" ")
print(c)
}
nc=0
}
}
Primos(2,9)
![Page 3: ENVIARMETODOSPREDICTIVOS](https://reader035.vdocuments.pub/reader035/viewer/2022072002/563db94a550346aa9a9be2a0/html5/thumbnails/3.jpg)
PREGUNTA 04
Mcd<-function(a,b){
if(a==b)
m<-a
else{
if(a<b)
m=Mcd(a,b-a)
else
m=Mcd(a-b,b)
return (m)
}
}
Mcd(18,24)
PREGUNTA 05
𝒆𝒙 = 𝒙𝟎
𝟎!+
𝒙𝟏
𝟏!+
𝒙𝟐
𝟐!+
𝒙𝟑
𝟑!+ ⋯
𝒆𝒙 = 𝟑𝟎
𝟎!+
𝟑𝟏
𝟏!+
𝟑𝟐
𝟐!+
𝟑𝟑
𝟑!= 𝟏𝟑
factorial = function(n)
{
if(n == 1 || n == 0)
{ return (1) }
else (n > 0)
{ return (n * factorial(n-1))}
}
taylor = function(x)
{
p = 0
for(i in 0:x)
{
p = p + (x^i)/factorial(i)
}
return (p)
}
x = taylor(3)
x
![Page 4: ENVIARMETODOSPREDICTIVOS](https://reader035.vdocuments.pub/reader035/viewer/2022072002/563db94a550346aa9a9be2a0/html5/thumbnails/4.jpg)
PREGUNTA 06
𝐬𝐢𝐧 𝒙 = 𝒙𝟏
𝟏!−
𝒙𝟑
𝟑!+
𝒙𝟓
𝟓!+ ⋯
𝐬𝐢𝐧 𝒙 = ∑(−𝟏)𝒏
(𝟐𝒏 + 𝟏)𝒙(𝟐𝒏+𝟏)
∞
𝒏=𝟎
factorial = function(n)
{
if(n == 1 || n == 0)
{ return (1) }
else (n > 0)
{ return (n * factorial(n-1))}
}
seno_x = function(x)
{
t = 0
signo = (x >= 0)
x = abs(x)
while (x > pi)
{
x = x - pi
signo = !signo
}
i = 0
while(i < 9)
{
t=t+((-1)^i)*( x ^(2*i + 1))/factorial(2*i+1)
i = i + 1
}
if (!signo)
{
t = t * (-1)
}
return (t)
}
Y = seno_x(5)
Y
![Page 5: ENVIARMETODOSPREDICTIVOS](https://reader035.vdocuments.pub/reader035/viewer/2022072002/563db94a550346aa9a9be2a0/html5/thumbnails/5.jpg)
PREGUNTA 08
Referencia de guia: https://www.youtube.com/watch?v=_pSJQO_9I4k
#utlizando read para archivos excel
d<-read.csv("a.csv",header=FALSE)
d
V1
1 0.0
2 2.2
3 3.3
4 4.4
d.V1
d$V1
[1] 0.0 2.2 3.3 4.4
sum(d$V1)
[1] 9.9
#utlizando scan para archivos txt
archivo<-function(){
vec<-scan("UnVec.txt")
archivo<-sum(vec)
}
PREGUNTA 10
grafico<-function(n){
a <- rnorm(n)
hist(a, col="blue",border="white",prob=FALSE)
}
grafico(150)
FUNCIONES RECURSIVAS
PREGUNTA 12
suma<-function(a,b){
if(b==0)
S<-a
else{
S=suma(a,b-1)+1
return(S)
}
}
suma(4,6)
![Page 6: ENVIARMETODOSPREDICTIVOS](https://reader035.vdocuments.pub/reader035/viewer/2022072002/563db94a550346aa9a9be2a0/html5/thumbnails/6.jpg)
PREGUNTA 13
primo<-function(a){
for(i in 2:(a)/2){
f(a%%2==0){
return ("no es primo"); }
else{
if(a%%2!=0){
return ("es primo");
}
}
}
}
PREGUNTA 14
cadena<-function(c){
a=c(2,3,5)
c=sort(a, decreasing=TRUE)
return(c)
}
c
PREGUNTA 15
Pascal <- function(filas){
aux <- matrix(nrow=filas+1,ncol=filas)
for (j in 1:filas){
aux[1,j] <- "-"
}
for (i in 1:filas+1){
for (j in 0:filas)
aux[i,j] <- "."
}
for(i in 1:filas+1){
j <- 1
aux[i,j] <- 1
while(i-1 > j){
aux[i,j+1] <- factorial(i-
2)/(factorial(j)*(factorial((i-2)-j)))
j <- j+1
}
}
print(data.frame(aux,check.names=F), row.names = FALSE)
}
Pascal(5)