You are on page 1of 1

File: Unsaved Document 1 Page 1 of 1

f_s <- function(xn, x0, erro) {


return ((((xn-x0)^5)/(2880*erro))^0.25)
}

I_s <- function(xn, x0, n) {


v <- vector(, n)
for (i in (1:n)) {
v[i] <- (xn/n)*i
}
delta = v[1]

impares <- vector(, n/2)


for (i in (1:length(impares))) {
impares[i] <- 4*sin(v[2*i-1])
}

pares <- vector(, n/2-1)


for (i in (1:length(pares))) {
pares[i] <- 2*sin(v[2*i])
}

return (delta/3 * (sin(x0) + sum(pares) + sum(impares) + sin(v[n])))


}

cat("Simpson\n")
v_s <- vector(, 4)
for (i in (2:5)) { v_s[i-1] <- 10^(-i) }
v_s <- f_s(x_max, x_min, v_s)
v_s <- ceiling(v_s)
print(v_s)
for (i in (1:length(v_s))) {
print(I_s(x_max, x_min, v_s[i]))
print(2 - I_s(x_max, x_min, v_s[i]))
}