Pemograman Statistika

Rangkuman

BAB 1

Instalasi linux on windows, ada beberapa tahapan dalam penginstalan linux di Windows.

  1. Find ‘’Turn windows features on or off’’ di type here to search and click. Seperti yang ditunjukan pada gambar berikut.

  2. Lalu akan muncul dan click centang pada ‘’windows subsystem for linux’’ dan click ok. seperti gambar berikut

  3. Tunggu saja sampai ada tulisan restart now lalu klik restart now. Seperti gambar berikut

  4. Find and click Microsoft store then type ubuntu on search engine at Microsoft store then click Ubunti 18.04 LTS. Seperti gambar berikut

  5. Click get then proses download akan berlangsung tunggu saja.

  6. After finish download then launch ubuntu, maka akan menampilkan seperti gambar berikut.

  7. Bikin account dengan mengisi username, password, lalu enter. Seperti pada gambar berikut.

  8. After finish installation then bisa belajar tutorial melalui link berikut https://www.youtube.com/watch?v=V1y-mbWM3B8

BAB 2

2.1 Dasar - Dasar R

2.1.1 Assignment

Assignment adalah suatu cara untuk memberikan value kepada suatu object. Ada beberapa cara untuk memberikan assign:

  • A <- b artinya object A akan diisi dengan nilai b
A <- 5 
paste('cara assign 1 = ', A)
[1] "cara assign 1 =  5"
  • b -> A sama seperti di no 1 yaitu memberikan nilai kepada si A dengan nilai b meskipun tandanya beda
A = 5
paste('cara assign 2 = ', A)
[1] "cara assign 2 =  5"
  • A = b cara lain untuk memberikan assign bisa dengan pake tanda ‘=’ sama aja seperti ‘<-’
5 -> A 
paste('cara assign 3 = ', A)
[1] "cara assign 3 =  5"
A = 5
paste('cara assign 2 = ', A)
[1] "cara assign 2 =  5"

2.1.2 case-sensitive

sebagai tambahan informasi di R ini sangat sensitive misalkan ingin memberikan nilai 5 kepada object A. maka ketika menuliskan A <- 5 tidak automatis bahwa a kecil akan bernilai 5. Artinya sangat sensitive terhadap penamaan. penamaan object diawali dengan huruf (A-z atau a-z) tidak bisa pake spasi misal jawa Barat <- 10, harus digabung jadi jawa_barat <-10 terdapat operator yang sudah digunakan misal TRUE, FALSE, NULL, dll tidak bisa dijadikan penamaan object

A <- 5 
paste('Nilai A = ', A)
[1] "Nilai A =  5"
a <- 10 
paste('Nilai a = ', a)
[1] "Nilai a =  10"

2.2 Objek di R

terdapat beberapa objeck di R yaitu Vector, Matrix, Array, Factor, List, and DataFrame.

2.2.1 vector

  • Membuat Vector

    #cara 1 membuat vector a1
    a1 <- c(2,4,7,3) 
    a1 
    [1] 2 4 7 3
    #cara 2 membuat vector a2 tidak perlu di define seperti cara 1
    assign("a2",c("2","4","7","3")) 
    a2 
    [1] "2" "4" "7" "3"
  • baris bilangan

    #cara 3 membuat vector a3 dengan selisih 0.5 dimulai dari 1
    a3 <- seq(1,10,by=0.5) 
    a3
     [1]  1.0  1.5  2.0  2.5  3.0  3.5  4.0  4.5  5.0  5.5  6.0  6.5  7.0  7.5  8.0
    [16]  8.5  9.0  9.5 10.0
    #cara 4 membuat vector a4 dengan jumlah data point sebanyak 12
    a4 <- seq(1,10,length.out=12) 
    a4
     [1]  1.000000  1.818182  2.636364  3.454545  4.272727  5.090909  5.909091
     [8]  6.727273  7.545455  8.363636  9.181818 10.000000
  • bilangan berulang

    #cara 5 membuat vector a5 dengan nilai 1 sebanyak 3 kali
    a5 <- rep(1,3)  
    a5
    [1] 1 1 1
    #cara 6 membuat vector a6 dengan nilai 1-3 diulangi sebanyak 3 kali
    a6 <- rep(1:3,3) 
    a6
    [1] 1 2 3 1 2 3 1 2 3
    #cara 7 membuat vector a7 perulangan nilai sesuai dengan posisinya
    a7 <- rep(1:3,1:3) 
    a7
    [1] 1 2 2 3 3 3
    #cara 8 membuat vector a8
    a8 <- rep(1:3,rep(2,3))  
    a8
    [1] 1 1 2 2 3 3
    #cara 9 membuat vector a9 sama seperti a8 dengan setiap nilai diulang 2 kali
    a9 <- rep(1:3,each=2) 
    a9
    [1] 1 1 2 2 3 3
  • karakter berpola

    #cara 10 membuat vector a10
    a10 <- paste("A", 1:10, sep="") 
    a10
     [1] "A1"  "A2"  "A3"  "A4"  "A5"  "A6"  "A7"  "A8"  "A9"  "A10"
    #cara 11 membuat vector a11 seperti cara 10
    a11 <- paste("A", rep(1:10), sep="") 
    a11
     [1] "A1"  "A2"  "A3"  "A4"  "A5"  "A6"  "A7"  "A8"  "A9"  "A10"
    #cara 12 membuat vector a12
    a12 <- paste0("A",1:10) 
    a12
     [1] "A1"  "A2"  "A3"  "A4"  "A5"  "A6"  "A7"  "A8"  "A9"  "A10"
    #cara 13 membuat vector a13
    a13 <- paste("A",1:10,sep='-') 
    a13
     [1] "A-1"  "A-2"  "A-3"  "A-4"  "A-5"  "A-6"  "A-7"  "A-8"  "A-9"  "A-10"
    #cara 14 membuat vector a14
    a8 <- rep(1:3,rep(2,3))
    a14 <- paste0("A",a8) 
    a14
    [1] "A1" "A1" "A2" "A2" "A3" "A3"
  • akses vector

    #mengambil value di index ke 3 pada vector a2
    assign("a2",c("2","4","7","3")) 
    a2[3] 
    [1] "7"
    #mengambil value di index ke 10 s/d 15 pada vector a3
    a3 <- seq(1,10,by=0.5) 
    a3[10:15] 
    [1] 5.5 6.0 6.5 7.0 7.5 8.0
    #mengambil value di index ke 4, 7 dan 9 vector a10
    a10 <- paste("A", 1:10, sep="") 
    a10[c(4,7,9)]
    [1] "A4" "A7" "A9"
    #membuang value di index ke 1 dan 2 pada vector a13
    a13 <- paste("A",1:10,sep='-') 
    a13[-c(1:2)] 
    [1] "A-3"  "A-4"  "A-5"  "A-6"  "A-7"  "A-8"  "A-9"  "A-10"
    #jumlah index pada vector a4
    a4 <- seq(1,10,length.out=12) 
    length(a4) 
    [1] 12

2.2.2 Matrix

#membuat matriks baris 1 s/d 12
a14 <- 1:12 
a14
 [1]  1  2  3  4  5  6  7  8  9 10 11 12
#membentuk matrix 3 x 4 pake data a14
b1 <- matrix(a14,3,4) 
b1
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12
#sama seperti b1 bedanya diisi baris pertama
b2 <- matrix(a14,3,4,byrow=TRUE) 
b2
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]    5    6    7    8
[3,]    9   10   11   12
#membentuk matrix 4 x 4 dengan value 1 s/d 10 dimulai dari kolom 1 - kolom ke 4
b3 <- matrix(1:10,4,4) 
b3
     [,1] [,2] [,3] [,4]
[1,]    1    5    9    3
[2,]    2    6   10    4
[3,]    3    7    1    5
[4,]    4    8    2    6
#membentuk matrix 4 x 5 dengan value 1 s/d 10 dimulai dari kolom 1 - kolom ke 5
b4 <- matrix(1:10,4,5) 
b4
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    5    9    3    7
[2,]    2    6   10    4    8
[3,]    3    7    1    5    9
[4,]    4    8    2    6   10
#assign matrix baris a14 ke b5
b5 <- a14 
b5
 [1]  1  2  3  4  5  6  7  8  9 10 11 12
#merubah objek vector ke matrix
dim(b5)<-c(6,2) 
dim(b5)
[1] 6 2
#membentuk matrix 2 x 2, jika tidak dimasukan nilai satunya
b6 <- matrix(1:4,2) 
b6
     [,1] [,2]
[1,]    1    3
[2,]    2    4
#membentuk matrix 2 x 2, jika tidak dimasukan nilai satunya
b7 <- matrix(6:9,2) 
b7
     [,1] [,2]
[1,]    6    8
[2,]    7    9
#gabung baris
b8 <- rbind(b6,b7) 
b8
     [,1] [,2]
[1,]    1    3
[2,]    2    4
[3,]    6    8
[4,]    7    9
#gabung kolom
b9 <- cbind(b7,b6) 
b9
     [,1] [,2] [,3] [,4]
[1,]    6    8    1    3
[2,]    7    9    2    4
#dimensi row and col pada matrix b8
dim(b8) 
[1] 4 2
#dimensi row and col pada matrix b9
dim(b9) 
[1] 2 4
#dimensi row and col pada matrix a14
dim(a14) 
NULL
#total data pada matrix b3
length(b3)  
[1] 16
#akses matrix
b2
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]    5    6    7    8
[3,]    9   10   11   12
#ambil value di indeks row = 2, col = 3
b2[2,3] 
[1] 7
#ambil value di indeks row = 2, col = 2,3,4
b2[2,2:4]
[1] 6 7 8
#ambil value di indeks row = 1,2, col = semua kolom
b2[1:2,] 
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]    5    6    7    8
#ambil value di indeks row = 1 dan 3, col = exclude kolom 2
b2[c(1,3),-2] 
     [,1] [,2] [,3]
[1,]    1    3    4
[2,]    9   11   12
#ambil value di row=1, col = 4
b2[10] 
[1] 4

2.2.3 Array

#akses array
c1 <- array(a14,dim=c(2,2,3))
c1
, , 1

     [,1] [,2]
[1,]    1    3
[2,]    2    4

, , 2

     [,1] [,2]
[1,]    5    7
[2,]    6    8

, , 3

     [,1] [,2]
[1,]    9   11
[2,]   10   12
c2 <- array(a14,dim=c(2,1,2,3))
c2
, , 1, 1

     [,1]
[1,]    1
[2,]    2

, , 2, 1

     [,1]
[1,]    3
[2,]    4

, , 1, 2

     [,1]
[1,]    5
[2,]    6

, , 2, 2

     [,1]
[1,]    7
[2,]    8

, , 1, 3

     [,1]
[1,]    9
[2,]   10

, , 2, 3

     [,1]
[1,]   11
[2,]   12
c3 <- array(a14,dim=c(1,2,4,2))
c3
, , 1, 1

     [,1] [,2]
[1,]    1    2

, , 2, 1

     [,1] [,2]
[1,]    3    4

, , 3, 1

     [,1] [,2]
[1,]    5    6

, , 4, 1

     [,1] [,2]
[1,]    7    8

, , 1, 2

     [,1] [,2]
[1,]    9   10

, , 2, 2

     [,1] [,2]
[1,]   11   12

, , 3, 2

     [,1] [,2]
[1,]    1    2

, , 4, 2

     [,1] [,2]
[1,]    3    4
c4 <- array(a14,dim=c(3,4))
c4
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12
#lembar 1 dari c2
c2[,,1,] 
     [,1] [,2] [,3]
[1,]    1    5    9
[2,]    2    6   10
#buku ke 2 dari c2
c2[,,,2] 
     [,1] [,2]
[1,]    5    7
[2,]    6    8
#lembar ke 1 buku ke 3 dari c2
c2[,,1,3] 
[1]  9 10

2.2.4 Factor

#membuat vector
a15 <- c("A","B","AB","O") 
a15
[1] "A"  "B"  "AB" "O" 
#transform tipe data ke skala pengukuran nominal
d1 <- factor(a15) 
d1
[1] A  B  AB O 
Levels: A AB B O
#mengubah posisi level
d2 <- factor(a15,levels=c("O","A","B","AB")) 
d2
[1] A  B  AB O 
Levels: O A B AB
#melihat unique kategorik
levels(d2) 
[1] "O"  "A"  "B"  "AB"
#membuat vector
a16 <- c("SD","SMP","SMA") 
a16
[1] "SD"  "SMP" "SMA"
#transform tipe data ke skala pengukuran ordinal
d3 <- ordered(a16) 
d3
[1] SD  SMP SMA
Levels: SD < SMA < SMP
d4 <- ordered(a16, levels=a16)
d4
[1] SD  SMP SMA
Levels: SD < SMP < SMA
d5 <- factor(a16, levels=a16, ordered=TRUE)
d5 
[1] SD  SMP SMA
Levels: SD < SMP < SMA
levels(d4)
[1] "SD"  "SMP" "SMA"
#akses factor
#mengambil indeks ke 2 pada vector d1
d1[2] 
[1] B
Levels: A AB B O
#mengambil indeks ke 2 dan 3 pada vector d4
d4[2:3] 
[1] SMP SMA
Levels: SD < SMP < SMA

2.2.5 List

#bisa dikasih tanda ; kalo untuk menampilkan, tidak perlu dibuat per line
a1; b2; c1; d2 
[1] 2 4 7 3
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]    5    6    7    8
[3,]    9   10   11   12
, , 1

     [,1] [,2]
[1,]    1    3
[2,]    2    4

, , 2

     [,1] [,2]
[1,]    5    7
[2,]    6    8

, , 3

     [,1] [,2]
[1,]    9   11
[2,]   10   12
[1] A  B  AB O 
Levels: O A B AB
#membuat sekumpulan assignment menjadi list
e1 <- list(a1,b2,c1,d2) 
e1
[[1]]
[1] 2 4 7 3

[[2]]
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]    5    6    7    8
[3,]    9   10   11   12

[[3]]
, , 1

     [,1] [,2]
[1,]    1    3
[2,]    2    4

, , 2

     [,1] [,2]
[1,]    5    7
[2,]    6    8

, , 3

     [,1] [,2]
[1,]    9   11
[2,]   10   12


[[4]]
[1] A  B  AB O 
Levels: O A B AB
e2 <- list(vect=a1,mat=b2,array=c1,fac=d2)
e2
$vect
[1] 2 4 7 3

$mat
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]    5    6    7    8
[3,]    9   10   11   12

$array
, , 1

     [,1] [,2]
[1,]    1    3
[2,]    2    4

, , 2

     [,1] [,2]
[1,]    5    7
[2,]    6    8

, , 3

     [,1] [,2]
[1,]    9   11
[2,]   10   12


$fac
[1] A  B  AB O 
Levels: O A B AB
#akses list
e1[[1]]
[1] 2 4 7 3
e2$fac
[1] A  B  AB O 
Levels: O A B AB
e2[2]
$mat
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]    5    6    7    8
[3,]    9   10   11   12
e1[c(2,4)]
[[1]]
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]    5    6    7    8
[3,]    9   10   11   12

[[2]]
[1] A  B  AB O 
Levels: O A B AB
dim(e2)
NULL
length(e2)
[1] 4
names(e2)
[1] "vect"  "mat"   "array" "fac"  

2.2.6 DataFrame

a17 <- 11:15
a17
[1] 11 12 13 14 15
d5 <- factor(LETTERS[6:10])
d5
[1] F G H I J
Levels: F G H I J
f1 <- data.frame(d5,a17)
f1
  d5 a17
1  F  11
2  G  12
3  H  13
4  I  14
5  J  15
#akses data frame
f1[1,2]
[1] 11
f1[3,]
  d5 a17
3  H  13
f1$d5
[1] F G H I J
Levels: F G H I J
f1[,"a17"]
[1] 11 12 13 14 15
colnames(f1)
[1] "d5"  "a17"
str(f1)
'data.frame':   5 obs. of  2 variables:
 $ d5 : Factor w/ 5 levels "F","G","H","I",..: 1 2 3 4 5
 $ a17: int  11 12 13 14 15
summary(f1)
 d5         a17    
 F:1   Min.   :11  
 G:1   1st Qu.:12  
 H:1   Median :13  
 I:1   Mean   :13  
 J:1   3rd Qu.:14  
       Max.   :15  

2.2.7 Latihan

  • Latihan 1

    c("la","ye")[rep(c(1,2,2,1),times=4)]
     [1] "la" "ye" "ye" "la" "la" "ye" "ye" "la" "la" "ye" "ye" "la" "la" "ye" "ye"
    [16] "la"
    c("la","ye")[rep(rep(1:2,each=3),2)]
     [1] "la" "la" "la" "ye" "ye" "ye" "la" "la" "la" "ye" "ye" "ye"
  • Latihan 2

    paste(c("x","y"),1:10,sep='')
     [1] "x1"  "y2"  "x3"  "y4"  "x5"  "y6"  "x7"  "y8"  "x9"  "y10"
    seq(1,28,by=3)
     [1]  1  4  7 10 13 16 19 22 25 28
  • Latihan 3

    Seorang peneliti merancang sebuah perancangan percobaan RAKL dengan 4 perlakuan dan 3 kelompok (anggaplah respon percobaan berupa baris bilangan). Bantulah peneliti tersebut untuk membuat raw data seperti output sebagai berikut!

    perl <- paste("P",rep(c(1:4),each=3),sep="")
    kel <- rep(c(1:3),times=4)
    resp <- seq(1,23,by=2)
    data1 <- data.frame(perl,kel,resp)
    data1 
       perl kel resp
    1    P1   1    1
    2    P1   2    3
    3    P1   3    5
    4    P2   1    7
    5    P2   2    9
    6    P2   3   11
    7    P3   1   13
    8    P3   2   15
    9    P3   3   17
    10   P4   1   19
    11   P4   2   21
    12   P4   3   23

2.2.8 operator-operator lain

  • is.vector() -> apakah objec bentuk vector?

  • is.matrix() -> apakah objec bentuk matrix?

  • is.array() -> apakah objec bentuk array?

  • is.factor() -> apakah objec tipe factor?

  • is.list() -> apakah objec list?

  • is.data.frame() -> apakah objec dataframe?

  • as.vector() -> operator membuat vector

  • as.matrix() -> operator membuat matrix

  • as.array() -> operator membentuk tipe array

  • as.factor() -> operator mengubah tipe data menjadi factor

  • as.list() -> operator membentuk list

  • as.data.frame() -> operator membentuk dataframe

BAB 3

3.1 Manejemen DataFrame

3.1.1 Membuat dan peubah dataframe

  • Membuat DataFrame

    id_mhw = paste("id", rep(1:10), sep="")
    id_mhw
     [1] "id1"  "id2"  "id3"  "id4"  "id5"  "id6"  "id7"  "id8"  "id9"  "id10"
    stat = c(86,87,90,91,92,78,98,77,89,80)
    stat
     [1] 86 87 90 91 92 78 98 77 89 80
    math = c(79,92,87,87,90,79,92,80,85,82)
    math
     [1] 79 92 87 87 90 79 92 80 85 82
    data = data.frame(id_mhw, stat, math)
    data
       id_mhw stat math
    1     id1   86   79
    2     id2   87   92
    3     id3   90   87
    4     id4   91   87
    5     id5   92   90
    6     id6   78   79
    7     id7   98   92
    8     id8   77   80
    9     id9   89   85
    10   id10   80   82
  • membuat variabel/kolom baru-Dilakukan seperti membuat vektor (dengan indeks atau operasi seleksi

    #import library
    library(dplyr)
    #dataframe
    id_mhw = paste("id", rep(1:10), sep="")
    stat = c(86,87,90,91,92,78,98,77,89,80)
    math = c(79,92,87,87,90,79,92,80,85,82)
    data = data.frame(id_mhw, stat, math)
    #cara 1
    data$paralel = factor(rep(1:2,5))
    data
       id_mhw stat math paralel
    1     id1   86   79       1
    2     id2   87   92       2
    3     id3   90   87       1
    4     id4   91   87       2
    5     id5   92   90       1
    6     id6   78   79       2
    7     id7   98   92       1
    8     id8   77   80       2
    9     id9   89   85       1
    10   id10   80   82       2
    #cara 2
    cara_2 = data
    cara_2[,'pararel1'] <- factor(rep(1:2,5))
    cara_2
       id_mhw stat math paralel pararel1
    1     id1   86   79       1        1
    2     id2   87   92       2        2
    3     id3   90   87       1        1
    4     id4   91   87       2        2
    5     id5   92   90       1        1
    6     id6   78   79       2        2
    7     id7   98   92       1        1
    8     id8   77   80       2        2
    9     id9   89   85       1        1
    10   id10   80   82       2        2
    #cara 3
    cara_3 <- data %>% mutate('pararel3' = factor(rep(1:2,5)))
    cara_3
       id_mhw stat math paralel pararel3
    1     id1   86   79       1        1
    2     id2   87   92       2        2
    3     id3   90   87       1        1
    4     id4   91   87       2        2
    5     id5   92   90       1        1
    6     id6   78   79       2        2
    7     id7   98   92       1        1
    8     id8   77   80       2        2
    9     id9   89   85       1        1
    10   id10   80   82       2        2
  • menambah baris baru

    #dataframe
    id_mhw = paste("id", rep(1:10), sep="")
    stat = c(86,87,90,91,92,78,98,77,89,80)
    math = c(79,92,87,87,90,79,92,80,85,82)
    data = data.frame(id_mhw, stat, math)
    data$paralel = factor(rep(1:2,5))
    #cara 1
    data[nrow(data) + 1,] = c("id11","78", "89", "2") 
    data[nrow(data) + 1,] = c("id12","80", "89", "2")
    data
       id_mhw stat math paralel
    1     id1   86   79       1
    2     id2   87   92       2
    3     id3   90   87       1
    4     id4   91   87       2
    5     id5   92   90       1
    6     id6   78   79       2
    7     id7   98   92       1
    8     id8   77   80       2
    9     id9   89   85       1
    10   id10   80   82       2
    11   id11   78   89       2
    12   id12   80   89       2

3.1.2 Subsetting Data

  • Subsetting Data (fungsi operator ==, !=, >, >=, <, <=, %in%, duplicated, is,na())

    dilakukan untuk akses sebagian data membuat ide logic untuk diterapkan dalam vektor logic yang diinginkan.

    #dataframe
    id_mhw = paste("id", rep(1:10), sep="")
    stat = c(86,87,90,91,92,78,98,77,89,80)
    math = c(79,92,87,87,90,79,92,80,85,82)
    data = data.frame(id_mhw, stat, math)
    data$paralel = factor(rep(1:2,5))
    #cara 1
    data[nrow(data) + 1,] = c("id11","78", "89", "2") 
    data[nrow(data) + 1,] = c("id12","80", "89", "2")
    
    #op ==
    datas1 <- data$paralel==1
    data[datas1,]
      id_mhw stat math paralel
    1    id1   86   79       1
    3    id3   90   87       1
    5    id5   92   90       1
    7    id7   98   92       1
    9    id9   89   85       1
    #op  == |
    datas2 <- data$stat == 90 | data$math == 90
    data[datas2,]
      id_mhw stat math paralel
    3    id3   90   87       1
    5    id5   92   90       1
    #op !=
    datas3 <- data$paralel != 2
    data[datas3,]
      id_mhw stat math paralel
    1    id1   86   79       1
    3    id3   90   87       1
    5    id5   92   90       1
    7    id7   98   92       1
    9    id9   89   85       1
    #op >=, <=
    datas4 <- data$stat >=80 & data$math <=90  
    data[datas4,]
       id_mhw stat math paralel
    1     id1   86   79       1
    3     id3   90   87       1
    4     id4   91   87       2
    5     id5   92   90       1
    9     id9   89   85       1
    10   id10   80   82       2
    12   id12   80   89       2
    #op %in%
    datas5 <- data$stat %in% c(80,85,90,95)   
    data[datas5,]
       id_mhw stat math paralel
    3     id3   90   87       1
    10   id10   80   82       2
    12   id12   80   89       2
    #op duplicated
    datas6 <- duplicated(data$id_mhw)   
    data[datas6,]
    [1] id_mhw  stat    math    paralel
    <0 rows> (or 0-length row.names)
    #op is,na()
    #cek data kosong di paralel
    indeks7 = is.na(data$paralel) 
    datas7 = data[indeks7,]
    datas7
    [1] id_mhw  stat    math    paralel
    <0 rows> (or 0-length row.names)
    #op is,null()
    #cek dataframe ada yang null atau tidak
    is.null(data) 
    [1] FALSE
    # contoh
    data[nrow(data) + 1,] = c("id12","80", "89", "")
    data <- data[-13,]
    data
       id_mhw stat math paralel
    1     id1   86   79       1
    2     id2   87   92       2
    3     id3   90   87       1
    4     id4   91   87       2
    5     id5   92   90       1
    6     id6   78   79       2
    7     id7   98   92       1
    8     id8   77   80       2
    9     id9   89   85       1
    10   id10   80   82       2
    11   id11   78   89       2
    12   id12   80   89       2

3.1.3 Mengurutkan Data (order(), sort(), which(), rev(), unique())

  • dilakukan untuk mengurutkan data berdasarkan beberapa peubah tertentu dilakukan dengan membuat vektork logika untuk melakukan pengurutan data

    #dataframe
    id_mhw = paste("id", rep(1:10), sep="")
    stat = c(86,87,90,91,92,78,98,77,89,80)
    math = c(79,92,87,87,90,79,92,80,85,82)
    data = data.frame(id_mhw, stat, math)
    data$paralel = factor(rep(1:2,5))
    #cara 1
    data[nrow(data) + 1,] = c("id11","78", "89", "2") 
    data[nrow(data) + 1,] = c("id12","80", "89", "2")
    #temp table
    datas2 <- data
    datas2$segment <- c('high','low','low','high','med','med','low','high','med','low','high','low')
    datas2$gender <- c('M','M','M','F','F','M','F','F','F','M','F','F')
    datas2
       id_mhw stat math paralel segment gender
    1     id1   86   79       1    high      M
    2     id2   87   92       2     low      M
    3     id3   90   87       1     low      M
    4     id4   91   87       2    high      F
    5     id5   92   90       1     med      F
    6     id6   78   79       2     med      M
    7     id7   98   92       1     low      F
    8     id8   77   80       2    high      F
    9     id9   89   85       1     med      F
    10   id10   80   82       2     low      M
    11   id11   78   89       2    high      F
    12   id12   80   89       2     low      F
    # order()
    # Simple
    datas2[order(datas2$stat),]
       id_mhw stat math paralel segment gender
    8     id8   77   80       2    high      F
    6     id6   78   79       2     med      M
    11   id11   78   89       2    high      F
    10   id10   80   82       2     low      M
    12   id12   80   89       2     low      F
    1     id1   86   79       1    high      M
    2     id2   87   92       2     low      M
    9     id9   89   85       1     med      F
    3     id3   90   87       1     low      M
    4     id4   91   87       2    high      F
    5     id5   92   90       1     med      F
    7     id7   98   92       1     low      F
    # rumit
    datas2[
      order(datas2$segment, 
            (datas2$gender=='M')*as.numeric(datas2$stat),
            (datas2$gender=='F')*as.numeric(datas2$math)
            ),
      ] %>% select(segment, gender, stat, math)
       segment gender stat math
    8     high      F   77   80
    4     high      F   91   87
    11    high      F   78   89
    1     high      M   86   79
    12     low      F   80   89
    7      low      F   98   92
    10     low      M   80   82
    2      low      M   87   92
    3      low      M   90   87
    9      med      F   89   85
    5      med      F   92   90
    6      med      M   78   79
    #rank
    datas2$rank = rank(datas2$stat)
    datas2[order(datas2$rank),]
       id_mhw stat math paralel segment gender rank
    8     id8   77   80       2    high      F  1.0
    6     id6   78   79       2     med      M  2.5
    11   id11   78   89       2    high      F  2.5
    10   id10   80   82       2     low      M  4.5
    12   id12   80   89       2     low      F  4.5
    1     id1   86   79       1    high      M  6.0
    2     id2   87   92       2     low      M  7.0
    9     id9   89   85       1     med      F  8.0
    3     id3   90   87       1     low      M  9.0
    4     id4   91   87       2    high      F 10.0
     [ reached 'max' / getOption("max.print") -- omitted 2 rows ]
    #sort - mengurutkan
    # untuk vektor berlaku
    x3 <- c(2,4,3,2,7,8) 
    sort(x3)
    [1] 2 2 3 4 7 8
    # untuk data frame tidak berlaku
    datas2[sort(datas2$stat),] 
         id_mhw stat math paralel segment gender rank
    NA     <NA> <NA> <NA>    <NA>    <NA>   <NA>   NA
    NA.1   <NA> <NA> <NA>    <NA>    <NA>   <NA>   NA
    NA.2   <NA> <NA> <NA>    <NA>    <NA>   <NA>   NA
    NA.3   <NA> <NA> <NA>    <NA>    <NA>   <NA>   NA
    NA.4   <NA> <NA> <NA>    <NA>    <NA>   <NA>   NA
    NA.5   <NA> <NA> <NA>    <NA>    <NA>   <NA>   NA
    NA.6   <NA> <NA> <NA>    <NA>    <NA>   <NA>   NA
    NA.7   <NA> <NA> <NA>    <NA>    <NA>   <NA>   NA
    NA.8   <NA> <NA> <NA>    <NA>    <NA>   <NA>   NA
    NA.9   <NA> <NA> <NA>    <NA>    <NA>   <NA>   NA
     [ reached 'max' / getOption("max.print") -- omitted 2 rows ]
    #which - mengurutkan indek bernilai true
    datas2[which(datas2$stat==80),]
       id_mhw stat math paralel segment gender rank
    10   id10   80   82       2     low      M  4.5
    12   id12   80   89       2     low      F  4.5
    #rev - mengurutkan kebalikan
    #vector
    datas2$id_mhw 
     [1] "id1"  "id2"  "id3"  "id4"  "id5"  "id6"  "id7"  "id8"  "id9"  "id10"
    [11] "id11" "id12"
    rev(datas2$id_mhw)
     [1] "id12" "id11" "id10" "id9"  "id8"  "id7"  "id6"  "id5"  "id4"  "id3" 
    [11] "id2"  "id1" 
    #mengurutkan data berdasarkan kolom secara terbalik df
    datas2 
       id_mhw stat math paralel segment gender rank
    1     id1   86   79       1    high      M  6.0
    2     id2   87   92       2     low      M  7.0
    3     id3   90   87       1     low      M  9.0
    4     id4   91   87       2    high      F 10.0
    5     id5   92   90       1     med      F 11.0
    6     id6   78   79       2     med      M  2.5
    7     id7   98   92       1     low      F 12.0
    8     id8   77   80       2    high      F  1.0
    9     id9   89   85       1     med      F  8.0
    10   id10   80   82       2     low      M  4.5
     [ reached 'max' / getOption("max.print") -- omitted 2 rows ]
    rev(datas2) 
       rank gender segment paralel math stat id_mhw
    1   6.0      M    high       1   79   86    id1
    2   7.0      M     low       2   92   87    id2
    3   9.0      M     low       1   87   90    id3
    4  10.0      F    high       2   87   91    id4
    5  11.0      F     med       1   90   92    id5
    6   2.5      M     med       2   79   78    id6
    7  12.0      F     low       1   92   98    id7
    8   1.0      F    high       2   80   77    id8
    9   8.0      F     med       1   85   89    id9
    10  4.5      M     low       2   82   80   id10
     [ reached 'max' / getOption("max.print") -- omitted 2 rows ]
    #mengurutkan data berdasarkan row
    datas2
       id_mhw stat math paralel segment gender rank
    1     id1   86   79       1    high      M  6.0
    2     id2   87   92       2     low      M  7.0
    3     id3   90   87       1     low      M  9.0
    4     id4   91   87       2    high      F 10.0
    5     id5   92   90       1     med      F 11.0
    6     id6   78   79       2     med      M  2.5
    7     id7   98   92       1     low      F 12.0
    8     id8   77   80       2    high      F  1.0
    9     id9   89   85       1     med      F  8.0
    10   id10   80   82       2     low      M  4.5
     [ reached 'max' / getOption("max.print") -- omitted 2 rows ]
    datas2[rev(rownames(datas2)),] 
       id_mhw stat math paralel segment gender rank
    12   id12   80   89       2     low      F  4.5
    11   id11   78   89       2    high      F  2.5
    10   id10   80   82       2     low      M  4.5
    9     id9   89   85       1     med      F  8.0
    8     id8   77   80       2    high      F  1.0
    7     id7   98   92       1     low      F 12.0
    6     id6   78   79       2     med      M  2.5
    5     id5   92   90       1     med      F 11.0
    4     id4   91   87       2    high      F 10.0
    3     id3   90   87       1     low      M  9.0
     [ reached 'max' / getOption("max.print") -- omitted 2 rows ]
    #unique cari lagi
    x <- unique(data$id_mhw)
    x
     [1] "id1"  "id2"  "id3"  "id4"  "id5"  "id6"  "id7"  "id8"  "id9"  "id10"
    [11] "id11" "id12"

3.1.4 Recording Data

  • digunakan untuk membuat nilai baru dari nilai peubah yang sudah ada dapat dilakukan secara logical, fungi ifelse(), recode(), dan fungsi lainnya.

    #dataframe
    id_mhw = paste("id", rep(1:10), sep="")
    stat = c(86,87,90,91,92,78,98,77,89,80)
    math = c(79,92,87,87,90,79,92,80,85,82)
    data = data.frame(id_mhw, stat, math)
    data$paralel = factor(rep(1:2,5))
    data$segment <- c('high','low','low','high','med','med','low','high','med','low')
    data$gender <- c('M','M','M','F','F','M','F','F','F','M')
    data
       id_mhw stat math paralel segment gender
    1     id1   86   79       1    high      M
    2     id2   87   92       2     low      M
    3     id3   90   87       1     low      M
    4     id4   91   87       2    high      F
    5     id5   92   90       1     med      F
    6     id6   78   79       2     med      M
    7     id7   98   92       1     low      F
    8     id8   77   80       2    high      F
    9     id9   89   85       1     med      F
    10   id10   80   82       2     low      M
    #logical
    data$code1 = 1*(data$stat>=85) + 0*(data$stat<85)
    data
       id_mhw stat math paralel segment gender code1
    1     id1   86   79       1    high      M     1
    2     id2   87   92       2     low      M     1
    3     id3   90   87       1     low      M     1
    4     id4   91   87       2    high      F     1
    5     id5   92   90       1     med      F     1
    6     id6   78   79       2     med      M     0
    7     id7   98   92       1     low      F     1
    8     id8   77   80       2    high      F     0
    9     id9   89   85       1     med      F     1
    10   id10   80   82       2     low      M     0
    #if
    new_segment <- matrix(nrow=length(data$segment),ncol=1)
    for (i in 1:nrow(data)){
      x <- data[i,'segment']
      if (x=='high'){new_segment[i] = 'h'}
      else if (x=='med'){new_segment[i]='m'}else{new_segment[i]='l'}
    }
    data$if_segment <- new_segment
    data
      id_mhw stat math paralel segment gender code1 if_segment
    1    id1   86   79       1    high      M     1          h
    2    id2   87   92       2     low      M     1          l
    3    id3   90   87       1     low      M     1          l
    4    id4   91   87       2    high      F     1          h
    5    id5   92   90       1     med      F     1          m
    6    id6   78   79       2     med      M     0          m
    7    id7   98   92       1     low      F     1          l
    8    id8   77   80       2    high      F     0          h
    9    id9   89   85       1     med      F     1          m
     [ reached 'max' / getOption("max.print") -- omitted 1 rows ]
    #switch
    new_gender <- matrix(nrow=length(data$gender),ncol=1)
    for (i in 1:nrow(data)){
      x <- data[i,'gender']
      new_gender[i] <- switch(x,"M" = "Male","F" = "Female")
    }
    data$switch_gender <- new_gender
    data
      id_mhw stat math paralel segment gender code1 if_segment switch_gender
    1    id1   86   79       1    high      M     1          h          Male
    2    id2   87   92       2     low      M     1          l          Male
    3    id3   90   87       1     low      M     1          l          Male
    4    id4   91   87       2    high      F     1          h        Female
    5    id5   92   90       1     med      F     1          m        Female
    6    id6   78   79       2     med      M     0          m          Male
    7    id7   98   92       1     low      F     1          l        Female
    8    id8   77   80       2    high      F     0          h        Female
     [ reached 'max' / getOption("max.print") -- omitted 2 rows ]
    #ifelse
    data$code2 = ifelse(data$stat>85,"GOOD","NOT BAD")
    data
      id_mhw stat math paralel segment gender code1 if_segment switch_gender
    1    id1   86   79       1    high      M     1          h          Male
    2    id2   87   92       2     low      M     1          l          Male
    3    id3   90   87       1     low      M     1          l          Male
    4    id4   91   87       2    high      F     1          h        Female
    5    id5   92   90       1     med      F     1          m        Female
    6    id6   78   79       2     med      M     0          m          Male
    7    id7   98   92       1     low      F     1          l        Female
        code2
    1    GOOD
    2    GOOD
    3    GOOD
    4    GOOD
    5    GOOD
    6 NOT BAD
    7    GOOD
     [ reached 'max' / getOption("max.print") -- omitted 3 rows ]
    #recode
    library(tidyverse)
    #recode_factor
    data$code4 <- recode_factor(data$code2, 'GOOD' = 1, 'NOT BAD' =  0)
    #case_when()
    data$case_when <- case_when((data$stat > 78) ~ "high",TRUE ~ "unknown") 
    data
      id_mhw stat math paralel segment gender code1 if_segment switch_gender
    1    id1   86   79       1    high      M     1          h          Male
    2    id2   87   92       2     low      M     1          l          Male
    3    id3   90   87       1     low      M     1          l          Male
    4    id4   91   87       2    high      F     1          h        Female
    5    id5   92   90       1     med      F     1          m        Female
    6    id6   78   79       2     med      M     0          m          Male
        code2 code4 case_when
    1    GOOD     1      high
    2    GOOD     1      high
    3    GOOD     1      high
    4    GOOD     1      high
    5    GOOD     1      high
    6 NOT BAD     0   unknown
     [ reached 'max' / getOption("max.print") -- omitted 4 rows ]

3.1.5 Merging Data

  • bisa dilakukan denga rbind atau cbind lebih mudah dengan fungsi merge

    #data sampel
    datas1 = c(1,2,3)
    datas1
    [1] 1 2 3
    datas2 = c(4,5,6)
    datas2
    [1] 4 5 6
    #digunakan untuk menggabungkan kolomOutput
    cbind(datas1,datas2) 
         datas1 datas2
    [1,]      1      4
    [2,]      2      5
    [3,]      3      6
    #digunakan untuk menggabungkan barisOutput
    rbind(datas1,datas2) 
           [,1] [,2] [,3]
    datas1    1    2    3
    datas2    4    5    6
    #tabel product
    id_cust = paste("ID", rep(120:129), sep="")
    product = paste("barang",11:20,sep=" ")
    tabel_product = data.frame(id_cust, product)
    tabel_product
       id_cust   product
    1    ID120 barang 11
    2    ID121 barang 12
    3    ID122 barang 13
    4    ID123 barang 14
    5    ID124 barang 15
    6    ID125 barang 16
    7    ID126 barang 17
    8    ID127 barang 18
    9    ID128 barang 19
    10   ID129 barang 20
    #tabel daerah
    id_cust = c("ID122", "ID126", "ID128", "ID129", "ID130", "ID133", "ID135")
    asal = paste("Kota",1:7,sep="-")
    tabel_daerah = data.frame(id_cust, asal)
    tabel_daerah
      id_cust   asal
    1   ID122 Kota-1
    2   ID126 Kota-2
    3   ID128 Kota-3
    4   ID129 Kota-4
    5   ID130 Kota-5
    6   ID133 Kota-6
    7   ID135 Kota-7
    #LEFT JOIN
    datas8 = merge(x=tabel_product,y=tabel_daerah,by="id_cust",all.x=TRUE)
    datas8
       id_cust   product   asal
    1    ID120 barang 11   <NA>
    2    ID121 barang 12   <NA>
    3    ID122 barang 13 Kota-1
    4    ID123 barang 14   <NA>
    5    ID124 barang 15   <NA>
    6    ID125 barang 16   <NA>
    7    ID126 barang 17 Kota-2
    8    ID127 barang 18   <NA>
    9    ID128 barang 19 Kota-3
    10   ID129 barang 20 Kota-4
    #INNER JOIN
    datas9 = merge(x=tabel_product,y=tabel_daerah,by="id_cust", all=FALSE)
    datas9
      id_cust   product   asal
    1   ID122 barang 13 Kota-1
    2   ID126 barang 17 Kota-2
    3   ID128 barang 19 Kota-3
    4   ID129 barang 20 Kota-4
    #RIGHT JOIN
    datas11 = merge(x=tabel_product,y=tabel_daerah,by="id_cust",all.y=TRUE)
    datas11
      id_cust   product   asal
    1   ID122 barang 13 Kota-1
    2   ID126 barang 17 Kota-2
    3   ID128 barang 19 Kota-3
    4   ID129 barang 20 Kota-4
    5   ID130      <NA> Kota-5
    6   ID133      <NA> Kota-6
    7   ID135      <NA> Kota-7
    #OUTER JOIN
    datas12 = merge(x=tabel_product,y=tabel_daerah,by="id_cust",all=TRUE)
    datas12
       id_cust   product   asal
    1    ID120 barang 11   <NA>
    2    ID121 barang 12   <NA>
    3    ID122 barang 13 Kota-1
    4    ID123 barang 14   <NA>
    5    ID124 barang 15   <NA>
    6    ID125 barang 16   <NA>
    7    ID126 barang 17 Kota-2
    8    ID127 barang 18   <NA>
    9    ID128 barang 19 Kota-3
    10   ID129 barang 20 Kota-4
    11   ID130      <NA> Kota-5
    12   ID133      <NA> Kota-6
    13   ID135      <NA> Kota-7

3.1.7 Re-shaping

  • Membentuk data baru dengan cara:1) long to wide, 2) wide to long Menggunakan fungsi reshape()

    #create dataframe
    kota = c("Manado", "Jakarta", "Bandung")
    bekerja = c("23400","56700","34500")
    tidak_kerja = c("10000","30000","12000")
    tabel = data.frame(kota, bekerja, tidak_kerja)
    colnames(tabel)<- c("Nama Kota","Bekerja","Tidak Bekerja")
    tabel
      Nama Kota Bekerja Tidak Bekerja
    1    Manado   23400         10000
    2   Jakarta   56700         30000
    3   Bandung   34500         12000
    #wide to long -> data frame diurutkan by varying (harus gunakan varying dan v.names) 
    widetolong<- reshape(tabel,idvar="Nama Kota",
                         varying = c("Bekerja","Tidak Bekerja"),
                         v.name=c("value"),
                         times=c("Bekerja","Tidak Bekerja"),
                         new.row.names = 1:100,
                         direction="long")
    widetolong
      Nama Kota          time value
    1    Manado       Bekerja 23400
    2   Jakarta       Bekerja 56700
    3   Bandung       Bekerja 34500
    4    Manado Tidak Bekerja 10000
    5   Jakarta Tidak Bekerja 30000
    6   Bandung Tidak Bekerja 12000
    # long to wide -> harus ada nama kolom buat idvar dan  v.names
    longtowide <- reshape(widetolong, idvar="Nama Kota",
                          v.names = "value",
                          timevar = "time",
                          direction="wide")
    longtowide
      Nama Kota value.Bekerja value.Tidak Bekerja
    1    Manado         23400               10000
    2   Jakarta         56700               30000
    3   Bandung         34500               12000

3.1.8 latihan

  • Latihan 1

    #create dataframe
    perl <- paste('P',rep(1:4,3),sep = '')
    kel <- rep(1:3,4)
    resp <- seq(1,23,by=2)
    data1 <- data.frame(perl,kel,resp)
    #Pada data1, buatlah peubah 'baru1' yang berisi nilai dari 12 sampai 1 secara berurutan
    data1$baru1 <- 12:1
    data1
       perl kel resp baru1
    1    P1   1    1    12
    2    P2   2    3    11
    3    P3   3    5    10
    4    P4   1    7     9
    5    P1   2    9     8
    6    P2   3   11     7
    7    P3   1   13     6
    8    P4   2   15     5
    9    P1   3   17     4
    10   P2   1   19     3
    11   P3   2   21     2
    12   P4   3   23     1
  • Latihan 2

    #create dataframe
    perl <- paste('P',rep(1:4,3),sep = '')
    kel <- rep(1:3,4)
    resp <- seq(1,23,by=2)
    data1 <- data.frame(perl,kel,resp)
    #dari data1 tersebut ambillah yang termasuk kelompok 1
    data2 <- data1[data1$kel == 1,]
    data2
       perl kel resp
    1    P1   1    1
    4    P4   1    7
    7    P3   1   13
    10   P2   1   19
  • Latihan 3

    #create dataframe
    perl <- paste('P',rep(1:4,3),sep = '')
    kel <- rep(1:3,4)
    resp <- seq(1,23,by=2)
    data1 <- data.frame(perl,kel,resp)
    #dari data1 tersebut ambillah yang termasuk kelompok 1 atau perlakuan p2
    data3 <- data1[data1$kel == 1 | data1$perl=='P2',]
    data3
       perl kel resp
    1    P1   1    1
    2    P2   2    3
    4    P4   1    7
    6    P2   3   11
    7    P3   1   13
    10   P2   1   19
  • Latihan 4

    #create dataframe
    perl <- paste('P',rep(1:4,3),sep = '')
    kel <- rep(1:3,4)
    resp <- seq(1,23,by=2)
    data1 <- data.frame(perl,kel,resp)
    #dari data1 tersebut ambillah amatan yang respon bilangan prima
    data4 <- data1[data1$resp %in% c(2,3,5,7,11,13,17,19,23),]
    data4
       perl kel resp
    2    P2   2    3
    3    P3   3    5
    4    P4   1    7
    6    P2   3   11
    7    P3   1   13
    9    P1   3   17
    10   P2   1   19
    12   P4   3   23
  • Latihan 5

    #create dataframe
    perl <- paste('P',rep(1:4,3),sep = '')
    kel <- rep(1:3,4)
    resp <- seq(1,23,by=2)
    data1 <- data.frame(perl,kel,resp)
    #urutkan data1 tersebut berdasarkan kelompok secara ascending
    data5 <- data1[order(data1$kel,decreasing = F),]
    data5
       perl kel resp
    1    P1   1    1
    4    P4   1    7
    7    P3   1   13
    10   P2   1   19
    2    P2   2    3
    5    P1   2    9
    8    P4   2   15
    11   P3   2   21
    3    P3   3    5
    6    P2   3   11
    9    P1   3   17
    12   P4   3   23
  • Latihan 6

    #create dataframe
    perl <- paste('P',rep(1:4,3),sep = '')
    kel <- rep(1:3,4)
    resp <- seq(1,23,by=2)
    data1 <- data.frame(perl,kel,resp)
    #urutkan data1 tersebut berdasarkan kelompok secara descending
    data6 <- data1[order(data1$kel,decreasing = T),]
    data6
       perl kel resp
    3    P3   3    5
    6    P2   3   11
    9    P1   3   17
    12   P4   3   23
    2    P2   2    3
    5    P1   2    9
    8    P4   2   15
    11   P3   2   21
    1    P1   1    1
    4    P4   1    7
    7    P3   1   13
    10   P2   1   19
  • Latihan 7

    #create dataframe
    perl <- paste('P',rep(1:4,3),sep = '')
    kel <- rep(1:3,4)
    resp <- seq(1,23,by=2)
    data1 <- data.frame(perl,kel,resp)
    #urutkan data1 tersebut berdasarkan kelompok secara ascending dan respon secara descending
    data7 <- data1[order(data1$resp,decreasing = T),]
    data7
       perl kel resp
    12   P4   3   23
    11   P3   2   21
    10   P2   1   19
    9    P1   3   17
    8    P4   2   15
    7    P3   1   13
    6    P2   3   11
    5    P1   2    9
    4    P4   1    7
    3    P3   3    5
    2    P2   2    3
    1    P1   1    1
    data8 <- data7[order(data7$kel,decreasing = F),] #order by kelompok
    data8
       perl kel resp
    10   P2   1   19
    7    P3   1   13
    4    P4   1    7
    1    P1   1    1
    11   P3   2   21
    8    P4   2   15
    5    P1   2    9
    2    P2   2    3
    12   P4   3   23
    9    P1   3   17
    6    P2   3   11
    3    P3   3    5
  • Latihan 8

    #create dataframe
    perl <- paste('P',rep(1:4,3),sep = '')
    kel <- rep(1:3,4)
    resp <- seq(1,23,by=2)
    data1 <- data.frame(perl,kel,resp)
    #lakukanlah recoding pada data8 untuk variable respon dengan kondisi jika respon<15, maka
    #code=1,selainnya code = 0
    library(car)
    data8$code3 <- recode(data8$resp,'1:14=1; else=0')
    data8
       perl kel resp code3
    10   P2   1   19     0
    7    P3   1   13     1
    4    P4   1    7     1
    1    P1   1    1     1
    11   P3   2   21     0
    8    P4   2   15     0
    5    P1   2    9     1
    2    P2   2    3     1
    12   P4   3   23     0
    9    P1   3   17     0
    6    P2   3   11     1
    3    P3   3    5     1
  • Latihan 9

    #create dataframe
    perl <- paste('P',rep(1:4,3),sep = '')
    kel <- rep(1:3,4)
    resp <- seq(1,23,by=2)
    data1 <- data.frame(perl,kel,resp)
    #gunakanlah data1 dengan tabel1 berdasarkan peubah pertamanya
    tabel1 <- data.frame(tr=c("p4","p2","p5"),k1=c(50,100,200))
    data9 <- merge(data1,tabel1, by.x = 1, by.y = 1, all = F)
    data9
    [1] perl kel  resp k1  
    <0 rows> (or 0-length row.names)
    data10 <- merge(data1,tabel1, by.x = 'perl', by.y = 'tr', all = T)
    data10
       perl kel resp  k1
    1    P1   1    1  NA
    2    P1   2    9  NA
    3    P1   3   17  NA
    4    p2  NA   NA 100
    5    P2   2    3  NA
    6    P2   3   11  NA
    7    P2   1   19  NA
    8    P3   3    5  NA
    9    P3   1   13  NA
    10   P3   2   21  NA
    11   p4  NA   NA  50
    12   P4   1    7  NA
    13   P4   2   15  NA
    14   P4   3   23  NA
    15   p5  NA   NA 200
  • Latihan 10

    #create dataframe
    perl <- paste('P',rep(1:4,3),sep = '')
    kel <- rep(1:3,4)
    resp <- seq(1,23,by=2)
    data1 <- data.frame(perl,kel,resp)
    #ubahlah data1 menjadi data dengan setiap barisnya merupakan masing-masing perlakuan
    #long to wide
    data11 <- reshape(data1[,-4],idvar = 'perl',timevar = 'kel', direction = "wide")
    data11
      perl resp.1 resp.2 resp.3
    1   P1      1      9     17
    2   P2     19      3     11
    3   P3     13     21      5
    4   P4      7     15     23
    #long to wide
    data12 <- reshape(data11,idvar = 'perl',timevar = 'kel', direction = "long")
    data12
         perl kel resp.1
    P1.1   P1   1      1
    P2.1   P2   1     19
    P3.1   P3   1     13
    P4.1   P4   1      7
    P1.2   P1   2      9
    P2.2   P2   2      3
    P3.2   P3   2     21
    P4.2   P4   2     15
    P1.3   P1   3     17
    P2.3   P2   3     11
    P3.3   P3   3      5
    P4.3   P4   3     23

BAB 4

# plot(x,y,"p") for points
# plot(x,y,"l") for lines
# plot(x,y,"b") for both
# plot(x,y,"c") for the lines part alone of "b"
# plot(x,y,"o") for overplotted
# plot(x,y,"h") for histogram like
# plot(x,y,"s") for stair steps
# plot(x,y,"S") for other steps
# plot(x,y,"n") for no plotting
# numeric 1-8 (recycle) -> palette()
# fungsi "colorname" (colors()) --> type colors() to show list of colours provided
# rainbow(7) --> output heksacode, rgb(red=0.30,green=0.50,blue=0.250)
# package "colorspace", "colourpicker", "RColorBrewer"
library("colorspace") 
library("colourpicker")
library("RColorBrewer")
#dasar plot
x <- 1:40
y <- rnorm(40,5,1)
plot(x,y,type="p")

plot(x,y,type="o")

plot(x,y,type="n")

#pch ada 25, col=colours ada 8
plot(x,y,type="p", xlab="sumbu x", ylab="sumbu y", main="bilangan acak normal",col=2,pch=16)

#pch ada 25, col ada 8 by default,cex=ukuran font data point
plot(x,y,type="p",
     xlab="sumbu x",ylab="sumbu y",
     main="bilangan acak normal",
     col=rainbow(40),pch=16,
     cex=2, xlim=c(0,50),ylim=c(2.5,7.5))  
#menambah amatan pada plot yg sudah dibuat
x1 <- 41:50
y1 <- rnorm(10,5,1)
points(x1,y1,cex=2)
#menambahkan garis
x2 <- rep(40.5,20)
y2 <- seq(min(c(y,y1)),max(c(y,y1)),length=20)
#lwd = lebar by default 1, lty = line type = 2 = garis putus-putus
lines(x2,y2,col=4,lwd=2,lty=2)  
#h = horizontal, v=vertikal, a dan b garis regresi dengan persamaan a+bx
abline(h=mean(y),col="red",lwd=2.5)
abline(a=2, b=1/10, col="maroon3",lwd=2, lty=2)
abline(v=mean(x),col="red",lwd=2.5)
#menambahkan tanda panah
arrows(x0=30,y0=3.5,x1=40,y1=mean(y)-0.1,lwd=2)
#menambahkan tulisan
text(x=29,y=3.3,labels="Titik potong", cex=0.7)
text(x=3,y=7.3,labels="data awal", cex=0.7)
text(x=46,y=7.3,labels="data baru", cex=0.7)

#latihan 1
#could you explain what are
plot(sin,-pi, 2*pi)

plot(table(rpois(100,5)),type='h',col='red',lwd=1,main="rpois(100,lambda=5)")

#latihan 2
#create some programs to make the graph below
a1 <- 1:25
a2 <- rnorm(25,4,2)
plot(a1,a2,pch='w',main='b')

plot(a1,a2,pch=c('w','a'),main='b')

#latihan 3
plot(a1,a1,type="n",main='w')
text(a1,a2,labels = paste("w",1:25,sep=''),col = rainbow(25),cex = 2.8)

#latihan 4
#create some programas to make the graph below, using 100 obs of X~x^2(df=4)
x <- rchisq(100,df=4)
hist(x,freq = F,ylim = c(0,0.2))
curve(dchisq(x,df=4),col=2,lty=2,lwd=2,add=T)

curve(dchisq(x,df=4),col=2,lty=2,lwd=2,add=F)

#latihan 5
par(mfrow=c(2,2))
plot(1:40,y,type="p",xlab='sumbu x',ylab='sumbu y', main='bilangan acak normal', col=2,pch=16)
plot(sin,-pi,2*pi)
plot(table(rpois(100,5)),type='h',col='red',lwd=1,main='rpois(100,lambda=5)')
plot(a1,a2,type='n', main='w')
text(a1,a2,labels=paste('w',1:25,sep=''),col=rainbow(25),cex=0.8)

par(mfcol=c(2,2))
plot(1:40,y,type="p",xlab='sumbu x',ylab='sumbu y', main='bilangan acak normal', col=2,pch=16)
plot(sin,-pi,2*pi)
plot(table(rpois(100,5)),type='h',col='red',lwd=1,main='rpois(100,lambda=5)')
plot(a1,a2,type='n', main='w')
text(a1,a2,labels=paste('w',1:25,sep=''),col=rainbow(25),cex=0.8)

windows()
plot(rnorm(100,5,1))

yb <- rnorm(100,5,1)
split.screen(c(2,2))
[1] 1 2 3 4
screen(1)
plot(1:100,yb,type='l',lwd=2,col='blue')
title('line plot bilangan acak normal',cex.main=0.7)
screen(2)
boxplot(yb)
title('boxplot bilangan acak normal',cex.main=0.7)
screen(3)
hist(yb,freq = F,main=NULL,ylim = c(0,0.5))
title('histogram bilangan acak normal',cex.main=0.7)
screen(4)
plot(1:100,yb,pch=16,col=rainbow(100))
title('scatterplot bilangan acak normal',cex.main=0.7)

BAB 5

Pembangkitan bilangan acak merupakan alat yang diperlukan dalam komputasi statistik, umumnya untuk simulasi. bilangan acak yang dibangkitkan merupakan pseudorandom (acak semu). Bilangan acak yang dibangkitkan memenuhi sebaran statistik tertentu (pdf/pmf,cdf). Semua Metode pembangkitan bilangan acak tergantung dari pembangkitan bilangan acak uniform. Pembangkit bilangan menggunakan seed yang umumnya mengambil waktu di komputer.

5.1 Fungsi-Fungsi Peluang Suatu Sebaran

  • Fungsi pembangkit bilangan acak dari suatu sebaran,

    set.seed(1)
    #normal mean=5 sd=1
    rnorm(n=10, mean = 5, sd = 1)
     [1] 4.373546 5.183643 4.164371 6.595281 5.329508 4.179532 5.487429 5.738325
     [9] 5.575781 4.694612
    hist(rnorm(n=30))

    #uniform
    runif(n=30)
     [1] 0.43465948 0.71251468 0.39999437 0.32535215 0.75708715 0.20269226
     [7] 0.71112122 0.12169192 0.24548851 0.14330438 0.23962942 0.05893438
    [13] 0.64228826 0.87626921 0.77891468 0.79730883 0.45527445 0.41008408
    [19] 0.81087024 0.60493329 0.65472393 0.35319727 0.27026015 0.99268406
    [25] 0.63349326 0.21320814 0.12937235 0.47811803 0.92407447 0.59876097
    hist(runif(n=30))

    #binom
    rnbinom(n = 100, size = 100, prob = 0.6)/100
     [1] 0.63 0.55 0.66 0.55 0.81 0.69 0.77 0.69 0.67 0.80 0.82 0.59 0.79 0.54 0.72
    [16] 0.78 0.82 0.62 0.52 0.66 0.70 0.76 0.55 0.70 0.66 0.72 0.57 0.57 0.60 0.51
    [31] 0.57 0.81 0.69 0.55 0.70 0.67 0.67 0.78 0.77 0.51 0.77 0.70 0.70 0.72 0.83
    [46] 0.53 0.56 0.61 0.63 0.84 0.52 0.51 0.66 0.92 0.76 0.68 0.73 0.57 0.66 0.47
    [61] 0.43 0.66 0.57 0.61 0.90 0.59 0.60 0.70 0.75 0.51 0.61 0.53 0.68 0.65 0.70
     [ reached getOption("max.print") -- omitted 25 entries ]
    hist(rnbinom(n = 100, size = 100, prob = 0.6))

  • Fungsi density/mass (pdf/pmf) dimulai huruf d diikutin dengan nama sebarannya. contoh dnorm, dunif.

    set.seed(1)
    #normal mean=5 sd=1
    dnorm(x = 2, mean = 5, sd = 1)
    [1] 0.004431848
    #uniform
    dunif(x = 2, min = 0, max = 5)
    [1] 0.2
    #binomial
    dbinom(x = 50, size = 100, prob = 0.6)
    [1] 0.01033751
    # acak
    plot(seq(-4,4, length=1000),dnorm(seq(-4,4, length=1000)))

  • Fungsi peluang sebaran kumulatif (cdf) dimulai huruf p diikutin dengan nama sebaranya. contoh pnorm, punif.

    set.seed(1)
    #normal mean=5 sd=1
    pnorm(q = 0.05, mean = 5, sd = 1, lower.tail = T)
    [1] 3.710674e-07
    #uniform
    punif(q = 2, min = 0, max = 5, lower.tail = T)
    [1] 0.4
    #binomial
    pbinom(q = 50, size = 100, prob = 0.6, lower.tail = T)
    [1] 0.0270992
  • Fungsi quantile/invers cdf dimulai huruf q diikuti dengan nama sebarannya. contoh qnorm, qunif.

    set.seed(1)
    #normal mean=5 sd=1
    qnorm(p = 0.05, mean = 5, sd = 1, lower.tail = T)
    [1] 3.355146
    qnorm(p = 0.05, mean = 5, sd = 1, lower.tail = F)
    [1] 6.644854
    #uniform
    qunif(p = 2, min = 0, max = 5, lower.tail = T)
    [1] NaN
    #binomial
    qbinom(p = 50, size = 100, prob = 0.6, lower.tail = T)
    [1] NaN

5.2 Teknik Pembangkitan Bilangan Acak

  • inverse-transform method

    Membangkitkan vektor r~uniform(0,1), lalu gunakan fungsi cdf dari sebaran yang diinginkan untuk mendapatkan x~invers(cdf r).

    algorithma step :

    1. tentukan fsk F(x) dari sebaran yang diinginkan

    2. tentukan Finvers(x)

    3. bangkitkan unifrom(0,1)

    4. transformasi X = Finvers(u)

    keunggulan : bisa digunakan untuk berbagai sebaran (termasuk sebaran diskrit)

    kesulitan utama : memperoleh kebalikan dari funsi sebaran kumulatif

    #ingin membangkitan normal(10,1)
    r <- runif(n=100, min = 0, max = 1)
    x <- qnorm(r, mean = 10, sd = 1,lower.tail = T) #invers cdf dari sebaran normal
    hist(x, prob=TRUE)
    sbx <- seq(6,14,0.01)
    lines(sbx, dnorm(sbx,mean=10,sd=1))

    #mebangkitkan X~f(x) = 3x^2; 0<x<1
    #maka dicari cdf dari fungsi tersebut dengan cara integral f(x)  
    #didapat Fx(X) = X^(1/3)
    n <- 1000
    u <- runif(n=n, min = 0, max = 1)
    x <- u^(1/3) #invers cdf dari suatu sebaran/fungsi 3*x^2
    hist(x,prob=TRUE)
    sbx <- seq(0,1,by=0.01)
    lines(sbx,3*sbx^2)

    #memabngkitkan acak dari binom(size=5,p=0.5)
    n <- 1000
    u <- runif(n = n,min = 0,max = 1)
    u
     [1] 0.690391705 0.253767139 0.411038370 0.122891113 0.131966556 0.640118008
     [7] 0.346423432 0.422756605 0.939408880 0.383889231 0.228585131 0.690278686
    [13] 0.009857917 0.686130894 0.791674596 0.507493489 0.308076249 0.737212277
    [19] 0.304715243 0.774708702 0.112113638 0.797743700 0.491001167 0.832918175
    [25] 0.758423155 0.902146561 0.278440013 0.445692850 0.272015736 0.329918326
    [31] 0.863600654 0.109857953 0.402256900 0.406075094 0.436479255 0.177000096
    [37] 0.265730200 0.659550013 0.816055505 0.421184345 0.160064304 0.288610127
    [43] 0.802129008 0.164245682 0.789792735 0.524214970 0.320035003 0.275177088
    [49] 0.801898038 0.104024431 0.838122267 0.079262874 0.717564067 0.864617827
    [55] 0.978558208 0.249126208 0.024860690 0.222978232 0.122025500 0.385239425
    [61] 0.084330474 0.282581900 0.566582459 0.328542302 0.943474683 0.377303514
    [67] 0.953315612 0.273252868 0.687330156 0.136991804 0.810210772 0.762604692
    [73] 0.442404834 0.456675695 0.680455089
     [ reached getOption("max.print") -- omitted 925 entries ]
    x <- qbinom(u,size = 5, prob = 0.5,lower.tail = T) #invers cdf binom
    table(x)
    x
      0   1   2   3   4   5 
     35 190 296 291 157  31 
    barplot(table(x))

  • Acceptance-rejection method

    1. mencari peubah acak y sebagai target sebaran dengan fungsi peluang g yang memenuhi f(t)/g(t)<=c. untuk semua t: f(t)>0

    2. untuk setiap satu bilangan acak : bangkitkan y dari sebaran peubah acak y, lalu bangkitkan u dari sebaran Uniform(0,1). Jika c.g(y).u<f(y), terima y sebagai x; selainya tolak y dan ulangi langkah 2(a)

    #memabngkitkan acak X~beta(2,2)
    #fungsi pdf dari beta(2,2) adalah f(x) = 6x(1-x);0<x<1
    n <- 1000 #nilai yang ingin dibangkitkan
    x <- numeric(n)
    iterasi <- 0
    accepted <- 0
    while (accepted < n) {
      iterasi <- iterasi+1
      #1)bangkitin y dari sebaran u(0,1) noted bisa dari sebaran apapun
      maks <- 1
      mins <- 0
      y <- runif(n = 1, min = mins, max = maks) 
      g <- function(t=0){1/(maks-mins)} #dari pdf sebaran uniform
      #2)cari max c dengan f(t)/g(t)
      f <- function(t){6*t*(1-t)} #dari pdf sebaran beta yang ingin dicari
      fs <- function(t){f(t)/g(t)}
      d <- optimize(fs, interval = c(mins,maks), tol = 0.0001, maximum = TRUE) #min maxks berasal dari interval pdf beta
      c <- ceiling(x = d$objective)
      #curve(fs, from = mins, to = maks)
      #abline(v=d$maximum, lty=3, lwd=1, col="red")
      #3) bangkitan u dari sebaran uniform(0,1)
      u <- runif(n = 1, min = mins, max = maks) 
      #4)area penerimaan jika c.g(t).u<f(t)
      #2.(1).u<6*y*(1-y) -> u<3*y*(1-y)
      if (c*g(y)*u<3*y*(1-y)){
        accepted <- accepted+1 
        x[accepted] <- y
      }
    }
    hist(x,prob=T)
    sbx <- seq (0 ,1 ,.01)
    lines (sbx,dbeta(sbx,2,2))

    cat('iterasi = ',iterasi,'accepted = ', accepted)
    iterasi =  4146 accepted =  1000
    #memabngkitkan acak X~beta(2,2)
    #fungsi pdf dari beta(2,2) adalah f(x) = 6x(1-x);0<x<1
    n <- 1000 #banyaknya bangkitan
    j <- k <- 0
    y <- numeric(n)
    while(k < n){
      u <- runif (1)
      j <- j +1
      x <- runif (1)
      if(3*x*(1 - x ) > u){
        k <- k +1 
      #terima x
        y[k] <- x
      }
    }
    hist (y , prob = T )
    sbx <- seq (0 ,1 ,.01)
    lines ( sbx , dbeta ( sbx ,2 ,2) )

    j
    [1] 1954
    #fungsi
    fs <- function(x){6*x*(1-x)}
    curve(fs, from = 0, to = 1)

  • Direct Transformation

    ##contoh lain binomial didekatkan dari bernouli
    m = 10
    n = 30
    bino <- matrix(nrow = m,ncol = 1)
    for (i in 1:n) {
      bino[i] <- sum(ifelse(rbernoulli(n = m,p = 0.5)==TRUE,1,0))
    }
    hist(bino)

    hist(rbinom(n = n, size = m, prob = 0.5))

    mean(bino)
    [1] 4.766667
    mean(rbinom(n = n, size = m, prob = 0.5))
    [1] 4.733333

5.3 Multivariate Normal Distribution

Sebuah vektor acak X = (X1,X2,…,Xd) merupakan sebaran multivariate normal dengan dimensi-d dinotasikan Nd(mu,sigma) dan setiap X1,…,Xd mengikuti normal distribution. Pembangkitan bilangan acak Nd(mu,sigma) dilakukan melalui 2 tahap sebagai berikut:

  1. Membangkitkan Z = (Z1,Z2,…,Zd)

  2. Transformasi Z sesuai dengan vektor rataan mud dan peragam (Covariance) sigma yang diinginkan

    1. CZ + mu~Nd(mu,sigma)

    2. sigma = C*C^T

    3. Faktorisasi sigma dapat menggunakan dekomposisi spektral: eigenvector (R:eigen), choleski (R:chol) atau svd (R:svd)

    rmvn.eigen <- function (n,mu,Sigma){
      d <- length(mu)
      ev <- eigen(Sigma,symmetric = TRUE)
      lambda <- ev$values
      V <- ev$vectors
      R <- V %*% diag(sqrt(lambda)) %*% t(V)
      Z <- matrix(rnorm(n*d),nrow = n,ncol = d)
      X <- Z %*% R + matrix(mu,n,d,byrow = T)
      X
    }
    mu <- c(0,0)
    Sigma <- matrix(c(1,.9,.9,1),nrow =2,ncol=2)
    X <- rmvn.eigen(1000,mu,Sigma)
    cov(X)
              [,1]      [,2]
    [1,] 1.0020004 0.8793415
    [2,] 0.8793415 0.9596326
    cor(X)
              [,1]      [,2]
    [1,] 1.0000000 0.8967495
    [2,] 0.8967495 1.0000000
    #atau
    library(MASS)
    X1 <- mvrnorm(1000,mu,Sigma)
    X2 <- mvrnorm (1000 , mu , Sigma , empirical = TRUE )
    var(X1)
              [,1]      [,2]
    [1,] 0.9287173 0.8177229
    [2,] 0.8177229 0.9039913
    var(X2)
         [,1] [,2]
    [1,]  1.0  0.9
    [2,]  0.9  1.0

5.4 Pembangkitan Bilangan Acak untuk Model

#misalkan akan dibangkitkan model regresi linier sederhana:
# y = b0 +b1x + e
# dalam hal ini e~N(0,1), b0=1, b1=1
b0 <- 1
b1 <- 1
b0hat <- NULL
b1hat <- NULL
for (i in 1:100){
  eps <- rnorm(10)
  X <- runif(10,5,10)
  Y <- b0+b1*X+eps
  obj <- lm(Y~X)
  b0hat <- c(b0hat,obj$coefficients[1])
  b1hat <- c(b1hat,obj$coefficients[2])
}
hasil <- matrix(c(mean(b0hat),sd(b0hat),mean(b1hat),
                  sd(b1hat)),nrow =2,ncol =2)
rownames(hasil) <- c("mean","sd")
colnames(hasil) <- c("b0","b1")
hasil
            b0        b1
mean 0.9387868 1.0061704
sd   1.6910867 0.2285921
#misalkan akan dibangkitkan model regresi linier sederhana:
# y = b0 +b1 x1 + b2 x2 + e
# dalam hal ini e~N(0,1), b0=1,b1=1,b2=1
library(MASS)
b0 <- 1
b1 <- 1
b2 <- 1
b0hat <- NULL
b1hat <- NULL
b2hat <- NULL
sigma <- matrix(c(1,0.9,0.9,1),2)
mu <- c(1,1)
for (i in 1:100){
  eps <- rnorm(n = 10)
  X <- mvrnorm(n = 10, mu = mu, Sigma = sigma)
  Y <- b0+b1*X[,1]+b2*X[,2]+eps
  obj <- lm(Y~X)
  b0hat <- c(b0hat,obj$coefficients[1])
  b1hat <- c(b1hat,obj$coefficients[2])
  b2hat <- c(b2hat,obj$coefficients[3])
}
hasil <- matrix(c(mean(b0hat), sd(b0hat),
                  mean(b1hat), sd(b1hat),
                  mean(b2hat), sd(b2hat)),
                nrow = 3, ncol = 2, byrow = T)
row.names(hasil) <- c('b0','b1','b2')
colnames(hasil) <- c('mean','sd')
hasil
        mean        sd
b0 1.0177919 0.5956583
b1 1.2003251 0.9488732
b2 0.8094725 0.9824059

5.5 Praktikum

  • Latihan 1

    set.seed(5)
    #membangkitkan bilangan acak eksponensial(lambda)
    eks <- function(n,lambda){
      U <- runif(n = n, min = 0, max = 1)
      x <- -log(1-U)/lambda #hasil invers dari cdf eksponensial
      return(x)
    }
    yy1 <- eks(n = 1000, lambda = 3) #inverse cdf transform method
    yy2 <- rexp(1000,rate=3) #fungsi bawaan R
    par(mfrow=c(1,2))
    hist(yy1,main='Exp dari inverse Transform')
    hist(yy2,main='Exp dari rexp')

  • Latihan 2

    set.seed(5)
    #bagkitkan bilangan acak yang memiliki fkp fy(y) = 3*y^2; 0<y<1 menggunakan
    # acceptance-rejection method!
    ar <- function(n,x0,x1,f) {
      xx <- seq(x0,x1,length=10000)
      c <- max(f(xx))
      terima <- 0
      iterasi <- 0
      hasil <- numeric(n)
      while(terima<n){
          x <- runif(1,x0,x1)
          y1<- runif(1,0,c)
          y2<- f(x)
          if(y1<=y2){
            terima <- terima+1
            hasil[terima]<-x
          }
          iterasi <- iterasi+1
      }
      list(hasil=hasil,iterasi=iterasi)
    }
    f <- function(x) {3*x^2} #fungsi yg ingin dibangkitkan random
    x0 <- 0
    x1 <- 1
    yyy <- ar(100,x0,x1,f)
    yyy
    $hasil
     [1] 0.9168758 0.9565001 0.8902071 0.4447306 0.2751492 0.8160761 0.8268702
     [8] 0.9289427 0.7601425 0.9330338 0.6239665 0.9866358 0.8882176 0.9304595
    [15] 0.9394365 0.4702749 0.9709980 0.7130181 0.9283003 0.8466150 0.7743666
    [22] 0.4744489 0.5922262 0.2815070 0.3814395 0.8348439 0.5750217 0.6909046
    [29] 0.8353511 0.4903933 0.9915121 0.3008908 0.7112479 0.8161342 0.8388997
    [36] 0.8718775 0.7504145 0.5825742 0.8997541 0.9476389 0.9953407 0.7878348
    [43] 0.6785758 0.5209068 0.8791718 0.8552571 0.6141239 0.8930837 0.9112591
    [50] 0.7682125 0.6756898 0.6133571 0.7417476 0.9853800 0.8279483 0.7739056
    [57] 0.7905514 0.8921900 0.8842232 0.3287677 0.5738227 0.9876561 0.5372197
    [64] 0.9481612 0.2548256 0.4527589 0.6300685 0.9420581 0.8202417 0.9854322
    [71] 0.7705284 0.7477860 0.6429059 0.7662060 0.4547465
     [ reached getOption("max.print") -- omitted 25 entries ]
    
    $iterasi
    [1] 275
    par(mfrow=c(1,1))
    hist(yyy$hasil,main="f(x)=3*x^2", prob=T)
    x <- seq(0, 1, 0.01)
    lines(x, f(x), lwd=2, col=4)

  • Latihan 3

    #direct transformation
    set.seed(5)
    x <- runif(n = 1000,min = 3, max = 5)
    # maka rumus y menjadi y = (b-a)X+a -> y = (5-3)X+3
    y <- 2*x+3
    y
     [1]  9.800858 11.740874 12.667503 10.137598  9.418601 11.804230 11.111840
     [8] 12.231741 12.826001  9.441812 10.093140 10.962053 10.273616 11.236691
    [15] 10.050373  9.807501 10.550103 12.551479 11.219690 12.368718 12.560828
    [22] 11.882804  9.845361  9.902869  9.559935 10.919655 10.749647 12.863857
    [29]  9.567656 12.819916 10.778922  9.237450 10.100597  9.124593  9.057929
    [36] 10.948676 11.380606 11.391412 10.590722 10.587322 12.264304  9.940795
    [43] 12.307481 11.133904 12.715771 11.199179 12.040570  9.274039 12.174437
    [50] 11.531214 10.538308 11.265091 12.687962 12.903510 12.732135 10.524651
    [57] 10.022256 10.029935  9.787546  9.545604 11.495866  9.694981 12.465738
    [64] 12.957343 12.946543 12.568052 12.552870  9.629374 12.721838 12.307721
    [71] 12.317374 11.869361  9.625438 12.341846  9.090898
     [ reached getOption("max.print") -- omitted 925 entries ]
  • Latihan 4

    set.seed(123)
    X1 <- runif(n = 25,min = 10,max = 25)
    X2 <- runif(n = 25,min = 90,max = 200)
    Y <- 10 + 2.3*X1 + 0.7*X2 + rnorm(25,0,9)
    model1 <- lm(Y~X1)
    summary(model1)
    
    Call:
    lm(formula = Y ~ X1)
    
    Residuals:
        Min      1Q  Median      3Q     Max 
    -29.991 -17.738  -2.632  17.896  33.171 
    
    Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
    (Intercept)  131.846     19.741   6.679 8.18e-07 ***
    X1             1.049      1.015   1.033    0.312    
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    
    Residual standard error: 22.42 on 23 degrees of freedom
    Multiple R-squared:  0.04433,   Adjusted R-squared:  0.002775 
    F-statistic: 1.067 on 1 and 23 DF,  p-value: 0.3124
    model2 <- lm(Y~X2)
    summary(model2)
    
    Call:
    lm(formula = Y ~ X2)
    
    Residuals:
        Min      1Q  Median      3Q     Max 
    -31.804  -4.850  -1.606  10.011  20.569 
    
    Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
    (Intercept) 70.83913   13.86879   5.108 3.57e-05 ***
    X2           0.58213    0.09767   5.960 4.46e-06 ***
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    
    Residual standard error: 14.38 on 23 degrees of freedom
    Multiple R-squared:  0.607, Adjusted R-squared:  0.5899 
    F-statistic: 35.52 on 1 and 23 DF,  p-value: 4.464e-06
    model3 <- lm(Y~X1+X2)
    summary(model3)
    
    Call:
    lm(formula = Y ~ X1 + X2)
    
    Residuals:
         Min       1Q   Median       3Q      Max 
    -14.8291  -4.5994  -0.4576   5.0602  20.5307 
    
    Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
    (Intercept) -0.62881   13.40229  -0.047    0.963    
    X1           2.72951    0.40701   6.706 9.67e-07 ***
    X2           0.72459    0.06105  11.869 4.91e-11 ***
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    
    Residual standard error: 8.427 on 22 degrees of freedom
    Multiple R-squared:  0.8709,    Adjusted R-squared:  0.8592 
    F-statistic: 74.21 on 2 and 22 DF,  p-value: 1.66e-10
    model4 <- lm(Y~X1:X2)
    summary(model4)
    
    Call:
    lm(formula = Y ~ X1:X2)
    
    Residuals:
        Min      1Q  Median      3Q     Max 
    -20.929  -7.009  -1.430   2.856  37.374 
    
    Coefficients:
                 Estimate Std. Error t value Pr(>|t|)    
    (Intercept) 80.645221  10.481428   7.694 8.32e-08 ***
    X1:X2        0.027491   0.003929   6.997 3.94e-07 ***
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    
    Residual standard error: 12.97 on 23 degrees of freedom
    Multiple R-squared:  0.6804,    Adjusted R-squared:  0.6665 
    F-statistic: 48.96 on 1 and 23 DF,  p-value: 3.942e-07
    model5 <- lm(Y~X1*X2)
    summary(model5)
    
    Call:
    lm(formula = Y ~ X1 * X2)
    
    Residuals:
         Min       1Q   Median       3Q      Max 
    -14.4425  -4.5808  -0.6702   4.6431  20.2409 
    
    Coefficients:
                 Estimate Std. Error t value Pr(>|t|)  
    (Intercept) 11.625896  37.941991   0.306   0.7623  
    X1           2.063573   1.967526   1.049   0.3062  
    X2           0.635870   0.263687   2.411   0.0251 *
    X1:X2        0.004905   0.014165   0.346   0.7326  
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    
    Residual standard error: 8.6 on 21 degrees of freedom
    Multiple R-squared:  0.8716,    Adjusted R-squared:  0.8533 
    F-statistic: 47.53 on 3 and 21 DF,  p-value: 1.548e-09
    R2 <- matrix(c(summary(model1)$r.squared,
    summary(model1)$adj.r.squared,
    summary(model2)$r.squared,
    summary(model2)$adj.r.squared,
    summary(model3)$r.squared,
    summary(model3)$adj.r.squared,
    summary(model4)$r.squared,
    summary(model4)$adj.r.squared,
    summary(model5)$r.squared,
    summary(model5)$adj.r.squared), 5, byrow=T)
    colnames(R2)<-c("R2","R2.adj"); R2*100
                R2     R2.adj
    [1,]  4.432592  0.2774876
    [2,] 60.699195 58.9904640
    [3,] 87.090357 85.9167529
    [4,] 68.036265 66.6465370
    [5,] 87.163648 85.3298839
    coef(model3)
    (Intercept)          X1          X2 
     -0.6288095   2.7295126   0.7245911 
    confint(model3)
                      2.5 %     97.5 %
    (Intercept) -28.4234482 27.1658292
    X1            1.8854322  3.5735929
    X2            0.5979779  0.8512044
    cbind(coef(model3), confint(model3))
                                 2.5 %     97.5 %
    (Intercept) -0.6288095 -28.4234482 27.1658292
    X1           2.7295126   1.8854322  3.5735929
    X2           0.7245911   0.5979779  0.8512044
    anova(model3)
    Analysis of Variance Table
    
    Response: Y
              Df  Sum Sq Mean Sq  F value    Pr(>F)    
    X1         1   536.4   536.4   7.5538   0.01173 *  
    X2         1 10002.4 10002.4 140.8614 4.911e-11 ***
    Residuals 22  1562.2    71.0                       
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    par(mfrow=c(2,2)); plot(model3)

BAB 6

6.1.1 Menciptakan Fungsi Sendiri

nama fungsi <- function(argumen) isifungsi. Jika isifungsi memerlukan beberapa baris, maka dibutuhkan {}, sehingga persamaan fungsi akan menjadi nama fungsi <- function(argumen) {isifungsi}. argumen pada fungsi bisa didefinisikan default misal function(x=10){isifungsi}. argumen fungsi dapat berulang/tidak didefinisikan secara pasti(menggunakan “…”) contoh: function(x=10,....). Argumen fungsi dapat menerima nama fungsi r lain untuk dijalankan misalnya apply(x,1,mean) atau apply(x,1,sum).

output luaran dari funsi adalah object, bisa dituliskan objeknya menggunakan return.

Nama argumen tidak perlu dituliskan, kecuali urutan diabaikan contoh : fungsi1(10,20) vs fungsi(arg2=10, arg1=10).

std.dev <- function(x=rnorm(10,5,23)) sqrt(var(x))
std.devs <- function(x){return(sqrt(var(x)))}
x <- rnorm(10,5,23)
std.dev()
[1] 21.53702
std.devs(x)
[1] 19.69824

Untuk menangani kesalahan dalam fungsi disediakan fungsi-fungsi:

  • try: pembungkus untuk menjalankan ekspresi yang mungkin gagal dan memungkinkan kode pengguna untuk menangani pemulihan kesalahan. contoh ; try(log(’a"))

    try(log("a"))
    Error in log("a") : non-numeric argument to mathematical function
  • tryCatch menyediakan mekanisme untuk menangani kondisi yang tidak biasa, termasuk kesalahan dan peringatan. contoh : tryCatch(log(10),finally=print(‘hello’))

    tryCatch(log(-10),finally=print('hello'))
    [1] "hello"
    [1] NaN
  • warning : menghasilkan pesan peringatan yang sesuai dengan argumanenya

  • stop : menghentikan eksekusi ekspresi saat ini

6.1.2 Pemrograman berorientasi objek (PBO)

Pemrograman berorientasi objek atau PBO merupakan sebuah paradigma dalam pembuatan sebuah program. OOP menitikberatkan pada identifikasi objek-objek yang terlibat dalam sebuah program dan bagaimana objek-objek tersebut berinteraksi. Pada PBO, program yang dibangun akan dibagi-bagi menjadi objek-objek. OOP menyediakan class dan object sebagai alat dasar untuk meminimalisir dan mengatur kompleksitas dari program.

Beberapa prinsip dari PBO adalah:
1. Abstraksi: suatu cara melihat suatu objek dalam bentuk yang sederhana. Selalu berkaitan dengan class 2. Enkapsulasi: konsep tentang pengikatan data atau metode yang berbeda yang disatukan atau “dikapsulkan” menjadi satu unit data.
3. Inheritance: konsep PBO dimana kita dapat membentuk class baru yang “mewarisi” atau memiliki bagian-bagian dari class yang sudah ada sebelumnya.
4. Polymorphism: konsep dimana suatu objek yang berbeda-beda dapat diakses melalui interface yang sama.

Kelas Merupakan definisi statik (kerangka dasar) dari objek yang akan diciptakan. Suatu class dibagi menjadi:

  • Property: data atau state yang dimiliki oleh class. Contoh pada class Mobil, memiliki property: warna, model, produsen.
  • Method: behavior (perilaku) sebuah class. Bisa dikatakan sebagai aksi atau tindakan yang bisa dilakukan oleh suatu class. Contoh pada class Mobil, memiliki method: Start, Stop, Change Gear, Turn.

Object adalah komponen yang diciptakan dari class (instance of class). Satu class bisa menghasilkan banyak objek. Setiap objek memiliki karakteristik dan fitur masing masing.

6.1.3 Objek: Class System S3

Suatu class dalam system S3 tidak didefinisikan dengan ketat. Fungsi class digunakan untuk menjadikan sebuah objek menjadi class yang diinginkan. class coords : untuk menyimpan data koordinat titik pada 2 buah vektor X dan y. Metode class terdiri dari metode print, lenght, bbox, dan plot. turunan dari class coords adalah vcoords karena ada tambahan property

Contoh 1: class pts

# objek "pts" dari list vektor x dan y
pts <- list(x = round(rnorm(5),2),
            y = round(rnorm(5),2))
class(pts)
[1] "list"
pts
$x
[1] -0.49 -2.31  1.01 -0.71 -0.69

$y
[1]  1.03 -0.28 -1.22  0.18 -0.14
length(pts)
[1] 2

Menjadikan class pts sebagai class baru yaitu class coords**

class(pts) <- "coords"
class(pts)
[1] "coords"
pts
$x
[1] -0.49 -2.31  1.01 -0.71 -0.69

$y
[1]  1.03 -0.28 -1.22  0.18 -0.14

attr(,"class")
[1] "coords"

Langkah sederhana dalam membuat objek dari suatu class seperti ini sangat tidak dianjurkan karena nilai-nilai instannya mungkin tidak tepat.

Konstruktor merupakan Sebuah fungsi konstruktor dibutuhkan untuk mengecek instan sesuai dengan objek. Misalkan pada kasus class coords:

  • Memeriksa x dan y harus berupa numerik

  • vektor x dan y tidak boleh NA, NaN atau Infinite

  • vektor harus memiliki panjang yang sama, dsb

Fungsi Konstruktor untuk Membuat Class coords

coords <- function(x,y){
  if (!is.numeric(x) || !is.numeric(y) || 
      !all(is.finite(x)) || !all(is.finite(y)))
    stop("Titik koordinat tidak tepat!")
  if(length(x) != length(y))
    stop("Panjang koordinat berbeda")
  pts <- list(x=x, y=y)
  class(pts) = "coords"
  pts
}
# Menyusun class pts dengan `coords`
pts <- coords (x= round ( rnorm (5),2),
               y= round ( rnorm (5),2))

pts
$x
[1]  0.01  0.39 -0.37  0.64 -0.22

$y
[1]  0.33  1.10  0.44 -0.33  1.15

attr(,"class")
[1] "coords"

Aksesor Untuk mengakses data dalam class coords, dapat menggunakan akses objek awalnya (list).

# mengakses x secara langsung
pts$x
[1]  0.01  0.39 -0.37  0.64 -0.22
pts$y
[1]  0.33  1.10  0.44 -0.33  1.15
pts
$x
[1]  0.01  0.39 -0.37  0.64 -0.22

$y
[1]  0.33  1.10  0.44 -0.33  1.15

attr(,"class")
[1] "coords"

Namun secara formal tidak dianjurkan mengakses data secara langsung. Diperlukan suatu fungsi aksesor untuk mengakses data pada class coords

Ilustrasi akses pada class coords dengan menggunakan 2 fungsi

# mendefinisi Fungi Aksesor
xcoords <- function(obj)obj$x
ycoords <- function(obj)obj$y

# mengakses x dan y dengan Fungsi Aksesor
xcoords(pts)
[1]  0.01  0.39 -0.37  0.64 -0.22
ycoords(pts)
[1]  0.33  1.10  0.44 -0.33  1.15

Fungsi Generik * Fungsi generik merupakan suatu method dari suatu class objek dalam R. * Fungsi generik bertindak untuk beralih memilih fungsi tertentu atau metode tertentu yang dijalankan sesuai dengan class-nya.

  • Terdapat beberapa fungsi generik yang sudah ada: print, plot, length, dll.

  • Untuk mendefinisi ulang suatu fungsi generik digunakan syntax: method.class <-function() ekspresibaru

Method Print merupakan cara menampilkan data pada suatu objek Class System S3.

Contoh menampilkan data class coords

print.coords <- function(obj){
  print (paste("(",
               format(xcoords(obj)),
               ",",
               format(ycoords(obj)),
               ")", sep =""),
         quote = FALSE )
}

print.coords(pts)
[1] ( 0.01, 0.33) ( 0.39, 1.10) (-0.37, 0.44) ( 0.64,-0.33) (-0.22, 1.15)
pts
[1] ( 0.01, 0.33) ( 0.39, 1.10) (-0.37, 0.44) ( 0.64,-0.33) (-0.22, 1.15)
class(pts)
[1] "coords"

Method Length digunakan untuk menghitung banyaknya anggota dari objek. Pada ilustrasi classs pts, fungsi length akan menghitung banyaknya anggota list pada coords sebelumnya, sehingga kurang tepat.

length(pts)
[1] 2

Mendefinisikan ulang method length untuk class coords

# mendefinisikan ulang method length
length.coords <- function(obj)length(xcoords(obj))
length.coords(pts)
[1] 5
length(pts)
[1] 5

Membuat Fungsi Generik Baru Untuk membuat suatu method yang dapat diwariskan, maka method tersebut harus dijadikan fungsi generik.

Method bbox Misal akan dibuat method bbox yang merupakan sebuah boundary box.

# menjadikan bbox sebagai fungsi generik
bbox <- function(obj)UseMethod("bbox") 

# mendefinisikan method bbox untuk class coords
bbox.coords <- function(obj){
  matrix(c(range(xcoords(obj)), range(ycoords(obj))),
         nc=2, dimnames = list (c("min", "max"),c("x:", "y:")))
}

# penerapan bbox pada pts
bbox.coords(pts)
       x:    y:
min -0.37 -0.33
max  0.64  1.15
bbox(pts)
       x:    y:
min -0.37 -0.33
max  0.64  1.15

Method Plot Misalkan akan dibuat method plot khusus untuk class coords

# mendefinisikan method plot
plot.coords <- function(obj,bbox=FALSE,...){
  if (bbox){
    plot (xcoords(obj),ycoords(obj),...);
    x <- c(bbox(obj)[1],bbox(obj)[2],bbox(obj)[2],bbox(obj)[1]);
    y <- c(bbox(obj)[3],bbox(obj)[3],bbox(obj)[4],bbox(obj)[4]);
    polygon(x,y)
    } 
  else {
    plot (xcoords(obj),ycoords(obj),...)
  }
}

# membuat plot pts
plot.coords(pts)

plot.coords(pts, bbox=T, pch=16, col="orange", main="Plot (x,y)")

Pewariasan class Sebagai ilustrasi, bila diinginkan sebuah objek yang berisi lokasi (coords) dan terdapat nilai (value) pada lokasi tersebut. Perlu menciptakan class baru vcoords sebagai turunan dari coords.

Fungsi Konstruktor dari class vcoords

vcoords <- function (x,y,v){
  if (!is.numeric (x)|| !is.numeric (y) || !is.numeric (v)|| !all(is.finite(x))|| !all(is.finite(y)))
    stop ("Titik koordinat tidak tepat !")
  if (length (x) != length (y)||
      length (x) != length (v))
    stop ("Panjang koordinat berbeda")
  pts <- list (x=x,y=y,v=v)
  class (pts)= c("vcoords", "coords")
  pts
}
nilai <- function(obj)obj$v

Fungsi xcoords, ycoords dan method bbox dari class coords masih sama sehingga tidak perlu didefinisi ulang.

vpts <- vcoords(x = round(rnorm(5),2),
                y = round(rnorm(5),2),
                v = round(runif(5,0,100)))

vpts
[1] ( 0.99,-0.60) ( 0.55, 2.19) ( 0.24, 1.53) (-0.63,-0.24) ( 1.36,-1.03)
xcoords(vpts)
[1]  0.99  0.55  0.24 -0.63  1.36
ycoords(vpts)
[1] -0.60  2.19  1.53 -0.24 -1.03
bbox(vpts)
       x:    y:
min -0.63 -1.03
max  1.36  2.19

Mendefinisikan ulang method print untuk class vcoords

# Mendifinisikan ulang 
print.vcoords <- function (obj){
  print (paste ("(",
                format (xcoords(obj)),
                ", ",
                format (ycoords(obj)),
                "; ", format (nilai(obj)),
                ")",sep=""),
         quote =FALSE)
}
vpts
[1] ( 0.99, -0.60; 24) ( 0.55,  2.19; 96) ( 0.24,  1.53; 60) (-0.63, -0.24; 52)
[5] ( 1.36, -1.03; 40)

Mendefinisikan ulang method plot untuk class vcoords

# Mendifinisikan ulang
plot.vcoords <- function(obj,txt=FALSE,bbox=FALSE,...){
  if (bbox){
    if (!txt){
      plot (xcoords(obj), ycoords(obj),...);
      } 
    else {
      plot (xcoords(obj), ycoords(obj),type="n",...);
      text (xcoords(obj), ycoords(obj),nilai(obj),...);
      }
    x <- c(bbox(pts)[1], bbox(pts)[2], bbox(pts)[2], bbox(pts)[1]);
    y <- c(bbox(pts)[3], bbox(pts)[3], bbox(pts)[4], bbox(pts)[4]);
    polygon (x,y)
    }
  else {
    if (!txt){
      plot (xcoords(obj), ycoords(obj),...);
      } 
    else {
      plot (xcoords(obj), ycoords(obj),type="n",...);
      text (xcoords(obj), ycoords(obj),nilai(obj) ,...);
    }
  }
}
plot.vcoords(vpts)

plot.vcoords(vpts, txt=T, bbox=T, col="red")

Method Subset Diinginkan untuk memiliki akses terhadap metode subset. Misal diiginkan ekspresi berikut: vpts[ xcoords(vpts) < 0 & ycoords(vpts) < 0 ]. Hal di atas dapat ditangani dengan mendefinisikan metode untuk [

# Mendefinisikan operator [
`[.vcoords` <- function(x,i){
  vcoords(xcoords(x)[i], ycoords(x)[i], nilai(x)[i])
}

# Mengakses anggota class vcoords 1:3
vpts[1:3]
[1] (0.99, -0.60; 24) (0.55,  2.19; 96) (0.24,  1.53; 60)

Pemeriksaan Cuatu Class Objek Untuk mengecek apakah suatu objek merupakan suatu class digunakan fungsi inherits

inherits(pts, "coords")
[1] TRUE
inherits(pts, "vcoords")
[1] FALSE
inherits(vpts, "coords")
[1] TRUE
inherits(vpts, "vcoords")
[1] TRUE

Ringkasan Class System S3 : Class System S3 memberikan fasilitas object-oriented, tetapi terlalu longgar Contoh ekspresi berikut diperbolehkan dalam R, padahal class "lm" merupakan class untuk pemodelan linier

model <- 1:10 
class(model) <- "lm"
class(model)
[1] "lm"

6.1.4 Objek: Class System S4

Class System S4: Mengatasi masalah dalam class System S3 dengan sistem objek lebih formal. Salah satu keuntungannya adalah sistem penurunan dari class/objek. Dalam sistem objek formal, setiap objek didefinisikan secara formal dalam suatu class. Sebuah class terdiri dari slot dengan tipe atau class spesifik. Class dideklarasikan dengan fungsi setClass.

Contoh, mendefinisikan ulang class coords sebelumnya ke class system S4

setClass("coords", representation(x = "numeric",y = "numeric"))

Contoh, membuat objek car

setClass("car", representation(Nama = "character",
                               Panjang = "numeric",
                               Lebar = "numeric",
                               Kecepatan = "numeric"))

car1 <- new("car", Nama = "Toyota", Panjang = 3.5, Lebar = 2, Kecepatan = 180)
car1
An object of class "car"
Slot "Nama":
[1] "Toyota"

Slot "Panjang":
[1] 3.5

Slot "Lebar":
[1] 2

Slot "Kecepatan":
[1] 180

Konstruktor Membuat objek coords

coords <- function(x, y){
  if (length(x) != length(y))
    stop("length x dan y harus bernilai sama")
  if (!is.numeric(x) || !is.numeric(y))
    stop("x dan y harus vector numeric")
  setClass("coords", representation(x = "numeric",y = "numeric"))
  new("coords", x = as.vector(x), y = as.vector(y))
}

pts <- coords(round(rnorm(5), 2),round(rnorm(5), 2))
pts
An object of class "coords"
Slot "x":
[1]  1.18 -0.56 -0.95 -0.67  0.45

Slot "y":
[1]  0.53 -0.23  1.40  1.76  0.49

Membuat object car menggunakan fungsi konstruktor

car <- function(Nama, Panjang, Lebar, Kecepatan){
  if (Panjang < 2 || Lebar < 1.5 || Kecepatan < 80)
    stop("atribut tidak sesuai")
  setClass("car", representation(Nama = "character",
                               Panjang = "numeric",
                               Lebar = "numeric",
                               Kecepatan = "numeric"))
  new("car", Nama = Nama, Panjang = Panjang, Lebar = Lebar, Kecepatan = Kecepatan)
}

car2 <- car("BMW", 3, 2, 300)
class(car2)
[1] "car"
attr(,"package")
[1] ".GlobalEnv"
class(car1)
[1] "car"
attr(,"package")
[1] ".GlobalEnv"

Aksesor Akses terhadap slot menggunakan fungsi slot atau operator @

slot(pts, "x")
[1]  1.18 -0.56 -0.95 -0.67  0.45
slot(pts, "y")
[1]  0.53 -0.23  1.40  1.76  0.49

Tetapi disarankan 2 fungsi seperti sebelumnya:

xcoords <- function(obj) obj@x
ycoords <- function(obj) obj@y
xcoords(pts)
[1]  1.18 -0.56 -0.95 -0.67  0.45
ycoords(pts)
[1]  0.53 -0.23  1.40  1.76  0.49

Akses terhadap slot pada objek car

car1@Nama
[1] "Toyota"
car2@Kecepatan
[1] 300

Akses terhadap slot pada objeck car dengan fungsi aksesor

nama <- function(objek) objek@Nama
kecepatan <-function(objek) objek@Kecepatan

nama(car1)
[1] "Toyota"
kecepatan(car2)
[1] 300

Fungsi generik show setara dengan fungsi generik print pada class System S3. Penciptaan fungsi generik menggunakan fungsi setMethod. Argumen didefinisikan dengan signature.

setMethod(show, signature(object = "coords"),
          function(object)
              print(paste("(", 
                          format(xcoords(object)),
                          ", ",
                          format(ycoords(object)),
                          ")", sep = ""),
                    quote = FALSE))
pts
[1] ( 1.18,  0.53) (-0.56, -0.23) (-0.95,  1.40) (-0.67,  1.76) ( 0.45,  0.49)
setMethod(show, "car",
          function(object) {
            print(cat("Nama : ", nama(object), "\n",
                      "Kecepatan : ", kecepatan(object),
                      sep = "")
                  )
          })
car2
Nama : BMW
Kecepatan : 300NULL

Fungsi Generik Baru Mendefinisikan fungsi baru sebagai fungsi generik menggunakan:

setGeneric("bbox",
           function(obj)
             standardGeneric("bbox"))
[1] "bbox"
setMethod("bbox", signature(obj = "coords"),
          function(obj)
            matrix(c(range(xcoords(obj)),
                     range(ycoords(obj))),
                   nc = 2,
                   dimnames = list(
                     c("min", "max"),
                     c("x:", "y:")
                   )))
bbox(pts)
       x:    y:
min -0.95 -0.23
max  1.18  1.76
setMethod("plot", signature(x="coords"),
          function(x, bbox=FALSE, ...){
            if (bbox) {
              plot(xcoords(x), ycoords(x), ...);
              x.1 <- c(bbox(x)[1],bbox(x)[2],bbox(x)[2],bbox(x)[1]);
              y.1 <- c(bbox(x)[3],bbox(x)[3],bbox(x)[4],bbox(x)[4]);
              polygon(x.1,y.1)
            } else {
              plot(xcoords(x),ycoords(x), ...)
            }
          })
plot(pts)

plot(pts, bbox = T, pch = 19, col =" red", xlab = "x", ylab = "y")

Pewarisan Class Terdapat class baru yang diturunkan dari coords dengan menambahkan slot nilai

setClass("vcoords",
         representation(nilai = "numeric"),
         contains = "coords")
vcoords <- function(x, y, nilai){
  if ((length(x) != length(y)) ||
      (length(x) != length(nilai)))
      stop("length x, y, dan nilai harus bernilai sama")
  if (!is.numeric(x) || !is.numeric(y)
      || !is.numeric(nilai))
      stop("x, y, dan nilai harus vektor numeric")
  new("vcoords", x = as.vector(x),
      y = as.vector(y),
      nilai = as.vector(nilai))
}

nilai <- function(obj) obj@nilai

vpts <- vcoords(xcoords(pts), ycoords(pts), round(100*runif(5)))
vpts
[1] ( 1.18,  0.53) (-0.56, -0.23) (-0.95,  1.40) (-0.67,  1.76) ( 0.45,  0.49)

Method show yang diwariskan perlu didefinisi ulang

setMethod(show, signature(object = "vcoords"),
          function(object)
            print(paste("(",
                        format(xcoords(object)),
                        ", ",
                        format(ycoords(object)),
                        ": ",
                        format(nilai(object)),
                        ")", sep = ""),
                  quote=FALSE))
vpts
[1] ( 1.18,  0.53: 40) (-0.56, -0.23: 48) (-0.95,  1.40: 56) (-0.67,  1.76: 70)
[5] ( 0.45,  0.49: 92)

Demikian juga method plot perlu didefinisikan ulang

setMethod("plot", signature(x = "vcoords"),
          function(x, txt=FALSE, bbox=FALSE, ...){
            if (bbox) {
              if (!txt) {
                plot(xcoords(x),ycoords(x), type="n", ...);
              } else {
                plot(xcoords(x),ycoords(x), type="n", ...);
                text(xcoords(x),ycoords(x), nilai(x), ...);
              }
              x.1 <- c(bbox(x)[1],bbox(x)[2],bbox(x)[2],bbox(x)[1]);
              y.1 <- c(bbox(x)[3],bbox(x)[3],bbox(x)[4],bbox(x)[4]);
              polygon(x.1,y.1)
            } else {
              if (!txt) {
                plot(xcoords(x),ycoords(x), ...);
              } else {
                plot(xcoords(x),ycoords(x), type="n", ...);
                text(xcoords(x),ycoords(x), nilai(x), ...);
              }
            }
          }
)
plot(vpts)

plot(vpts, txt=T, bbox=T, pch=19, col="red")

Pemeriksaan Suatu Class Objek Untuk mengecek apakah objek merupakan suatu class digunakan fungsi is.

is(pts, "coords")
[1] TRUE
is(pts, "vcoords")
[1] FALSE
is(vpts, "coords")
[1] TRUE
is(vpts, "vcoords")
[1] TRUE

Untuk men-coerce objek ke objek lain dari suatu class digunakan fungsi as().

as(vpts, "coords")
[1] ( 1.18,  0.53) (-0.56, -0.23) (-0.95,  1.40) (-0.67,  1.76) ( 0.45,  0.49)
as(pts, "vcoords")
[1] ( 1.18,  0.53: ) (-0.56, -0.23: ) (-0.95,  1.40: ) (-0.67,  1.76: )
[5] ( 0.45,  0.49: )

6.1.5 Praktikum

  • Fungsi untuk membuat sekumpulan mekaninsme dasar yang dijalankan secara simultan

    angka_acak1 <- function(n,pw){
      x=runif(n) 
      y=runif(n) 
      z=(x+y)^pw
      return(z)
    }
    angka_acak1(10,2)
     [1] 1.3576383 1.1897119 0.5094803 0.4782191 0.3280158 1.2582250 0.3560325
     [8] 3.2446240 1.2550398 2.3412705
    angka_acak2 <- function(n,pw){
      x=runif(n) 
      y=runif(n) 
      z=(x+y)^pw
      return(list(x=x,y=y,zs=z))
    }
    angka_acak2(10,2)
    $x
     [1] 0.2572167 0.2217879 0.5930457 0.2675214 0.5310704 0.7852917 0.1680608
     [8] 0.4043992 0.4715763 0.8681068
    
    $y
     [1] 0.9257080 0.8819776 0.6741868 0.9501670 0.5164449 0.5765190 0.3363312
     [8] 0.3473246 0.0200243 0.5028130
    
    $zs
     [1] 1.3993109 1.2182983 1.6058782 1.4827651 1.0972883 1.8545284 0.2544113
     [8] 0.5650887 0.2416711 1.8794212
    angka_acak3 <- function(n=10,pw=2){
      x=runif(n) 
      y=runif(n) 
      z=(x+y)^pw
      return(z)
    }
    angka_acak3()
     [1] 2.65571539 0.02056553 0.21962506 0.15147396 0.68606869 1.27933517
     [7] 1.07496240 0.47936072 0.01664451 1.74002524
    angka_acak4 <- function(){
      x=runif(n) 
      y=runif(n) 
      z=(x+y)^pw
      return(z)
    }
    n=10;pw=2
    angka_acak4()
     [1] 1.17141019 0.01213335 0.72414991 2.59155656 1.91650592 1.68354963
     [7] 1.29681357 0.01250263 0.30415250 1.66700361
  • Latihan 1

    med <- function(vect){
      n <-length(vect)
      vects <- sort(vect)
      if(n%%2==1){m<-vects[(n+1)/2]}
      else {m <- (vects[n/2]+vects[(n/2)+1])/2}
      return(m)
    }
    x1 <- c(1,5,3,7,3,4,2,7)
    med(x1)
    [1] 3.5
  • Latihan 2

    modus <- function(vect){
      v <- unique(vect)
      f <- NULL
      for(i in v)
      {
        byk <- sum(vect==i)
        f <- c(f,byk)
      }
      fmax <- max(f)
      vf <- cbind(v,f)
      mode <- vf[f==fmax,]
      return(mode)
    }
    x1 <- c(1,5,3,7,3,4,2,7)
    modus(x1)
         v f
    [1,] 3 2
    [2,] 7 2
  • Latihan 3

    p.est<-function(A){
    if(!is.matrix(A))
    stop("input must be on matrix")
    x1<-A[,-1]
    y <-A[,1]
    one<-rep(1,nrow(A))
    x <-cbind(one,x1)
    colnames(x)<-paste("x",1:ncol(x),sep="")
    b.est<-as.vector(solve(t(x) %*% x) %*% (t(x) %*% y))
    names(b.est)<-paste("b",0:(length(b.est)-1),sep="")
    fitted.value<-as.vector(x%*%b.est)
    error<-as.vector(y-fitted.value)
    names(fitted.value)<-names(error)<-1:nrow(A)
    list(beta.est=b.est,fit.val=fitted.value,error=error)
    }
    Pendapatan<-c(3.5,3.2,3.0,2.9,4.0,2.5,2.3)
    Biaya.Iklan<-c(3.1,3.4,3.0,3.2,3.9,2.8,2.2)
    Jumlah.Warung<-c(30,25,20,30,40,25,30)
    X<-cbind(Pendapatan,Biaya.Iklan,Jumlah.Warung)
    p.est(X)
    $beta.est
             b0          b1          b2 
    -0.21381852  0.89843390  0.01745279 
    
    $fit.val
           1        2        3        4        5        6        7 
    3.094910 3.277176 2.830539 3.184754 3.988185 2.738116 2.286320 
    
    $error
              1           2           3           4           5           6 
     0.40508982 -0.07717642  0.16946108 -0.28475357  0.01181483 -0.23811608 
              7 
     0.01368033 
    model<-lm(Pendapatan~Biaya.Iklan+Jumlah.Warung)
    model$coefficients
      (Intercept)   Biaya.Iklan Jumlah.Warung 
      -0.21381852    0.89843390    0.01745279 
    model$fitted.values
           1        2        3        4        5        6        7 
    3.094910 3.277176 2.830539 3.184754 3.988185 2.738116 2.286320 
    model$residuals
              1           2           3           4           5           6 
     0.40508982 -0.07717642  0.16946108 -0.28475357  0.01181483 -0.23811608 
              7 
     0.01368033 
  • Latihan 4

    three.m <- function(vect){
      v <- unique(vect)
      f <- NULL
      for(i in v)
      {
        byk <- sum(vect==i)
        f <- c(f,byk)
      }
      fmax <- max(f)
      vf <- cbind(v,f)
      mode <- vf[f==fmax,]
      return(mode)
    }
    x1 <- rbinom(100,10,0.5)
    three.m(x1)
     v  f 
     4 26 
  • Object-S3

    A1 <- c(1:10)
    class(A1)
    [1] "integer"
    A2 <- matrix(A1,2,5)
    class(A2)
    [1] "matrix" "array" 
    A3 <- 1:12
    A4 <- letters[1:12]
    B1 <- data.frame(A3,A4)
    class(B1)
    [1] "data.frame"
    B1$A4
     [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l"
    A5 <- 10+A3+rnorm(12)
    B2 <- lm(A5~A3) #membuat model linear
    class(B2)
    [1] "lm"
    methods(class=class(B2))
     [1] add1                addterm             alias              
     [4] anova               Anova               avPlot             
     [7] Boot                bootCase            boxcox             
    [10] boxCox              brief               case.names         
    [13] ceresPlot           coerce              confidenceEllipse  
    [16] confint             Confint             cooks.distance     
    [19] crPlot              deltaMethod         deviance           
    [22] dfbeta              dfbetaPlots         dfbetas            
    [25] dfbetasPlots        drop1               dropterm           
    [28] dummy.coef          durbinWatsonTest    effects            
    [31] extractAIC          family              formula            
    [34] fortify             hatvalues           hccm               
    [37] infIndexPlot        influence           influencePlot      
    [40] initialize          inverseResponsePlot kappa              
    [43] labels              leveneTest          leveragePlot       
    [46] linearHypothesis    logLik              logtrans           
    [49] mcPlot              mmp                 model.frame        
    [52] model.matrix        ncvTest             nextBoot           
    [55] nobs                outlierTest         plot               
    [58] powerTransform      predict             Predict            
    [61] print               proj                qqPlot             
    [64] qr                  residualPlot        residualPlots      
    [67] residuals           rstandard           rstudent           
    [70] S                   show                sigmaHat           
    [73] simulate            slotsFromS3         spreadLevelPlot    
     [ reached getOption("max.print") -- omitted 4 entries ]
    see '?methods' for accessing help and source code
    summary(B2)
    
    Call:
    lm(formula = A5 ~ A3)
    
    Residuals:
        Min      1Q  Median      3Q     Max 
    -1.2389 -0.6844 -0.1951  0.3688  1.6757 
    
    Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
    (Intercept)  9.79440    0.59644   16.42 1.46e-08 ***
    A3           1.04520    0.08104   12.90 1.48e-07 ***
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    
    Residual standard error: 0.9691 on 10 degrees of freedom
    Multiple R-squared:  0.9433,    Adjusted R-squared:  0.9376 
    F-statistic: 166.3 on 1 and 10 DF,  p-value: 1.479e-07
    names(B2)
     [1] "coefficients"  "residuals"     "effects"       "rank"         
     [5] "fitted.values" "assign"        "qr"            "df.residual"  
     [9] "xlevels"       "call"          "terms"         "model"        
    B2$coefficients
    (Intercept)          A3 
       9.794403    1.045204 
  • Mengubah menjadi class : class(obj) <- “class.name”

    Mobil1 <- list(Nama="Toyota", Panjang=3.5,Lebar=2, Kecepatan=180)
    class(Mobil1)
    [1] "list"
    class(Mobil1) <- "mobil"
    Mobil2 <- list(Nama="Suzuki", Panjang=1,Lebar=1.8, Kecepatan=150)
    class(Mobil2) <- "mobil"
  • Mengubah menjadi class menggunakan fungsi konstruktor. Fungsi konstruktor menambahkan screening sebelum menambahkan class

    Mobil <- function(Nama,Panjang,Lebar,Kecepatan){
    if(Panjang<2 || Lebar<1.5 || Kecepatan<80)
    stop("atribut tidak sesuai")
    Mobil <- list(Nama=Nama, Panjang=Panjang,Lebar=Lebar, Kecepatan=Kecepatan)
    class(Mobil) <- "mobil"
    Mobil
    }
    Mobil3 <- Mobil("Daihatsu", 2.1, 1.9, 120)
    Mobil4 <- Mobil("Proton", 2, 1.8, 80)
    Mobil3
    $Nama
    [1] "Daihatsu"
    
    $Panjang
    [1] 2.1
    
    $Lebar
    [1] 1.9
    
    $Kecepatan
    [1] 120
    
    attr(,"class")
    [1] "mobil"
    Mobil4
    $Nama
    [1] "Proton"
    
    $Panjang
    [1] 2
    
    $Lebar
    [1] 1.8
    
    $Kecepatan
    [1] 80
    
    attr(,"class")
    [1] "mobil"
  • Fungsi Aksesor

    #Cara langsung (tidak direkomendasikan)
    Mobil2$Nama
    [1] "Suzuki"
    Mobil3$Panjang
    [1] 2.1
    #Dengan fungsi aksesor
    nama <- function(objek) objek$Nama
    kecepatan <- function(objek) objek$Kecepatan
    nama(Mobil1)
    [1] "Toyota"
    kecepatan(Mobil3)
    [1] 120
  • Fungsi Generik : function(…){…}

    print.mobil <- function(objek) {
    print(cat("Nama : ", nama(objek), "\n",
    "Kecepatan : ", kecepatan(objek),
    sep="")
    )
    }
    Mobil1
    Nama : Toyota
    Kecepatan : 180NULL
  • memciptakan fungsi generik. method hanya dapat didefinisikan untuk fungsi yang generik. Membuat nama method baru dengan menciptakan fungsi generik

    fungsibaru <- function (objek) UseMethod("fungsibaru")
  • Object-S4 : mengatasi masalah dalam sistem objek S3 dengan sistem objek lebih formal.

    setClass("car",
    representation(Nama="character",Panjang="numeric",
    Lebar="numeric",Kecepatan="numeric"))
    Car1 <- new("car", Nama="Toyota",Panjang=3.5, Lebar=2,Kecepatan=180)
    Car1
    An object of class "car"
    Slot "Nama":
    [1] "Toyota"
    
    Slot "Panjang":
    [1] 3.5
    
    Slot "Lebar":
    [1] 2
    
    Slot "Kecepatan":
    [1] 180
  • Membuat Object S4 dengan menggunakan fungsi konstruktor

    Car <- function(Nama,Panjang,Lebar,Kecepatan){
    if(Panjang<2 || Lebar<1.5 || Kecepatan<80)
    stop("atribut tidak sesuai")
    new("car", Nama=Nama, Panjang=Panjang,Lebar=Lebar, Kecepatan=Kecepatan)
    }
    Car2 <- Car("Suzuki", 2.4, 1.8, 150)
    class(Car2)
    [1] "car"
    attr(,"package")
    [1] ".GlobalEnv"
    class(Mobil1)
    [1] "mobil"
  • Fungsi Aksesor

    #Cara langsung (tidak direkomendasikan)
    Car1@Nama
    [1] "Toyota"
    Car2@Kecepatan
    [1] 150
    #Dengan fungsi aksesor
    nama1 <- function(objek) objek@Nama
    kecepatan1 <- function(objek) objek@Kecepatan
    nama1(Car1)
    [1] "Toyota"
    kecepatan1(Car2)
    [1] 150
  • Class Method

    setMethod(show, "car", function(object) {
    print(cat("Nama : ", nama1(object), "\n",
    "Kecepatan : ", kecepatan1(object),
    sep="")
    )}
    )
    Car2
    Nama : Suzuki
    Kecepatan : 150NULL
  • Menciptakan fungsi genetik S4

    setGeneric("fungsibaru",
    function(objek)
    standardGeneric("fungsibaru"))
    [1] "fungsibaru"

BAB 7

7.1 Optimasi

7.1.1 Representasi Bilangan

Perbedaan perhitungan di matematika dan komputer, seperti nilai 0.2=0.0011 di komputer, maka untuk membuat hal itu sama bisa menggunakan fungsi all.equal(0.2, 0.3-0.1).

#before
paste('before = ',(0.3-0.1) == 0.2)
[1] "before =  FALSE"
#after
paste('after = ',isTRUE(all.equal(0.2,0.3-0.1)))
[1] "after =  TRUE"

7.1.2 Differensial

Dapat melakukan diferentiasi dari suatu fungsi, bisa berupa hasil turunannya, maupun angka dari penurunan tersebut.

#fungsi
xfs <- expression(exp(x^2))
xturunan <- deriv(~x^2 ,"x")
#turunan dari suatu fungsi
D(xfs,'x')
exp(x^2) * (2 * x)
#value dari turunan fungsi
x <- 2
eval(xturunan)
[1] 4
attr(,"gradient")
     x
[1,] 4

7.1.2 Integral

Dapat melakukan integral dari suatu fungsi, untuk mendapatkan batas dari fungsi integralan tersebut.

#fungsi
fs <- function(x){x^2}
#mendapatkan integral dari suatu fungsi
library(Ryacas)
yac_str("Integrate(x) x^2")
[1] "x^3/3"
#value dari integral fungsi
lower = 0
upper = 1
integrate(fs,lower,upper)
0.3333333 with absolute error < 3.7e-15

7.1.3 Operasi Numerik

Beberapa metode untuk mendapatkan nilai optimum dari suatu fungsi, baik mengoptimukan nilai maksimum maupun minimum.

  • Golden Section Search

    Pada umumnya, algoritma Golden Section digunakan untuk menyelesaikan NLP (Non-Linier Programming). mecari nilai optimum maksimum or minimum dari fungsi peubah tunggal dari suatu selang. misal : ingin dicari nilai minimum dari f(x) = |x-3.5| + (x-2)^2.

    nilai a<b. set tol sebagai batas maksimum selisih antara a dan b.

    x <- seq(1,5, by=0.01)
    f <- abs(x-3.5)+(x-2)^2
    plot(x,f, 
         type = "l", 
         main = "Grafik fungsi f(x) = |x-3.5| + (x-2)^2", 
         xlab = "Nilai x", 
         ylab = "Nilai f(x)",
         xlim = c(0,6),
         ylim = c(0,12))

    golden <- function(f,a,b,tol,optval){
      ratio <- 2/(sqrt(5)+1)
      x1 <- b - ratio * (b-a)
      x2 <- a + ratio * (b-a)
      f1 <- f(x1)
      f2 <- f(x2)
      if(optval=='maksimum'){
        while(abs(b-a) > tol) {
          if (f1 > f2){
            b <- x2
            x2 <- x1
            f2 <- f1
            x1 <- b - ratio * (b-a)
            f1 <- f(x1)
        } else{
          a <- x1
          x1 <- x2
          f1 <- f2
          x2 <- a + ratio * (b-a)
          f2 <- f(x2)
        }
      }
      } else{
        while(abs(b-a) > tol){
          if (f2 > f1){
            b <- x2
            x2 <- x1
            f2 <- f1
            x1 <- b - ratio * (b-a)
            f1 <- f(x1)
        } else{
          a <- x1
          x1 <- x2
          f1 <- f2
          x2 <- a + ratio * (b-a)
          f2 <- f(x2)
        }
      }
      }
      return((a+b)/2)
    }
    
    
    tol = 0.0000001
    a = 1
    b = 10
    optval = 'maksimum'
    #f <- function(x){abs(x-3.5)+(x-2)^2}
    f <- function(x){18*x - 2*x^2 + 10}
    golden(f,a,b,tol,optval)
    [1] 4.5
  • Newton-Raphson

    Suatu fungsi memiliki turunan pertama dan kedua, maka nilai minimum dapat menggunakan metode newton raphosn. Metode ini lebih cepat ketimbang golden section search. Tahapan interasi pada metode newton-raphson akan tersu berjalan sampai f′(xn−1) mendekati 0 atau lebih kecil dari nilai toleransi.

    #fungsi
    newtonr <- function(fx, x0=1){
      fx1 <- deriv(fx, "x")        #turunan pertama
      fx2 <- deriv(D(fx,"x"), "x") #turunan kedua
        e <- 1000
       while (e > 1e-6) {
          x <- x0
         f1 <- attr(eval(fx1), "gradient")[1]
         f2 <- attr(eval(fx2), "gradient")[1]
          e <- abs(f1) #bisa juga e <- abs(x1-x0)
         x1 <- x0-f1/f2
         x0 <- x1
       }
        return(x1)
    }
    fs <- expression(4*(x^2) - 3*x - 7)
    f <- function(x){4*(x^2) - 3*x - 7}
    newtonr(fs)
    [1] 0.375
    curve(f, ylab='fx')
    abline(v=0.375, lty=3, lwd=4, col="gray60")

  • Fungsi Optimasi Built-in

    Algoritma Nelder-Mead adalah salah satu metode optimasi untuk fungsi yang memiliki lebih dari satu peubah. Pada R algoritma Nelder-Mead diterapkan pada fungsi:

    Fungsi optimize( ) digunakan untuk mendapatkan nilai minimum/maksimum dari suatu fungsi dengan satu peubah. Fungsi optim( ) digunakan untuk mendapatkan nilai minimum/maksimum dari suatu fungsi dengan peubah lebih dari satu.

    #nilai minimum
    fs <- function(x){(x-(1/3))^2}
    curve(fs, from=0,to=1)
    abline(v=0.3333333, lty=3, lwd=1, col="red")

    optimize(fs, interval = c(0,1), tol = 0.0001, maximum = FALSE)
    $minimum
    [1] 0.3333333
    
    $objective
    [1] 0
    #nilai maksimum
    fs <- function(x){(x-(1/3))^2}
    curve(fs, from=0,to=1)
    abline(v=0.9999339, lty=3, lwd=1, col="red")

    optimize(fs, interval = c(0,1), tol = 0.0001, maximum = TRUE)
    $maximum
    [1] 0.9999339
    
    $objective
    [1] 0.4443563
    f <- function(para,y,x){
         X <- cbind(1,x)
         yhat <- X %*% as.matrix(para)
         sisa2 <- sum((y-yhat)^2)
         return(sisa2)
         }
    x1 <- runif(10,1,10)
    x2 <- runif(10,1,10)
    galat <- rnorm(10,0,0.5)
    y <- 1 + 2*x1 + 3*x2 + galat
    hasil <- optim(par = c(1,1,1),f,y=y,x=cbind(x1,x2))
    hasil$par
    [1] 1.061033 2.016336 2.960377
    #bandingkan hasilnya dengan fungsi lm() untuk membuat model regresi
    lm(y~x1+x2)
    
    Call:
    lm(formula = y ~ x1 + x2)
    
    Coefficients:
    (Intercept)           x1           x2  
          1.062        2.016        2.960  
  • MLE : Maximum Likelihood Estimator

    Maximum Likelihood Estimator (MLE) merupakan metode yang paling sering digunakan untuk menduga parameter sebaran

    library(bbmle)
    lnorm <- function (para ,xd){
      nilai <- -1*sum(dnorm(xd, mean = para[1], sd = para[2], log = TRUE))
      return (nilai)
      }
    set.seed(2)
    x <- rnorm(10,2,5)
    hasil <- optim(c(1,1), lnorm, xd = x)
    hasil
    $par
    [1] 3.056350 4.671425
    
    $value
    [1] 29.6057
    
    $counts
    function gradient 
          63       NA 
    
    $convergence
    [1] 0
    
    $message
    NULL
    library(bbmle)
    lnorm <- function (mean, sd){
      nilai <- -1*sum(dnorm(x, mean = mean, sd = sd, log = TRUE))
      return (nilai)
      }
    suppressWarnings(
      estnorm <- mle2(minuslogl = lnorm, start=list(mean = 1, sd = 3))
      )
    summary(estnorm)
    Maximum likelihood estimation
    
    Call:
    mle2(minuslogl = lnorm, start = list(mean = 1, sd = 3))
    
    Coefficients:
         Estimate Std. Error z value     Pr(z)    
    mean   3.0557     1.4775  2.0682   0.03862 *  
    sd     4.6722     1.0448  4.4721 7.746e-06 ***
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    
    -2 log L: 59.2114 

7.1.5 Latihan

  • Latihan 1

    #fungsi
    fs <- function(x){x^2+4}
    #mendapatkan integral dari suatu fungsi
    library(Ryacas)
    yac_str("Integrate(x) x^2+4")
    [1] "x^3/3+4*x"
    #value dari integral fungsi
    lower = -10
    upper = 10
    integrate(fs,lower,upper)
    746.6667 with absolute error < 8.3e-12
  • Latihan 2

    #fungsi
    fs <- function(t){t^4*exp(-t)}
    #mendapatkan integral dari suatu fungsi
    library(Ryacas)
    yac_str("Integrate(t) t^4*exp(-t)")
    [1] "AntiDeriv(t,t^4*exp(-t))"
    #value dari integral fungsi
    lower = 0
    upper = Inf
    integrate(fs,lower,upper)
    24 with absolute error < 2.2e-05
  • Latihan 3

    Mencari titik maksimum dan minimum dari fungsi: f(x) = sin(x) + sin(2x) + cos(3x)

    #fungsi
    fs <- function(x){sin(x)+sin(2*x)+cos(3*x)}
    curve(fs, from = 0, to = 2*pi)

    #minimum lokal
    optimize(fs, interval = c(0, 2*pi)) 
    $minimum
    [1] 3.033129
    
    $objective
    [1] -1.054505
    #minimum global
    optimize(fs, interval = c(4, 2*pi)) 
    $minimum
    [1] 5.273383
    
    $objective
    [1] -2.741405
    #maksimum lokal
    optimize(fs, interval = c(0, 2*pi), maximum = T) 
    $maximum
    [1] 4.0598
    
    $objective
    [1] 1.096473
    #maksimum global
    optimize(fs, interval = c(0,1.5), maximum = T)
    $maximum
    [1] 0.3323289
    
    $objective
    [1] 1.485871
    golden <- function(f,a,b,tol,optval){
      ratio <- 2/(sqrt(5)+1)
      x1 <- b - ratio * (b-a)
      x2 <- a + ratio * (b-a)
      f1 <- f(x1)
      f2 <- f(x2)
      if(optval=='maksimum'){
        while(abs(b-a) > tol) {
          if (f1 > f2){
            b <- x2
            x2 <- x1
            f2 <- f1
            x1 <- b - ratio * (b-a)
            f1 <- f(x1)
        } else{
          a <- x1
          x1 <- x2
          f1 <- f2
          x2 <- a + ratio * (b-a)
          f2 <- f(x2)
        }
      }
      } else{
        while(abs(b-a) > tol){
          if (f2 > f1){
            b <- x2
            x2 <- x1
            f2 <- f1
            x1 <- b - ratio * (b-a)
            f1 <- f(x1)
        } else{
          a <- x1
          x1 <- x2
          f1 <- f2
          x2 <- a + ratio * (b-a)
          f2 <- f(x2)
        }
      }
      }
      return((a+b)/2)
    }
    tol = 0.0000001
    fs <- function(x){sin(x)+sin(2*x)+cos(3*x)}
    #minimum lokal
    golden(fs,0,2*pi,tol,'minimum')
    [1] 3.033133
    #minimum global
    golden(fs,4,2*pi,tol,'minimum')
    [1] 5.273376
    #maksimum lokal
    golden(fs,0,2*pi,tol,'maksimum')
    [1] 4.059791
    #maksimum global
    golden(fs,0,1.5,tol,'maksimum')
    [1] 0.332332
  • Latihan 4

    Mencari titik minimum dari fungsi: f(x) = 4*(x4) - 2*(x^3) - 3*(x)

    #fungsi
    fs <- function(x){4*(x^4)-2*(x^3)-3*x}
    curve(fs, from = -1, to = 20)

    #minimum
    optim(par=c(-0.5),fn=fs) 
    $par
    [1] 0.728418
    
    $value
    [1] -1.832126
    
    $counts
    function gradient 
          36       NA 
    
    $convergence
    [1] 0
    
    $message
    NULL
  • Latihan 5

    Mencari minimum dari residual sum of square persamaan regresi

    #data
    data5 = data.frame(x=c(1,2,3,4,5,6),
                       y=c(1,3,5,6,8,12))
    jkg <- function(data,b){with(data,sum((b[1]+b[2]*x-y)))}
    hasil1 <- optim(par = c(1,1), fn=jkg, data=data5)
    hasil2 <- lm(y~x, data = data5)
    plot(data5)
    abline(hasil1$par,col=4)

    hasil1$par
    [1]  4.996335e+54 -3.183805e+55
    hasil2$coefficients
    (Intercept)           x 
      -1.266667    2.028571 
    hasil1$value
    [1] -6.386211e+56
    sum(hasil2$residuals^2)
    [1] 2.819048

BAB 8

8.1 Latihan

8.1.1 nomor 1

Misalkan saja ada sebuah vektor x=[3,1,4,1,5,9,2,6,5]x=[3,1,4,1,5,9,2,6,5], buat program untuk mengurutkan vektor tersebut dari kecil ke besar, kemudian bandingkan hasilnya dengan fungsi sort! Gunakan algoritme pada slide kuliah ke-16 !

Jawaban:

Untuk melakukan pengurutan, iterasi yang akan digunakan terdiri dari dua tingkat,

  1. iterasi untuk memastikan semua elemen diperiksa

  2. Iterasi untuk mengakses elemen-elemen vektor yang digunakan untuk penukaran antar elemen

Pada iterasi tingkat kedua nilai-nilai yang besar akan semakin terdorong ke-belakang sehingga elemen-elemen belakang vektor tidak perlu diperiksa lagi. Misal pada saat iterasi tingkat pertama sama dengan 3 maka elemen yang akan dibandingkan hanya dari element 1 sampai 7 saja (ingat ada j+1). Semakin meningkat iterasi tingkat 1 maka banyaknya iterasi tingkat 2 semakin mengecil (pada kasus ini diakomodir dengan n_x-i).

x <- c(3,1,4,1,5,9,2,6,5)
# mendefinisikan objek baru yang akan digunakan untuk menampilkan hasil sortir
x_sort <- x
#jumlah amatan 
n_x <- length(x)
#iterasi tingkat 1
for(i in 1:(n_x-1)){
  #iterasi tingkat 2
  for(j in 1:(n_x-i)) {
    # Pemeriksaan kondisi apakah elemen ke-j+1 lebih kecil dari elemen ke-j
    if(x_sort[j+1] < x_sort[j]) {
      # jika terpenuhi
      #Buat tempat sementara untuk menyimpan elemen ke-j yang akan ditukar
      tmp <- x_sort[j]
      # Ganti nilai elemen ke-j dengan nilai yang ada pada elemen ke j+1
      x_sort[j] <- x_sort[j+ 1]
      # Ganti nilai elemen j+1 dengan nilai yang ada dalam objek temp
      x_sort[j+1] <- tmp
    }
  }
  }
x_sort
[1] 1 1 2 3 4 5 5 6 9

8.1.2 nomor 2

Berdasarkan jawaban nomor 1, Buatlah fungsi yang bernama fungsi_urutan dengan yang memiliki input x dan outputnya merupakan vector yang sudah terurut!

fungsi_urutan <- function(x){
n_x <- length(x)



for(i in 1:(n_x-1)){
  for(j in 1:(n_x-i)) {
    if(x[j+1] < x[j]) {
      tmp <- x[j]
      x[j] <- x[j+ 1]
      x[j+1] <- tmp
    }
  }
  }
  return(x)
}

#mencoba menerapkan fungsi urutan
x <- c(3,1,4,1,5,9,2,6,5)
fungsi_urutan(x)
[1] 1 1 2 3 4 5 5 6 9

8.1.3 nomor 3

Bandingkan kecepatan running user-defined-function pada nomor 2 dan fungsi sort dengan menggunakan package microbenchmark.

fungsi_urutan <- function(x){
n_x <- length(x)



for(i in 1:(n_x-1)){
  for(j in 1:(n_x-i)) {
    if(x[j+1] < x[j]) {
      tmp <- x[j]
      x[j] <- x[j+ 1]
      x[j+1] <- tmp
    }
  }
  }
  return(x)
}

#mencoba menerapkan fungsi urutan
microbenchmark::microbenchmark(sort(x),fungsi_urutan(x))
Unit: microseconds
             expr  min    lq    mean median    uq     max neval
          sort(x) 39.3 41.75  57.654   63.8 67.80   167.0   100
 fungsi_urutan(x)  7.1  8.20 154.611   10.3 14.85 14315.8   100

8.1.4 nomor 4

Susunlah sintaks R untuk penjumlahan deret berikut!

z=2−6/5+8/10−10/17+12/26−…

hint: Cari terlebih dahulu formula/rumus dari deret tersebut

Jawaban:

Rumus dari deret tersebut adalah

Z = Σ((−1)^(i+1))*(2i+2)/(i^2+1)

#menuliskan rumus fungsi dalam bentuk function
fz <- function(n){
  (-1)^(n+1)*((2*n+2)/((n^2)+1))
}
#mendefinisikan kriteris stopping
stopping_criteria <- function(y_current,y_before){
  abs(y_current-y_before)
}
#nilai awal kriteria stopping
error <- 10
#nilai awal deret
z0 <- 0
# nilai awal iterasi
n <- 1
#menuliskan iterasi untuk mencari jumlah deret
while (error>0.00001) {
  z <- z0 + fz(n)
  error <- stopping_criteria(z,z0)
  z0 <- z
  n <- n+1
}
# final result
z 
[1] 1.267197
# criteria stopping
error
[1] 1e-05

8.1.5 nomor 5

Z = 2/5+3/40+6/135+11/320+18/625+27/1080+…

hint: Cari terlebih dahulu formula/rumus dari deret tersebut

Jawaban:

Rumus dari deret tersebut adalah

z=Σ(i^2 +2*i+3)/(5*i^3)

#menuliskan rumus fungsi dalam bentuk function
fz <- function(n){
  ((n^2) - 2*n + 3) / (5*n^3)
}
#mendefinisikan kriteris stopping
stopping_criteria <- function(y_current,y_before){
  abs(y_current-y_before)
}
#nilai awal kriteria stopping
error <- 10
#nilai awal deret
z0 <- 0
# nilai awal iterasi
n <- 1
#menuliskan iterasi untuk mencari jumlah deret
while (error>0.00001) {
  z <- z0 + fz(n)
  error <- stopping_criteria(z,z0)
  z0 <- z
  n <- n+1
}
# final result
z 
[1] 2.159406
# criteria stopping
error
[1] 1e-05

8.2 Tugas

  1. Susunlah sintaks R untuk penjumlahan deret berikut!

    z = 1 + 1 + 1/2 + 1/3 + 1/5 + 1/8 + ⋯

    fungsi_sum <- function(n){
      deret <- 0
      bawah <- matrix(nrow = n,ncol = 1)
      deret <- matrix(nrow = n,ncol = 1)
      bawah[1] <- 0
      bawah[2] <- 1
      for (i in 2:n) {
        bawah[i+1] = bawah[i]+bawah[i-1] 
      }
      for (i in 1:length(bawah)) {
        if (bawah[i]==0) {
          deret[i] = 1
        }else{
          deret[i] = round(1/bawah[i],2)
        }
      }
      return(sum(deret[-1]))
    }
    n = 5
    fungsi_sum(n)
    [1] 3.03
  2. Susunlah SIntaks R untuk penjulahan deret berikut!

    Z = 10-2 + 0.4-0.08+…

    n=4
    a0 = 10
    a1 = a0-(a0/5)
    for (i in 2:(n-1)) {
      j = i-1
      c = ((a0/5)^i)/(a0^j)
      d = (-1)^i
      a = c*d
      a1 = a1+a
    }
    a1
    [1] 8.32
  1. Buatlah fungsi untuk mengurutkan vektor Berikut dari besar ke kecil. Bandingkan hasilnya dengan mengguakan fungsi sort yang ada di R

    x = [13, 7, 6, 45, 21, 9, 101, 102 ]

    fungsi_urutan <- function(x){
      n_x <- length(x)
      for(i in 1:(n_x-1)){
        for(j in 1:(n_x-i)) {
          if(x[j+1] > x[j]) {
            tmp <- x[j]
            x[j] <- x[j+ 1]
            x[j+1] <- tmp
          }
        }
      }
      return(x)
    }
    #mencoba menerapkan fungsi urutan
    x = c(13.7,6.45,21.9,101,102)
    fungsi_urutan(x)
    [1] 102.00 101.00  21.90  13.70   6.45

BAB 9

9.1 Metode Fixed-Point

Fungsi fixedpoint memiliki beberapa argumen yaitu ftn yang berupa function di R, x0 merupakan nilai awal, tol merupakan nilai tolerasi dan max.iter adalah iterasi maksimum. tol dan max.iter masing-masing memiliki nilai default 1e-9 dan 100.

fixedpoint <- function(ftn,fx, x0, tol = 1e-9, max.iter = 100) {
  
  xold <- x0
  xnew <- ftn(xold)
  iter <- 1
  err <- abs(xnew-xold)
# membuat tempat penyimpanan result
all_res <- data.frame(iteration=iter,
                      x_old=xold,
                      x_new=xnew,
                      `f(x)`=fx(xnew),
                      error = err
                      )
while ((err > tol) && (iter < max.iter)) {
# xold digunakan untuk menyimpan akar-akar persamaan dari iterasi sebelumnya
    xold <- xnew
# xnew digunakan untuk menghitung akar-akar persamaan pada iterasi yang sedang berjalan
    xnew <- ftn(xold) #ingat ftn bentuknya fungsi
    

    
# menghitung error
    err <- abs(xnew-xold) 
# iter digunakan untuk menyimpan banyaknya iterasi
    iter <- iter + 1
#menyimpan semua hasil pada iterasi tertentu
    all_res <-
      rbind(all_res,
            data.frame(
              iteration = iter,
              x_old = xold,
              x_new = xnew,
              `f(x)` = fx(xnew),
              error = err
            ))
  }
# output bergantung pada kesuksesan algoritma
  if (err> tol) {
      cat("Algorithm failed to converge\n")
      return(list(all_result=all_res,x_roots=NULL))
      } else {
           cat("Algorithm converged\n")
           return(list(all_result=all_res,x_roots=xnew))
           }
 }

9.2 Metode Newton-Raphson

Fungsi newtonraphson memiliki beberapa argumen yaitu ftn yang berupa function di R, x0 merupakan nilai awal, tol merupakan nilai tolerasi dan max.iter adalah iterasi maksimum. tol dan max.iter masing-masing memiliki nilai default 1e-9 dan 100.

newtonraphson <- function(ftn, x0, tol = 1e-5, max.iter = 100) {
  
    x <- x0
    fx <- ftn(x)
    iter <- 0
    # menyimpan semua hasil
    all_res <- data.frame(iteration=iter,
                      x_old=x0,
                      x_new=x,
                      `f(x)`=fx[[1]],
                      error = abs(fx[[1]])
                      )

   while ((abs(fx[1]) > tol) && (iter < max.iter)) {
         x0 <- x
         x <- x - fx[1]/fx[2]
         fx <- ftn(x)
         iter <- iter + 1
          #menyimpan semua hasil 
         all_res <- rbind(all_res,data.frame(iteration=iter,
                      x_old=x0,
                      x_new=x,
                      `f(x)`=fx[[1]],
                      error = abs(fx[[1]])
                      ))
   }
   # output bergantung pada kesuksesan algoritma
   if (abs(fx[1]) > tol) {
       cat("Algorithm failed to converge\n")
       return(list(all_result=all_res,x_roots=NULL))
       } else {
            cat("Algorithm converged\n")
            return(list(all_result=all_res,x_roots=x))
            }
   }

9.3 Metode Secant

Fungsi secant memiliki beberapa argumen yaitu ftn yang berupa function di R, x0 dan x1 merupakan nilai awal, tol merupakan nilai tolerasi dan max.iter adalah iterasi maksimum. tol dan max.iter masing-masing memiliki nilai default 1e-9 dan 100.

secant <- function(ftn, x0, x1, tol = 1e-9, max.iter = 100) 
  {
  xa <- x0
  fxa <- ftn(xa)
  xb <- x1
  fxb <- ftn(xb)
  iter <- 0
  # menyimpan semua hasil
  all_res <- data.frame(iteration=iter,
                      xa=x0,
                      xb=x1,
                      `f(x_a)`=fxa,
                      `f(x_b)`=fxb,
                      error = abs(xb-xa)
                      )
  
  while ((abs(xb-xa) > tol) && (iter < max.iter)) 
    {
    xt <- fxb*((xb-xa)/(fxb-fxa))
    xc <- xb-xt

    iter <- iter + 1

    xa <- xb
    xb <- xc
    fxa <- ftn(xa)
    fxb <- ftn(xb)
    # menyimpan semua hasil
    all_res <- rbind(all_res,data.frame(iteration=iter,
                      xa=xa,
                      xb=xb,
                      `f(x_a)`=fxa,
                      `f(x_b)`=fxb,
                      error = abs(xb-xa)
                      ))
  }

  if (abs(xb-xa) > tol) {
    cat("Algorithm failed to converge\n")
    return(list(all_result=all_res,x_roots=NULL))
  } else {
    cat("Algorithm converged\n")
    return(list(all_result=all_res,x_roots=xb))
  }
}

9.4 Metode Bisection

Fungsi bisection memiliki beberapa argumen yaitu fx yang berupa function di R, xl dan xr merupakan nilai awal, tol merupakan nilai tolerasi dan max.iter adalah iterasi maksimum. tol dan max.iter masing-masing memiliki nilai default 1e-9 dan 100.

bisection <- function(f, xl, xr, tol = 1e-7,max.iter = 100) {
# Jika tanda dari hasil perkalian  evaluasi fungsi pada titik xl dan xr bernilai positif (f(xl)*f(xr)>0) maka program dihentikan
if (f(xl)*f(xr) > 0) {
    stop('signs of f(xl) and f(xr) must be differ')
}
  
# menyimpan semua hasil
  all_res <-data.frame(iteration=0,
                      x_left=0,
                      x_right=0,
                      x_mid = 0,
                      `f(xm)`=0,
                      error = 1000
                      )
  
  for (iter in 1:max.iter) {
    xm <- (xl + xr) / 2 # menghitung nilai tengah

  # menyimpan semua hasil
  all_res <-rbind(all_res, data.frame(iteration=iter,
                      x_left=xl,
                      x_right=xr,
                      x_mid = xm,
                      `f(xm)`=f(xm),
                      error = abs(xr - xl)
                      ))

#Jika fungsinya sama dengan 0 di titik tengah atau titik tengah di bawah toleransi yang diinginkan, hentikan dan keluarkan nilai tengah sebagai akar
if ((f(xm) == 0) || abs(xr - xl) < tol) {
      return(list(all_result=all_res,x_roots=xm))
    }
# Jika diperlukan iterasi lain,
# periksa tanda-tanda fungsi pada titik xm dan xl dan tetapkan kembali
# xl atau xr sebagai titik tengah yang akan digunakan pada iterasi berikutnya.    
    ifelse(sign(f(xm)) == sign(f(xl)), 
           xl <- xm,xr <- xm)
  }
}

9.5 Latihan

soal 1:

Misalkan diberikan suatu persamaan x^3−2x−5=0x3−2x−5=0.

  1. Gambarkan fungsi tersebut!

  2. Carilah akar-akar persamaan dengan menggunakan metode fixed-point, newton-raphson, secant dan bisection!

  3. Buatlah animasi untuk metode newton-raphson dan bisection dengan bantuan package gganimate!

fx <- function(x) {
  x^3 - 2 * x - 5
}

Khusus metode fixed-point, kita ubah persamaan x^3−2x−5=0x3−2x−5=0 menjadi x=g(x)x=g(x) dengan cara berikut:

x^3−2x−5=0

2x = 5−x^3

2x=5−x^3

x = (5−x^3)/2

sehingga diperoleh

g(x) = (5−x^3)/2

gx <- function(x){
  5-x^{3}/(2)
}

mendefinisikan persamaan dalam bentuk fungsi untuk newton-raphson

fx_nr <- function(x) {
rumus_fungsi <- function(x) x^3-2*x-5
fungsi <- rumus_fungsi(x)
# mencari turunan dengan menggunakan fungsi Deriv
# dari package Deriv
rumus_turunan <- Deriv::Deriv(fx)
turunan <- rumus_turunan(x)
return(c("fungsi"=fungsi,"turunan"=turunan))
}
  1. Gambarkan fungsi tersebut!
curve(fx,xlim=c(-3,3), col='steelblue',lwd=2)
abline(h=0)
abline(v=0)

  1. Carilah akar-akar persamaan dengan menggunakan metode fixed-point, newton-raphson, secant dan bisection!
#fixed-point
fixed_point_res <-fixedpoint(ftn = gx,fx = fx,x0 =0)
Algorithm failed to converge
fixed_point_res
$all_result
   iteration          x_old          x_new           f.x.         error
1          1   0.000000e+00   5.000000e+00   1.100000e+02  5.000000e+00
2          2   5.000000e+00  -5.750000e+01  -1.899994e+05  6.250000e+01
3          3  -5.750000e+01   9.505969e+04   8.589921e+14  9.511719e+04
4          4   9.505969e+04  -4.294960e+14  -7.922777e+43  4.294960e+14
5          5  -4.294960e+14   3.961389e+43  6.216449e+130  3.961389e+43
6          6   3.961389e+43 -3.108224e+130           -Inf 3.108224e+130
7          7 -3.108224e+130            Inf            NaN           Inf
8          8            Inf           -Inf            NaN           Inf
9          9           -Inf            Inf            NaN           Inf
10        10            Inf           -Inf            NaN           Inf
11        11           -Inf            Inf            NaN           Inf
12        12            Inf           -Inf            NaN           Inf
13        13           -Inf            Inf            NaN           Inf
14        14            Inf           -Inf            NaN           Inf
15        15           -Inf            Inf            NaN           Inf
 [ reached 'max' / getOption("max.print") -- omitted 85 rows ]

$x_roots
NULL
# newton raphson
nr_res <-newtonraphson(ftn=fx_nr,x0=0)
Algorithm converged
nr_res
$all_result
         iteration      x_old      x_new       f.x.     error
1                0  0.0000000  0.0000000  -5.000000  5.000000
fungsi           1  0.0000000 -2.5000000 -15.625000 15.625000
fungsi1          2 -2.5000000 -1.5671642  -5.714632  5.714632
fungsi2          3 -1.5671642 -0.5025924  -4.121770  4.121770
fungsi3          4 -0.5025924 -3.8207065 -53.132488 53.132488
fungsi4          5 -3.8207065 -2.5493934 -16.470758 16.470758
fungsi5          6 -2.5493934 -1.6081115  -5.942390  5.942390
fungsi6          7 -1.6081115 -0.5761004  -4.039002  4.039002
fungsi7          8 -0.5761004 -4.5977096 -92.995258 92.995258
fungsi8          9 -4.5977096 -3.0835431 -28.151977 28.151977
fungsi9         10 -3.0835431 -2.0221943  -9.224909  9.224909
fungsi10        11 -2.0221943 -1.1237641  -4.171613  4.171613
fungsi11        12 -1.1237641  1.2086516  -5.651658  5.651658
fungsi12        13  1.2086516  3.5807900  33.751515 33.751515
fungsi13        14  3.5807900  2.6552332   8.409627  8.409627
 [ reached 'max' / getOption("max.print") -- omitted 4 rows ]

$x_roots
  fungsi 
2.094551 
# secant
sec_res <- secant(fx,x0=1,x1=3)
Algorithm converged
sec_res
$all_result
   iteration       xa       xb        f.x_a.        f.x_b.        error
1          0 1.000000 3.000000 -6.000000e+00  1.600000e+01 2.000000e+00
2          1 3.000000 1.545455  1.600000e+01 -4.399699e+00 1.454545e+00
3          2 1.545455 1.859163 -4.399699e+00 -2.292151e+00 3.137087e-01
4          3 1.859163 2.200350 -2.292151e+00  1.252384e+00 3.411868e-01
5          4 2.200350 2.079799  1.252384e+00 -1.632926e-01 1.205509e-01
6          5 2.079799 2.093704 -1.632926e-01 -9.451895e-03 1.390506e-02
7          6 2.093704 2.094559 -9.451895e-03  7.903548e-05 8.543201e-04
8          7 2.094559 2.094551  7.903548e-05 -3.771081e-08 7.084470e-06
9          8 2.094551 2.094551 -3.771081e-08 -1.501022e-13 3.378656e-09
10         9 2.094551 2.094551 -1.501022e-13 -8.881784e-16 1.332268e-14

$x_roots
[1] 2.094551
# bisection
bis_res <- bisection(fx,xl=-3,xr=3)
bis_res
$all_result
   iteration    x_left  x_right    x_mid        f.xm.        error
1          0  0.000000 0.000000 0.000000  0.000000000 1.000000e+03
2          1 -3.000000 3.000000 0.000000 -5.000000000 6.000000e+00
3          2  0.000000 3.000000 1.500000 -4.625000000 3.000000e+00
4          3  1.500000 3.000000 2.250000  1.890625000 1.500000e+00
5          4  1.500000 2.250000 1.875000 -2.158203125 7.500000e-01
6          5  1.875000 2.250000 2.062500 -0.351318359 3.750000e-01
7          6  2.062500 2.250000 2.156250  0.712799072 1.875000e-01
8          7  2.062500 2.156250 2.109375  0.166835785 9.375000e-02
9          8  2.062500 2.109375 2.085938 -0.095678806 4.687500e-02
10         9  2.085938 2.109375 2.097656  0.034714282 2.343750e-02
11        10  2.085938 2.097656 2.091797 -0.030697711 1.171875e-02
12        11  2.091797 2.097656 2.094727  0.001954348 5.859375e-03
 [ reached 'max' / getOption("max.print") -- omitted 16 rows ]

$x_roots
[1] 2.094551
  1. Membuat animasi untuk metode newton-raphson dan bisection dengan bantuan package gganimate

Memanggil pacakge yang dibutuhkan

library(tidyverse)
library(gganimate)

Untuk membuat animasi dengan gganimate, terlebih dahulu kita membuat plot dengan ggplot2

Animasi Newton Raphson

#menyimpan hasil newton rapshon kedalam objek baru
nr_data <- nr_res$all_result %>% 
# convert iteration ke dalam bentuk faktor untuk keperluan animasi
  mutate(iteration=as.factor(iteration))

#membuat plot dengan ggplot2 
p_nr <- ggplot(data=nr_data)+
  # membuat grafik fungsi
  stat_function(aes(x=seq(-3,
                          3,
                          length.out=nrow(nr_data)
                          )
                    ),
                    fun=fx ,#masukan fungsi
                    color="steelblue",
                    size=1.25 # mengatur tebal kurva
                    )+
  geom_hline(yintercept = 0) + # membuat sumbu y
  geom_vline(xintercept = 0)+ # membuat sumbu x
  # membuat titik untuk setiap x_new
  geom_point(aes(x=x_new, 
                 y=fx(x_new))
             )+
  # membuat text untuk setiap x_new
  geom_text(aes(x=x_new,
                y=fx(x_new),
                # memberi text pada setiap titik
                label=str_c("Iteration ",
                            iteration)
                      ),
            # mengatur tulisan agar jauh dari titik
            nudge_y = 4
            )+
  xlab("x")+ # merubah nama pada sumbu x
  ylab("f(x)")+ # merubah nama pada sumbu y
  theme_bw()+
  # membuat animasi dengan gganimate
  # animasi didasarkan pada kolom iteration
  transition_states(iteration,
                   transition_length=3,
                   state_length =3,
                   wrap=F)

Jika ingin menampilkan langsung di RStudio bisa menjalankan sintaks dibawah

animate(p_nr,nframes = 200,fps=5)

Jika ingin menyimpan hasilnya dalam bentuk .gif gunakan sintaks dibawah ini.

#anim_save("nr_anim.gif",animate(p_nr,nframes = 200,fps=5))

Animasi Bisection

#menyimpan hasil newton rapshon kedalam objek baru
#bs_data <- bis_res$all_result %>% mutate(iteration=as.factor(iteration))

#membuat plot dengan ggplot2 
#p_bis <- ggplot(data=bs_data)+
  
  # membuat grafik fungsi
#  stat_function(aes(x=seq(-3,
#                          3,
#                          length.out=nrow(bs_data)
#                          )
#                    ),
#                    fun=fx,#masukan fungsi
#                    color="steelblue",
#                    size=1.25 # mengatur tebal kurva
#                    )+
#  geom_hline(yintercept = 0) + # membuat sumbu y
#  geom_vline(xintercept = 0)+ # membuat sumbu x
#  # membuat titik untuk setiap x_left
#  geom_point(aes(x=x_left,
#                 y=fx(x_left)),
#             color="red"
#             )+
  # membuat titik untuk setiap x_right
#  geom_point(aes(x=x_right,
#                 y=fx(x_right)),
#             color="green"
#             )+
  # membuat titik untuk setiap x_mid
#geom_point(aes(x=x_mid,
#                 y=fx(x_mid)),
#             color="black"
#             )+
#  # membuat text untuk setiap x_left
#  geom_text(aes(x=x_left,
#                 y=fx(x_left),
#                label=str_c("Iteration ",
#                            iteration)
#                      ),
#            nudge_y = 2,
#            color="red"
#            )+
#  # membuat text untuk setiap x_right
#   geom_text(aes(x=x_right,
#                 y=fx(x_right),
#                label=str_c("Iteration ",
#                            iteration)
#                      ),
#            nudge_y = 2,
#            color="green"
#            )+
#  # membuat text untuk setiap x_mid
#   geom_text(aes(x=x_mid,
#                 y=fx(x_mid),
#                label=str_c("Iteration ",
#                            iteration)
#                      ),
#            nudge_y = 2,
#            color="black"
#            )+
###  xlab("x")+
#  ylab("f(x)")+
#  theme_bw()+
  # membuat animasi dengan gganimate
  # animasi didasarkan pada kolom iteration
#  transition_states(iteration,
#                   transition_length=3,
#                   state_length =3,
#                   wrap=F)

#anim_save("bis_anim.gif",animate(p_bis,nframes = 200,fps=5))

BAB 10

library(pracma)

Metode Integral Numerik : Berikut adalah user-defined function dari metode-metode Integral Numerik

10.1 Metode Trapezoidal

trapezoid <- function(ftn, a, b, n = 100) {
     h <- (b-a)/n
     x.vec <- seq(a, b, by = h)
     f.vec <- sapply(x.vec, ftn)     # ftn(x.vec)
     Trap <- h*(f.vec[1]/2 + sum(f.vec[2:n]) + f.vec[n+1]/2)
     return(Trap)
}

10.2 Metode Simpson

simpson_n <- function(ftn, a, b, n = 100) {
    n <- max(c(2*(n %/% 2), 4))
    h <- (b-a)/n
    x.vec1 <- seq(a+h, b-h, by = 2*h)       # ganjil
    x.vec2 <- seq(a+2*h, b-2*h, by = 2*h)   # genap
    f.vec1 <- sapply(x.vec1, ftn)   # ganjil
    f.vec2 <- sapply(x.vec2, ftn)   # genap
    S <- h/3*(ftn(a) + ftn(b) + 4*sum(f.vec1) + 2*sum(f.vec2))
    return(S)
}

10.3 Metode Gauss Quadrature

# untuk n=2
gaussLegendre(n=2,a=-1,b=1)
$x
[1] -0.5773503  0.5773503

$w
[1] 1 1
# untuk n=3
gaussLegendre(n=3,a=-1,b=1)
$x
[1] -7.745967e-01  8.881784e-16  7.745967e-01

$w
[1] 0.5555556 0.8888889 0.5555556
# untuk n=4
gaussLegendre(n=4,a=-1,b=1)
$x
[1] -0.8611363 -0.3399810  0.3399810  0.8611363

$w
[1] 0.3478548 0.6521452 0.6521452 0.3478548
# untuk n=5
gaussLegendre(n=5,a=-1,b=1)
$x
[1] -9.061798e-01 -5.384693e-01  5.551115e-16  5.384693e-01  9.061798e-01

$w
[1] 0.2369269 0.4786287 0.5688889 0.4786287 0.2369269
# untuk n=6
gaussLegendre(n=6,a=-1,b=1)
$x
[1] -0.9324695 -0.6612094 -0.2386192  0.2386192  0.6612094  0.9324695

$w
[1] 0.1713245 0.3607616 0.4679139 0.4679139 0.3607616 0.1713245
# untuk n=7
gaussLegendre(n=7,a=-1,b=1)
$x
[1] -9.491079e-01 -7.415312e-01 -4.058452e-01  9.992007e-16  4.058452e-01
[6]  7.415312e-01  9.491079e-01

$w
[1] 0.1294850 0.2797054 0.3818301 0.4179592 0.3818301 0.2797054 0.1294850

10.4 Metode Integral Monte Carlo

mc_integral <- function(ftn, a, b,m=1000){
  #Membangkitkan x berdistribusi U(a,b)
  x <- runif(m,a,b)
  # Menghitung rata-rata dari output fungsi
  Gx <- ftn(x)
  Gx_m <- mean(Gx)
  theta.hat <- (b-a)*Gx_m
  return(theta.hat)
}

10.5 Integral numerik dengan package di R

Selain user-defined function diatas terdapat beberapa fungsi yang bisa langsung digunakan, yaitu

  1. Metode Trapezoidal menggunakan fungsi trapzfun dari package pracma

  2. Metode Simpson belum ada fungsi secara khusus

  3. Metode Adaptive Quadrature menggunakan fungsi integrate

  4. Metode Monte Carlo belum ada fungsi secara khusus.

Soal 1:

  1. Hitunglah menggunakan R dengan user-defined function

mendefinisikan fungsi f(x)

f <- function(x){
  1/x
}

Menghitung integral menggunakan fungsi trapezoid

trapezoid(f,1,5,n = 4)
[1] 1.683333
  1. Hitunglah menggunakan R fungsi trapzfun dari package pracma
trapzfun(f,1,5,maxit =  4)
$value
[1] 1.614406

$iter
[1] 4

$rel.err
[1] 0.01456193
  1. Hitunglah menggunakan R hingga hasil integral mendekati hasil exact-nya dengan toleransi 0.0005
exact_value=1.609
tol <-  0.0005
err <- 1
n = 4

while(err>tol){
  res_trap <- trapezoid(f,1,5,n = n)
  
  err <- abs(res_trap-exact_value)
  
  cat("n=",n,", result=",res_trap,", error=",err,"\n",sep = "")
  
  n=n+1
  if(n==1000){
    break
  }
  
}
n=4, result=1.683333, error=0.07433333
n=5, result=1.657907, error=0.04890706
n=6, result=1.643601, error=0.03460084
n=7, result=1.63478, error=0.02577994
n=8, result=1.628968, error=0.01996825
n=9, result=1.624942, error=0.01594152
n=10, result=1.622039, error=0.01303901
n=11, result=1.619879, error=0.01087908
n=12, result=1.618229, error=0.009228993
n=13, result=1.61694, error=0.007940381
n=14, result=1.615915, error=0.006915077
n=15, result=1.615086, error=0.006086061
n=16, result=1.614406, error=0.005406324
n=17, result=1.613842, error=0.004842114
n=18, result=1.613369, error=0.004368695
n=19, result=1.612968, error=0.003967606
n=20, result=1.612625, error=0.003624844
n=21, result=1.61233, error=0.003329638
n=22, result=1.612074, error=0.003073587
n=23, result=1.61185, error=0.002850067
n=24, result=1.611654, error=0.002653798
n=25, result=1.611481, error=0.002480525
n=26, result=1.611327, error=0.002326794
n=27, result=1.61119, error=0.002189776
n=28, result=1.611067, error=0.002067133
n=29, result=1.610957, error=0.001956925
n=30, result=1.610858, error=0.001857527
n=31, result=1.610768, error=0.00176757
n=32, result=1.610686, error=0.001685896
n=33, result=1.610612, error=0.001611519
n=34, result=1.610544, error=0.001543595
n=35, result=1.610481, error=0.0014814
n=36, result=1.610424, error=0.001424306
n=37, result=1.610372, error=0.001371771
n=38, result=1.610323, error=0.001323323
n=39, result=1.610279, error=0.001278548
n=40, result=1.610237, error=0.001237084
n=41, result=1.610199, error=0.001198614
n=42, result=1.610163, error=0.001162854
n=43, result=1.61013, error=0.001129558
n=44, result=1.610099, error=0.001098503
n=45, result=1.610069, error=0.001069494
n=46, result=1.610042, error=0.001042353
n=47, result=1.610017, error=0.001016925
n=48, result=1.609993, error=0.0009930681
n=49, result=1.609971, error=0.0009706553
n=50, result=1.60995, error=0.0009495727
n=51, result=1.60993, error=0.0009297169
n=52, result=1.609911, error=0.0009109947
n=53, result=1.609893, error=0.0008933214
n=54, result=1.609877, error=0.0008766201
n=55, result=1.609861, error=0.0008608208
n=56, result=1.609846, error=0.0008458596
n=57, result=1.609832, error=0.0008316785
n=58, result=1.609818, error=0.0008182241
n=59, result=1.609805, error=0.0008054475
n=60, result=1.609793, error=0.000793304
n=61, result=1.609782, error=0.0007817525
n=62, result=1.609771, error=0.000770755
n=63, result=1.60976, error=0.0007602769
n=64, result=1.60975, error=0.0007502857
n=65, result=1.609741, error=0.0007407519
n=66, result=1.609732, error=0.0007316479
n=67, result=1.609723, error=0.0007229484
n=68, result=1.609715, error=0.0007146296
n=69, result=1.609707, error=0.0007066697
n=70, result=1.609699, error=0.0006990484
n=71, result=1.609692, error=0.0006917466
n=72, result=1.609685, error=0.0006847469
n=73, result=1.609678, error=0.0006780327
n=74, result=1.609672, error=0.0006715888
n=75, result=1.609665, error=0.0006654008
n=76, result=1.609659, error=0.0006594553
n=77, result=1.609654, error=0.0006537399
n=78, result=1.609648, error=0.0006482429
n=79, result=1.609643, error=0.0006429532
n=80, result=1.609638, error=0.0006378605
n=81, result=1.609633, error=0.0006329552
n=82, result=1.609628, error=0.0006282283
n=83, result=1.609624, error=0.0006236711
n=84, result=1.609619, error=0.0006192756
n=85, result=1.609615, error=0.0006150343
n=86, result=1.609611, error=0.0006109401
n=87, result=1.609607, error=0.0006069861
n=88, result=1.609603, error=0.0006031662
n=89, result=1.609599, error=0.0005994743
n=90, result=1.609596, error=0.0005959047
n=91, result=1.609592, error=0.0005924521
n=92, result=1.609589, error=0.0005891115
n=93, result=1.609586, error=0.000585878
n=94, result=1.609583, error=0.0005827471
n=95, result=1.60958, error=0.0005797146
n=96, result=1.609577, error=0.0005767763
n=97, result=1.609574, error=0.0005739284
n=98, result=1.609571, error=0.0005711672
n=99, result=1.609568, error=0.0005684892
n=100, result=1.609566, error=0.0005658912
n=101, result=1.609563, error=0.0005633699
n=102, result=1.609561, error=0.0005609224
n=103, result=1.609559, error=0.0005585458
n=104, result=1.609556, error=0.0005562374
n=105, result=1.609554, error=0.0005539947
n=106, result=1.609552, error=0.0005518151
n=107, result=1.60955, error=0.0005496964
n=108, result=1.609548, error=0.0005476362
n=109, result=1.609546, error=0.0005456324
n=110, result=1.609544, error=0.000543683
n=111, result=1.609542, error=0.0005417861
n=112, result=1.60954, error=0.0005399397
n=113, result=1.609538, error=0.0005381422
n=114, result=1.609536, error=0.0005363917
n=115, result=1.609535, error=0.0005346867
n=116, result=1.609533, error=0.0005330255
n=117, result=1.609531, error=0.0005314068
n=118, result=1.60953, error=0.0005298291
n=119, result=1.609528, error=0.0005282909
n=120, result=1.609527, error=0.0005267911
n=121, result=1.609525, error=0.0005253282
n=122, result=1.609524, error=0.0005239012
n=123, result=1.609523, error=0.0005225089
n=124, result=1.609521, error=0.00052115
n=125, result=1.60952, error=0.0005198237
n=126, result=1.609519, error=0.0005185288
n=127, result=1.609517, error=0.0005172644
n=128, result=1.609516, error=0.0005160295
n=129, result=1.609515, error=0.0005148232
n=130, result=1.609514, error=0.0005136446
n=131, result=1.609512, error=0.0005124929
n=132, result=1.609511, error=0.0005113673
n=133, result=1.60951, error=0.000510267
n=134, result=1.609509, error=0.0005091912
n=135, result=1.609508, error=0.0005081392
n=136, result=1.609507, error=0.0005071104
n=137, result=1.609506, error=0.000506104
n=138, result=1.609505, error=0.0005051193
n=139, result=1.609504, error=0.0005041559
n=140, result=1.609503, error=0.000503213
n=141, result=1.609502, error=0.0005022901
n=142, result=1.609501, error=0.0005013867
n=143, result=1.609501, error=0.0005005021
n=144, result=1.6095, error=0.0004996359

Soal 2 :

  1. Hitunglah menggunakan R dengan user-defined function

mendefinisikan fungsi f(x)

f2 <- function(x){
  3^{x}
}

Menghitung integral menggunakan metode simpson

simpson_n(f2,-2,2,n = 4)
[1] 8.148148
  1. Hitunglah menggunakan R fungsi trapzfun dari package pracma
trapzfun(f,1,5,maxit =  4)
$value
[1] 1.614406

$iter
[1] 4

$rel.err
[1] 0.01456193
  1. Hitunglah menggunakan R hingga hasil integral mendekati hasil exact-nya dengan toleransi 0.0001
exact_value=8.091
tol <-  0.0001
err <- 1
n = 4

while(err>tol){
  res_simp <- simpson_n(f2,-2,2,n = n)
  
  err <- abs(res_simp-exact_value)
  
  cat("n=",n,", result=",res_simp,", error=",err,"\n",sep = "")
  
  n=n+1
  if(n==1000){
    break
  }
  
}
n=4, result=8.148148, error=0.05714815
n=5, result=8.148148, error=0.05714815
n=6, result=8.103168, error=0.01216778
n=7, result=8.103168, error=0.01216778
n=8, result=8.094965, error=0.003965356
n=9, result=8.094965, error=0.003965356
n=10, result=8.092654, error=0.001653864
n=11, result=8.092654, error=0.001653864
n=12, result=8.091811, error=0.0008110155
n=13, result=8.091811, error=0.0008110155
n=14, result=8.091447, error=0.0004466333
n=15, result=8.091447, error=0.0004466333
n=16, result=8.091269, error=0.0002688499
n=17, result=8.091269, error=0.0002688499
n=18, result=8.091174, error=0.0001739047
n=19, result=8.091174, error=0.0001739047
n=20, result=8.09112, error=0.0001195166
n=21, result=8.09112, error=0.0001195166
n=22, result=8.091087, error=8.656722e-05

Soal 3:

#gt::gt(data = bobot_gc[3,])

  1. Hitunglah menggunakan R dengan fungsi gaussLegendre dengan menggunakan domain [−1,1][−1,1]

mendefinisikan fungsi hasil transformasi f(t)

ft <- function(t){
  (3/2)*exp((-(3/2*(t+1))^2))
}

Legendre order 4

gL <- gaussLegendre(n = 4,a = -1,1)

mendefinisikan koefisien dan gauss point

Ci <- gL$w # koefisien
Ci
[1] 0.3478548 0.6521452 0.6521452 0.3478548
xi <- gL$x # gauss point
xi
[1] -0.8611363 -0.3399810  0.3399810  0.8611363

Menghitung integral

I <- sum(Ci * ft(xi))
I
[1] 0.8841359
  1. Hitunglah menggunakan R dengan fungsi gaussLegendre dengan menggunakan domain asal

mendefinisikan fungsi hasil transformasi f(x)

f3 <- function(x){
  exp(-(x^2))
}

Legendre order 4 dengan domain [0,3]

gL <- gaussLegendre(n = 4,a = 0,3)

mendefinisikan koefisien dan gauss point

Ci <- gL$w # koefisien
Ci
[1] 0.5217823 0.9782177 0.9782177 0.5217823
xi <- gL$x # gauss point
xi
[1] 0.2082955 0.9900284 2.0099716 2.7917045

Menghitung integral

I <- sum(Ci * f3(xi))
I
[1] 0.8841359
  1. Hitunglah menggunakan R hingga hasil integral mendekati hasil exact-nya dengan toleransi 0.00001
exact_value=0.886207
tol <-  0.00001
err <- 1
n = 4

while(err>tol){
  
  gL <- gaussLegendre(n = n,a = 0,3)

 Ci <- gL$w # koefisien
 xi <- gL$x # gauss point
  
  res_gl <- sum(Ci * f3(xi))

  err <- abs(res_gl-exact_value)
  
  cat("n=",n,", result=",res_gl,", error=",err,"\n",sep = "")
  
  n=n+1
  if(n==1000){
    break
  }
  
}
n=4, result=0.8841359, error=0.00207107
n=5, result=0.8865292, error=0.0003221738
n=6, result=0.8861828, error=2.416802e-05
n=7, result=0.8862082, error=1.22274e-06

Soal 4:

g1 <- function(s) {
  (1/(5*sqrt(2*pi)))*exp(-(1/2)*(((1/s)-30)/5)^(2))*(1/(s^2))
}
g2 <- function(x) {
  (1/(5*sqrt(2*pi)))*exp(-(1/2)*((x-30)/5)^(2))
}
set.seed(123)
int_g1 <- mc_integral(g1,a=-1,b=0,m = 1000)
int_g1
[1] 2.841771e-10
set.seed(123)
int_g2 <- mc_integral(g2,a=-1,b=32,m = 1000)
int_g2
[1] 0.6437677
int_g <- int_g1 + int_g2
int_g
[1] 0.6437677

jadi nilai cdf dari N(30,5) untuk x=32 adalah F(x=32|30,5)≈0.6437677

10.6 Tugas

Soal 1:

Jawaban A:

Jawaban B:

library(pracma)
a = 5
b = 3
n = 4
exact_value = 0.886207
tol <-  0.0001
err <- 1
f = function(x) {
  x*a*b*(x^a-1)*(1-x^a)^b-1  
} 
#### trapezoida ####
xs = seq(0, 1, length.out = 101)
ys = f(xs)
trapezoid <- function(ftn, a, b, n = 100) {
     h <- (b-a)/n
     x.vec <- seq(a, b, by = h)
     f.vec <- sapply(x.vec, ftn)     # ftn(x.vec)
     Trap <- h*(f.vec[1]/2 + sum(f.vec[2:n]) + f.vec[n+1]/2)
     return(Trap)
}
while(err>tol){
  res_trap <- trapezoid(f,a,b,n = n)
  err <- abs(res_trap-exact_value)
  cat("n=",n,", result=",res_trap,", error=",err,"\n",sep = "")
  n=n+1
  if(n==1000){
    break
  }
}
n=4, result=2.211194e+15, error=2.211194e+15
n=5, result=2.007511e+15, error=2.007511e+15
n=6, result=1.893165e+15, error=1.893165e+15
n=7, result=1.822897e+15, error=1.822897e+15
n=8, result=1.776742e+15, error=1.776742e+15
n=9, result=1.744845e+15, error=1.744845e+15
n=10, result=1.721902e+15, error=1.721902e+15
n=11, result=1.704857e+15, error=1.704857e+15
n=12, result=1.691853e+15, error=1.691853e+15
n=13, result=1.681709e+15, error=1.681709e+15
n=14, result=1.673645e+15, error=1.673645e+15
n=15, result=1.66713e+15, error=1.66713e+15
n=16, result=1.661791e+15, error=1.661791e+15
n=17, result=1.657362e+15, error=1.657362e+15
n=18, result=1.653648e+15, error=1.653648e+15
n=19, result=1.650502e+15, error=1.650502e+15
n=20, result=1.647815e+15, error=1.647815e+15
n=21, result=1.645501e+15, error=1.645501e+15
n=22, result=1.643494e+15, error=1.643494e+15
n=23, result=1.641743e+15, error=1.641743e+15
n=24, result=1.640206e+15, error=1.640206e+15
n=25, result=1.638849e+15, error=1.638849e+15
n=26, result=1.637645e+15, error=1.637645e+15
n=27, result=1.636572e+15, error=1.636572e+15
n=28, result=1.635612e+15, error=1.635612e+15
n=29, result=1.63475e+15, error=1.63475e+15
n=30, result=1.633972e+15, error=1.633972e+15
n=31, result=1.633268e+15, error=1.633268e+15
n=32, result=1.632629e+15, error=1.632629e+15
n=33, result=1.632047e+15, error=1.632047e+15
n=34, result=1.631515e+15, error=1.631515e+15
n=35, result=1.631029e+15, error=1.631029e+15
n=36, result=1.630582e+15, error=1.630582e+15
n=37, result=1.630171e+15, error=1.630171e+15
n=38, result=1.629792e+15, error=1.629792e+15
n=39, result=1.629442e+15, error=1.629442e+15
n=40, result=1.629118e+15, error=1.629118e+15
n=41, result=1.628817e+15, error=1.628817e+15
n=42, result=1.628537e+15, error=1.628537e+15
n=43, result=1.628277e+15, error=1.628277e+15
n=44, result=1.628034e+15, error=1.628034e+15
n=45, result=1.627807e+15, error=1.627807e+15
n=46, result=1.627595e+15, error=1.627595e+15
n=47, result=1.627396e+15, error=1.627396e+15
n=48, result=1.627209e+15, error=1.627209e+15
n=49, result=1.627034e+15, error=1.627034e+15
n=50, result=1.626869e+15, error=1.626869e+15
n=51, result=1.626714e+15, error=1.626714e+15
n=52, result=1.626567e+15, error=1.626567e+15
n=53, result=1.626429e+15, error=1.626429e+15
n=54, result=1.626299e+15, error=1.626299e+15
n=55, result=1.626175e+15, error=1.626175e+15
n=56, result=1.626058e+15, error=1.626058e+15
n=57, result=1.625947e+15, error=1.625947e+15
n=58, result=1.625842e+15, error=1.625842e+15
n=59, result=1.625742e+15, error=1.625742e+15
n=60, result=1.625647e+15, error=1.625647e+15
n=61, result=1.625557e+15, error=1.625557e+15
n=62, result=1.625471e+15, error=1.625471e+15
n=63, result=1.625389e+15, error=1.625389e+15
n=64, result=1.625311e+15, error=1.625311e+15
n=65, result=1.625236e+15, error=1.625236e+15
n=66, result=1.625165e+15, error=1.625165e+15
n=67, result=1.625097e+15, error=1.625097e+15
n=68, result=1.625032e+15, error=1.625032e+15
n=69, result=1.62497e+15, error=1.62497e+15
n=70, result=1.62491e+15, error=1.62491e+15
n=71, result=1.624853e+15, error=1.624853e+15
n=72, result=1.624799e+15, error=1.624799e+15
n=73, result=1.624746e+15, error=1.624746e+15
n=74, result=1.624696e+15, error=1.624696e+15
n=75, result=1.624647e+15, error=1.624647e+15
n=76, result=1.624601e+15, error=1.624601e+15
n=77, result=1.624556e+15, error=1.624556e+15
n=78, result=1.624513e+15, error=1.624513e+15
n=79, result=1.624472e+15, error=1.624472e+15
n=80, result=1.624432e+15, error=1.624432e+15
n=81, result=1.624394e+15, error=1.624394e+15
n=82, result=1.624357e+15, error=1.624357e+15
n=83, result=1.624321e+15, error=1.624321e+15
n=84, result=1.624287e+15, error=1.624287e+15
n=85, result=1.624254e+15, error=1.624254e+15
n=86, result=1.624222e+15, error=1.624222e+15
n=87, result=1.624191e+15, error=1.624191e+15
n=88, result=1.624161e+15, error=1.624161e+15
n=89, result=1.624132e+15, error=1.624132e+15
n=90, result=1.624104e+15, error=1.624104e+15
n=91, result=1.624077e+15, error=1.624077e+15
n=92, result=1.624051e+15, error=1.624051e+15
n=93, result=1.624026e+15, error=1.624026e+15
n=94, result=1.624001e+15, error=1.624001e+15
n=95, result=1.623978e+15, error=1.623978e+15
n=96, result=1.623955e+15, error=1.623955e+15
n=97, result=1.623932e+15, error=1.623932e+15
n=98, result=1.623911e+15, error=1.623911e+15
n=99, result=1.62389e+15, error=1.62389e+15
n=100, result=1.62387e+15, error=1.62387e+15
n=101, result=1.62385e+15, error=1.62385e+15
n=102, result=1.623831e+15, error=1.623831e+15
n=103, result=1.623812e+15, error=1.623812e+15
n=104, result=1.623794e+15, error=1.623794e+15
n=105, result=1.623777e+15, error=1.623777e+15
n=106, result=1.62376e+15, error=1.62376e+15
n=107, result=1.623743e+15, error=1.623743e+15
n=108, result=1.623727e+15, error=1.623727e+15
n=109, result=1.623711e+15, error=1.623711e+15
n=110, result=1.623696e+15, error=1.623696e+15
n=111, result=1.623681e+15, error=1.623681e+15
n=112, result=1.623667e+15, error=1.623667e+15
n=113, result=1.623653e+15, error=1.623653e+15
n=114, result=1.623639e+15, error=1.623639e+15
n=115, result=1.623626e+15, error=1.623626e+15
n=116, result=1.623613e+15, error=1.623613e+15
n=117, result=1.6236e+15, error=1.6236e+15
n=118, result=1.623588e+15, error=1.623588e+15
n=119, result=1.623576e+15, error=1.623576e+15
n=120, result=1.623564e+15, error=1.623564e+15
n=121, result=1.623553e+15, error=1.623553e+15
n=122, result=1.623541e+15, error=1.623541e+15
n=123, result=1.623531e+15, error=1.623531e+15
n=124, result=1.62352e+15, error=1.62352e+15
n=125, result=1.62351e+15, error=1.62351e+15
n=126, result=1.623499e+15, error=1.623499e+15
n=127, result=1.62349e+15, error=1.62349e+15
n=128, result=1.62348e+15, error=1.62348e+15
n=129, result=1.62347e+15, error=1.62347e+15
n=130, result=1.623461e+15, error=1.623461e+15
n=131, result=1.623452e+15, error=1.623452e+15
n=132, result=1.623443e+15, error=1.623443e+15
n=133, result=1.623435e+15, error=1.623435e+15
n=134, result=1.623426e+15, error=1.623426e+15
n=135, result=1.623418e+15, error=1.623418e+15
n=136, result=1.62341e+15, error=1.62341e+15
n=137, result=1.623402e+15, error=1.623402e+15
n=138, result=1.623395e+15, error=1.623395e+15
n=139, result=1.623387e+15, error=1.623387e+15
n=140, result=1.62338e+15, error=1.62338e+15
n=141, result=1.623373e+15, error=1.623373e+15
n=142, result=1.623365e+15, error=1.623365e+15
n=143, result=1.623359e+15, error=1.623359e+15
n=144, result=1.623352e+15, error=1.623352e+15
n=145, result=1.623345e+15, error=1.623345e+15
n=146, result=1.623339e+15, error=1.623339e+15
n=147, result=1.623332e+15, error=1.623332e+15
n=148, result=1.623326e+15, error=1.623326e+15
n=149, result=1.62332e+15, error=1.62332e+15
n=150, result=1.623314e+15, error=1.623314e+15
n=151, result=1.623308e+15, error=1.623308e+15
n=152, result=1.623302e+15, error=1.623302e+15
n=153, result=1.623297e+15, error=1.623297e+15
n=154, result=1.623291e+15, error=1.623291e+15
n=155, result=1.623286e+15, error=1.623286e+15
n=156, result=1.62328e+15, error=1.62328e+15
n=157, result=1.623275e+15, error=1.623275e+15
n=158, result=1.62327e+15, error=1.62327e+15
n=159, result=1.623265e+15, error=1.623265e+15
n=160, result=1.62326e+15, error=1.62326e+15
n=161, result=1.623255e+15, error=1.623255e+15
n=162, result=1.623251e+15, error=1.623251e+15
n=163, result=1.623246e+15, error=1.623246e+15
n=164, result=1.623241e+15, error=1.623241e+15
n=165, result=1.623237e+15, error=1.623237e+15
n=166, result=1.623232e+15, error=1.623232e+15
n=167, result=1.623228e+15, error=1.623228e+15
n=168, result=1.623224e+15, error=1.623224e+15
n=169, result=1.62322e+15, error=1.62322e+15
n=170, result=1.623216e+15, error=1.623216e+15
n=171, result=1.623211e+15, error=1.623211e+15
n=172, result=1.623208e+15, error=1.623208e+15
n=173, result=1.623204e+15, error=1.623204e+15
n=174, result=1.6232e+15, error=1.6232e+15
n=175, result=1.623196e+15, error=1.623196e+15
n=176, result=1.623192e+15, error=1.623192e+15
n=177, result=1.623189e+15, error=1.623189e+15
n=178, result=1.623185e+15, error=1.623185e+15
n=179, result=1.623182e+15, error=1.623182e+15
n=180, result=1.623178e+15, error=1.623178e+15
n=181, result=1.623175e+15, error=1.623175e+15
n=182, result=1.623171e+15, error=1.623171e+15
n=183, result=1.623168e+15, error=1.623168e+15
n=184, result=1.623165e+15, error=1.623165e+15
n=185, result=1.623162e+15, error=1.623162e+15
n=186, result=1.623159e+15, error=1.623159e+15
n=187, result=1.623155e+15, error=1.623155e+15
n=188, result=1.623152e+15, error=1.623152e+15
n=189, result=1.623149e+15, error=1.623149e+15
n=190, result=1.623146e+15, error=1.623146e+15
n=191, result=1.623144e+15, error=1.623144e+15
n=192, result=1.623141e+15, error=1.623141e+15
n=193, result=1.623138e+15, error=1.623138e+15
n=194, result=1.623135e+15, error=1.623135e+15
n=195, result=1.623132e+15, error=1.623132e+15
n=196, result=1.62313e+15, error=1.62313e+15
n=197, result=1.623127e+15, error=1.623127e+15
n=198, result=1.623125e+15, error=1.623125e+15
n=199, result=1.623122e+15, error=1.623122e+15
n=200, result=1.623119e+15, error=1.623119e+15
n=201, result=1.623117e+15, error=1.623117e+15
n=202, result=1.623115e+15, error=1.623115e+15
n=203, result=1.623112e+15, error=1.623112e+15
n=204, result=1.62311e+15, error=1.62311e+15
n=205, result=1.623107e+15, error=1.623107e+15
n=206, result=1.623105e+15, error=1.623105e+15
n=207, result=1.623103e+15, error=1.623103e+15
n=208, result=1.623101e+15, error=1.623101e+15
n=209, result=1.623098e+15, error=1.623098e+15
n=210, result=1.623096e+15, error=1.623096e+15
n=211, result=1.623094e+15, error=1.623094e+15
n=212, result=1.623092e+15, error=1.623092e+15
n=213, result=1.62309e+15, error=1.62309e+15
n=214, result=1.623088e+15, error=1.623088e+15
n=215, result=1.623086e+15, error=1.623086e+15
n=216, result=1.623084e+15, error=1.623084e+15
n=217, result=1.623082e+15, error=1.623082e+15
n=218, result=1.62308e+15, error=1.62308e+15
n=219, result=1.623078e+15, error=1.623078e+15
n=220, result=1.623076e+15, error=1.623076e+15
n=221, result=1.623074e+15, error=1.623074e+15
n=222, result=1.623072e+15, error=1.623072e+15
n=223, result=1.623071e+15, error=1.623071e+15
n=224, result=1.623069e+15, error=1.623069e+15
n=225, result=1.623067e+15, error=1.623067e+15
n=226, result=1.623065e+15, error=1.623065e+15
n=227, result=1.623064e+15, error=1.623064e+15
n=228, result=1.623062e+15, error=1.623062e+15
n=229, result=1.62306e+15, error=1.62306e+15
n=230, result=1.623058e+15, error=1.623058e+15
n=231, result=1.623057e+15, error=1.623057e+15
n=232, result=1.623055e+15, error=1.623055e+15
n=233, result=1.623054e+15, error=1.623054e+15
n=234, result=1.623052e+15, error=1.623052e+15
n=235, result=1.623051e+15, error=1.623051e+15
n=236, result=1.623049e+15, error=1.623049e+15
n=237, result=1.623047e+15, error=1.623047e+15
n=238, result=1.623046e+15, error=1.623046e+15
n=239, result=1.623045e+15, error=1.623045e+15
n=240, result=1.623043e+15, error=1.623043e+15
n=241, result=1.623042e+15, error=1.623042e+15
n=242, result=1.62304e+15, error=1.62304e+15
n=243, result=1.623039e+15, error=1.623039e+15
n=244, result=1.623037e+15, error=1.623037e+15
n=245, result=1.623036e+15, error=1.623036e+15
n=246, result=1.623035e+15, error=1.623035e+15
n=247, result=1.623033e+15, error=1.623033e+15
n=248, result=1.623032e+15, error=1.623032e+15
n=249, result=1.623031e+15, error=1.623031e+15
n=250, result=1.623029e+15, error=1.623029e+15
n=251, result=1.623028e+15, error=1.623028e+15
n=252, result=1.623027e+15, error=1.623027e+15
n=253, result=1.623026e+15, error=1.623026e+15
n=254, result=1.623024e+15, error=1.623024e+15
n=255, result=1.623023e+15, error=1.623023e+15
n=256, result=1.623022e+15, error=1.623022e+15
n=257, result=1.623021e+15, error=1.623021e+15
n=258, result=1.62302e+15, error=1.62302e+15
n=259, result=1.623019e+15, error=1.623019e+15
n=260, result=1.623017e+15, error=1.623017e+15
n=261, result=1.623016e+15, error=1.623016e+15
n=262, result=1.623015e+15, error=1.623015e+15
n=263, result=1.623014e+15, error=1.623014e+15
n=264, result=1.623013e+15, error=1.623013e+15
n=265, result=1.623012e+15, error=1.623012e+15
n=266, result=1.623011e+15, error=1.623011e+15
n=267, result=1.62301e+15, error=1.62301e+15
n=268, result=1.623009e+15, error=1.623009e+15
n=269, result=1.623008e+15, error=1.623008e+15
n=270, result=1.623007e+15, error=1.623007e+15
n=271, result=1.623006e+15, error=1.623006e+15
n=272, result=1.623005e+15, error=1.623005e+15
n=273, result=1.623004e+15, error=1.623004e+15
n=274, result=1.623003e+15, error=1.623003e+15
n=275, result=1.623002e+15, error=1.623002e+15
n=276, result=1.623001e+15, error=1.623001e+15
n=277, result=1.623e+15, error=1.623e+15
n=278, result=1.622999e+15, error=1.622999e+15
n=279, result=1.622998e+15, error=1.622998e+15
n=280, result=1.622997e+15, error=1.622997e+15
n=281, result=1.622996e+15, error=1.622996e+15
n=282, result=1.622995e+15, error=1.622995e+15
n=283, result=1.622994e+15, error=1.622994e+15
n=284, result=1.622993e+15, error=1.622993e+15
n=285, result=1.622993e+15, error=1.622993e+15
n=286, result=1.622992e+15, error=1.622992e+15
n=287, result=1.622991e+15, error=1.622991e+15
n=288, result=1.62299e+15, error=1.62299e+15
n=289, result=1.622989e+15, error=1.622989e+15
n=290, result=1.622988e+15, error=1.622988e+15
n=291, result=1.622988e+15, error=1.622988e+15
n=292, result=1.622987e+15, error=1.622987e+15
n=293, result=1.622986e+15, error=1.622986e+15
n=294, result=1.622985e+15, error=1.622985e+15
n=295, result=1.622984e+15, error=1.622984e+15
n=296, result=1.622984e+15, error=1.622984e+15
n=297, result=1.622983e+15, error=1.622983e+15
n=298, result=1.622982e+15, error=1.622982e+15
n=299, result=1.622981e+15, error=1.622981e+15
n=300, result=1.622981e+15, error=1.622981e+15
n=301, result=1.62298e+15, error=1.62298e+15
n=302, result=1.622979e+15, error=1.622979e+15
n=303, result=1.622978e+15, error=1.622978e+15
n=304, result=1.622978e+15, error=1.622978e+15
n=305, result=1.622977e+15, error=1.622977e+15
n=306, result=1.622976e+15, error=1.622976e+15
n=307, result=1.622976e+15, error=1.622976e+15
n=308, result=1.622975e+15, error=1.622975e+15
n=309, result=1.622974e+15, error=1.622974e+15
n=310, result=1.622973e+15, error=1.622973e+15
n=311, result=1.622973e+15, error=1.622973e+15
n=312, result=1.622972e+15, error=1.622972e+15
n=313, result=1.622971e+15, error=1.622971e+15
n=314, result=1.622971e+15, error=1.622971e+15
n=315, result=1.62297e+15, error=1.62297e+15
n=316, result=1.62297e+15, error=1.62297e+15
n=317, result=1.622969e+15, error=1.622969e+15
n=318, result=1.622968e+15, error=1.622968e+15
n=319, result=1.622968e+15, error=1.622968e+15
n=320, result=1.622967e+15, error=1.622967e+15
n=321, result=1.622966e+15, error=1.622966e+15
n=322, result=1.622966e+15, error=1.622966e+15
n=323, result=1.622965e+15, error=1.622965e+15
n=324, result=1.622965e+15, error=1.622965e+15
n=325, result=1.622964e+15, error=1.622964e+15
n=326, result=1.622964e+15, error=1.622964e+15
n=327, result=1.622963e+15, error=1.622963e+15
n=328, result=1.622962e+15, error=1.622962e+15
n=329, result=1.622962e+15, error=1.622962e+15
n=330, result=1.622961e+15, error=1.622961e+15
n=331, result=1.622961e+15, error=1.622961e+15
n=332, result=1.62296e+15, error=1.62296e+15
n=333, result=1.62296e+15, error=1.62296e+15
n=334, result=1.622959e+15, error=1.622959e+15
n=335, result=1.622959e+15, error=1.622959e+15
n=336, result=1.622958e+15, error=1.622958e+15
n=337, result=1.622957e+15, error=1.622957e+15
n=338, result=1.622957e+15, error=1.622957e+15
n=339, result=1.622956e+15, error=1.622956e+15
n=340, result=1.622956e+15, error=1.622956e+15
n=341, result=1.622955e+15, error=1.622955e+15
n=342, result=1.622955e+15, error=1.622955e+15
n=343, result=1.622954e+15, error=1.622954e+15
n=344, result=1.622954e+15, error=1.622954e+15
n=345, result=1.622953e+15, error=1.622953e+15
n=346, result=1.622953e+15, error=1.622953e+15
n=347, result=1.622952e+15, error=1.622952e+15
n=348, result=1.622952e+15, error=1.622952e+15
n=349, result=1.622952e+15, error=1.622952e+15
n=350, result=1.622951e+15, error=1.622951e+15
n=351, result=1.622951e+15, error=1.622951e+15
n=352, result=1.62295e+15, error=1.62295e+15
n=353, result=1.62295e+15, error=1.62295e+15
n=354, result=1.622949e+15, error=1.622949e+15
n=355, result=1.622949e+15, error=1.622949e+15
n=356, result=1.622948e+15, error=1.622948e+15
n=357, result=1.622948e+15, error=1.622948e+15
n=358, result=1.622947e+15, error=1.622947e+15
n=359, result=1.622947e+15, error=1.622947e+15
n=360, result=1.622947e+15, error=1.622947e+15
n=361, result=1.622946e+15, error=1.622946e+15
n=362, result=1.622946e+15, error=1.622946e+15
n=363, result=1.622945e+15, error=1.622945e+15
n=364, result=1.622945e+15, error=1.622945e+15
n=365, result=1.622944e+15, error=1.622944e+15
n=366, result=1.622944e+15, error=1.622944e+15
n=367, result=1.622944e+15, error=1.622944e+15
n=368, result=1.622943e+15, error=1.622943e+15
n=369, result=1.622943e+15, error=1.622943e+15
n=370, result=1.622942e+15, error=1.622942e+15
n=371, result=1.622942e+15, error=1.622942e+15
n=372, result=1.622942e+15, error=1.622942e+15
n=373, result=1.622941e+15, error=1.622941e+15
n=374, result=1.622941e+15, error=1.622941e+15
n=375, result=1.622941e+15, error=1.622941e+15
n=376, result=1.62294e+15, error=1.62294e+15
n=377, result=1.62294e+15, error=1.62294e+15
n=378, result=1.622939e+15, error=1.622939e+15
n=379, result=1.622939e+15, error=1.622939e+15
n=380, result=1.622939e+15, error=1.622939e+15
n=381, result=1.622938e+15, error=1.622938e+15
n=382, result=1.622938e+15, error=1.622938e+15
n=383, result=1.622938e+15, error=1.622938e+15
n=384, result=1.622937e+15, error=1.622937e+15
n=385, result=1.622937e+15, error=1.622937e+15
n=386, result=1.622937e+15, error=1.622937e+15
n=387, result=1.622936e+15, error=1.622936e+15
n=388, result=1.622936e+15, error=1.622936e+15
n=389, result=1.622935e+15, error=1.622935e+15
n=390, result=1.622935e+15, error=1.622935e+15
n=391, result=1.622935e+15, error=1.622935e+15
n=392, result=1.622934e+15, error=1.622934e+15
n=393, result=1.622934e+15, error=1.622934e+15
n=394, result=1.622934e+15, error=1.622934e+15
n=395, result=1.622933e+15, error=1.622933e+15
n=396, result=1.622933e+15, error=1.622933e+15
n=397, result=1.622933e+15, error=1.622933e+15
n=398, result=1.622933e+15, error=1.622933e+15
n=399, result=1.622932e+15, error=1.622932e+15
n=400, result=1.622932e+15, error=1.622932e+15
n=401, result=1.622932e+15, error=1.622932e+15
n=402, result=1.622931e+15, error=1.622931e+15
n=403, result=1.622931e+15, error=1.622931e+15
n=404, result=1.622931e+15, error=1.622931e+15
n=405, result=1.62293e+15, error=1.62293e+15
n=406, result=1.62293e+15, error=1.62293e+15
n=407, result=1.62293e+15, error=1.62293e+15
n=408, result=1.622929e+15, error=1.622929e+15
n=409, result=1.622929e+15, error=1.622929e+15
n=410, result=1.622929e+15, error=1.622929e+15
n=411, result=1.622929e+15, error=1.622929e+15
n=412, result=1.622928e+15, error=1.622928e+15
n=413, result=1.622928e+15, error=1.622928e+15
n=414, result=1.622928e+15, error=1.622928e+15
n=415, result=1.622927e+15, error=1.622927e+15
n=416, result=1.622927e+15, error=1.622927e+15
n=417, result=1.622927e+15, error=1.622927e+15
n=418, result=1.622927e+15, error=1.622927e+15
n=419, result=1.622926e+15, error=1.622926e+15
n=420, result=1.622926e+15, error=1.622926e+15
n=421, result=1.622926e+15, error=1.622926e+15
n=422, result=1.622926e+15, error=1.622926e+15
n=423, result=1.622925e+15, error=1.622925e+15
n=424, result=1.622925e+15, error=1.622925e+15
n=425, result=1.622925e+15, error=1.622925e+15
n=426, result=1.622925e+15, error=1.622925e+15
n=427, result=1.622924e+15, error=1.622924e+15
n=428, result=1.622924e+15, error=1.622924e+15
n=429, result=1.622924e+15, error=1.622924e+15
n=430, result=1.622923e+15, error=1.622923e+15
n=431, result=1.622923e+15, error=1.622923e+15
n=432, result=1.622923e+15, error=1.622923e+15
n=433, result=1.622923e+15, error=1.622923e+15
n=434, result=1.622922e+15, error=1.622922e+15
n=435, result=1.622922e+15, error=1.622922e+15
n=436, result=1.622922e+15, error=1.622922e+15
n=437, result=1.622922e+15, error=1.622922e+15
n=438, result=1.622922e+15, error=1.622922e+15
n=439, result=1.622921e+15, error=1.622921e+15
n=440, result=1.622921e+15, error=1.622921e+15
n=441, result=1.622921e+15, error=1.622921e+15
n=442, result=1.622921e+15, error=1.622921e+15
n=443, result=1.62292e+15, error=1.62292e+15
n=444, result=1.62292e+15, error=1.62292e+15
n=445, result=1.62292e+15, error=1.62292e+15
n=446, result=1.62292e+15, error=1.62292e+15
n=447, result=1.622919e+15, error=1.622919e+15
n=448, result=1.622919e+15, error=1.622919e+15
n=449, result=1.622919e+15, error=1.622919e+15
n=450, result=1.622919e+15, error=1.622919e+15
n=451, result=1.622919e+15, error=1.622919e+15
n=452, result=1.622918e+15, error=1.622918e+15
n=453, result=1.622918e+15, error=1.622918e+15
n=454, result=1.622918e+15, error=1.622918e+15
n=455, result=1.622918e+15, error=1.622918e+15
n=456, result=1.622917e+15, error=1.622917e+15
n=457, result=1.622917e+15, error=1.622917e+15
n=458, result=1.622917e+15, error=1.622917e+15
n=459, result=1.622917e+15, error=1.622917e+15
n=460, result=1.622917e+15, error=1.622917e+15
n=461, result=1.622916e+15, error=1.622916e+15
n=462, result=1.622916e+15, error=1.622916e+15
n=463, result=1.622916e+15, error=1.622916e+15
n=464, result=1.622916e+15, error=1.622916e+15
n=465, result=1.622916e+15, error=1.622916e+15
n=466, result=1.622915e+15, error=1.622915e+15
n=467, result=1.622915e+15, error=1.622915e+15
n=468, result=1.622915e+15, error=1.622915e+15
n=469, result=1.622915e+15, error=1.622915e+15
n=470, result=1.622915e+15, error=1.622915e+15
n=471, result=1.622914e+15, error=1.622914e+15
n=472, result=1.622914e+15, error=1.622914e+15
n=473, result=1.622914e+15, error=1.622914e+15
n=474, result=1.622914e+15, error=1.622914e+15
n=475, result=1.622914e+15, error=1.622914e+15
n=476, result=1.622914e+15, error=1.622914e+15
n=477, result=1.622913e+15, error=1.622913e+15
n=478, result=1.622913e+15, error=1.622913e+15
n=479, result=1.622913e+15, error=1.622913e+15
n=480, result=1.622913e+15, error=1.622913e+15
n=481, result=1.622913e+15, error=1.622913e+15
n=482, result=1.622912e+15, error=1.622912e+15
n=483, result=1.622912e+15, error=1.622912e+15
n=484, result=1.622912e+15, error=1.622912e+15
n=485, result=1.622912e+15, error=1.622912e+15
n=486, result=1.622912e+15, error=1.622912e+15
n=487, result=1.622912e+15, error=1.622912e+15
n=488, result=1.622911e+15, error=1.622911e+15
n=489, result=1.622911e+15, error=1.622911e+15
n=490, result=1.622911e+15, error=1.622911e+15
n=491, result=1.622911e+15, error=1.622911e+15
n=492, result=1.622911e+15, error=1.622911e+15
n=493, result=1.622911e+15, error=1.622911e+15
n=494, result=1.62291e+15, error=1.62291e+15
n=495, result=1.62291e+15, error=1.62291e+15
n=496, result=1.62291e+15, error=1.62291e+15
n=497, result=1.62291e+15, error=1.62291e+15
n=498, result=1.62291e+15, error=1.62291e+15
n=499, result=1.62291e+15, error=1.62291e+15
n=500, result=1.622909e+15, error=1.622909e+15
n=501, result=1.622909e+15, error=1.622909e+15
n=502, result=1.622909e+15, error=1.622909e+15
n=503, result=1.622909e+15, error=1.622909e+15
n=504, result=1.622909e+15, error=1.622909e+15
n=505, result=1.622909e+15, error=1.622909e+15
n=506, result=1.622908e+15, error=1.622908e+15
n=507, result=1.622908e+15, error=1.622908e+15
n=508, result=1.622908e+15, error=1.622908e+15
n=509, result=1.622908e+15, error=1.622908e+15
n=510, result=1.622908e+15, error=1.622908e+15
n=511, result=1.622908e+15, error=1.622908e+15
n=512, result=1.622908e+15, error=1.622908e+15
n=513, result=1.622907e+15, error=1.622907e+15
n=514, result=1.622907e+15, error=1.622907e+15
n=515, result=1.622907e+15, error=1.622907e+15
n=516, result=1.622907e+15, error=1.622907e+15
n=517, result=1.622907e+15, error=1.622907e+15
n=518, result=1.622907e+15, error=1.622907e+15
n=519, result=1.622907e+15, error=1.622907e+15
n=520, result=1.622906e+15, error=1.622906e+15
n=521, result=1.622906e+15, error=1.622906e+15
n=522, result=1.622906e+15, error=1.622906e+15
n=523, result=1.622906e+15, error=1.622906e+15
n=524, result=1.622906e+15, error=1.622906e+15
n=525, result=1.622906e+15, error=1.622906e+15
n=526, result=1.622906e+15, error=1.622906e+15
n=527, result=1.622905e+15, error=1.622905e+15
n=528, result=1.622905e+15, error=1.622905e+15
n=529, result=1.622905e+15, error=1.622905e+15
n=530, result=1.622905e+15, error=1.622905e+15
n=531, result=1.622905e+15, error=1.622905e+15
n=532, result=1.622905e+15, error=1.622905e+15
n=533, result=1.622905e+15, error=1.622905e+15
n=534, result=1.622904e+15, error=1.622904e+15
n=535, result=1.622904e+15, error=1.622904e+15
n=536, result=1.622904e+15, error=1.622904e+15
n=537, result=1.622904e+15, error=1.622904e+15
n=538, result=1.622904e+15, error=1.622904e+15
n=539, result=1.622904e+15, error=1.622904e+15
n=540, result=1.622904e+15, error=1.622904e+15
n=541, result=1.622904e+15, error=1.622904e+15
n=542, result=1.622903e+15, error=1.622903e+15
n=543, result=1.622903e+15, error=1.622903e+15
n=544, result=1.622903e+15, error=1.622903e+15
n=545, result=1.622903e+15, error=1.622903e+15
n=546, result=1.622903e+15, error=1.622903e+15
n=547, result=1.622903e+15, error=1.622903e+15
n=548, result=1.622903e+15, error=1.622903e+15
n=549, result=1.622903e+15, error=1.622903e+15
n=550, result=1.622902e+15, error=1.622902e+15
n=551, result=1.622902e+15, error=1.622902e+15
n=552, result=1.622902e+15, error=1.622902e+15
n=553, result=1.622902e+15, error=1.622902e+15
n=554, result=1.622902e+15, error=1.622902e+15
n=555, result=1.622902e+15, error=1.622902e+15
n=556, result=1.622902e+15, error=1.622902e+15
n=557, result=1.622902e+15, error=1.622902e+15
n=558, result=1.622902e+15, error=1.622902e+15
n=559, result=1.622901e+15, error=1.622901e+15
n=560, result=1.622901e+15, error=1.622901e+15
n=561, result=1.622901e+15, error=1.622901e+15
n=562, result=1.622901e+15, error=1.622901e+15
n=563, result=1.622901e+15, error=1.622901e+15
n=564, result=1.622901e+15, error=1.622901e+15
n=565, result=1.622901e+15, error=1.622901e+15
n=566, result=1.622901e+15, error=1.622901e+15
n=567, result=1.6229e+15, error=1.6229e+15
n=568, result=1.6229e+15, error=1.6229e+15
n=569, result=1.6229e+15, error=1.6229e+15
n=570, result=1.6229e+15, error=1.6229e+15
n=571, result=1.6229e+15, error=1.6229e+15
n=572, result=1.6229e+15, error=1.6229e+15
n=573, result=1.6229e+15, error=1.6229e+15
n=574, result=1.6229e+15, error=1.6229e+15
n=575, result=1.6229e+15, error=1.6229e+15
n=576, result=1.6229e+15, error=1.6229e+15
n=577, result=1.622899e+15, error=1.622899e+15
n=578, result=1.622899e+15, error=1.622899e+15
n=579, result=1.622899e+15, error=1.622899e+15
n=580, result=1.622899e+15, error=1.622899e+15
n=581, result=1.622899e+15, error=1.622899e+15
n=582, result=1.622899e+15, error=1.622899e+15
n=583, result=1.622899e+15, error=1.622899e+15
n=584, result=1.622899e+15, error=1.622899e+15
n=585, result=1.622899e+15, error=1.622899e+15
n=586, result=1.622899e+15, error=1.622899e+15
n=587, result=1.622898e+15, error=1.622898e+15
n=588, result=1.622898e+15, error=1.622898e+15
n=589, result=1.622898e+15, error=1.622898e+15
n=590, result=1.622898e+15, error=1.622898e+15
n=591, result=1.622898e+15, error=1.622898e+15
n=592, result=1.622898e+15, error=1.622898e+15
n=593, result=1.622898e+15, error=1.622898e+15
n=594, result=1.622898e+15, error=1.622898e+15
n=595, result=1.622898e+15, error=1.622898e+15
n=596, result=1.622898e+15, error=1.622898e+15
n=597, result=1.622897e+15, error=1.622897e+15
n=598, result=1.622897e+15, error=1.622897e+15
n=599, result=1.622897e+15, error=1.622897e+15
n=600, result=1.622897e+15, error=1.622897e+15
n=601, result=1.622897e+15, error=1.622897e+15
n=602, result=1.622897e+15, error=1.622897e+15
n=603, result=1.622897e+15, error=1.622897e+15
n=604, result=1.622897e+15, error=1.622897e+15
n=605, result=1.622897e+15, error=1.622897e+15
n=606, result=1.622897e+15, error=1.622897e+15
n=607, result=1.622897e+15, error=1.622897e+15
n=608, result=1.622896e+15, error=1.622896e+15
n=609, result=1.622896e+15, error=1.622896e+15
n=610, result=1.622896e+15, error=1.622896e+15
n=611, result=1.622896e+15, error=1.622896e+15
n=612, result=1.622896e+15, error=1.622896e+15
n=613, result=1.622896e+15, error=1.622896e+15
n=614, result=1.622896e+15, error=1.622896e+15
n=615, result=1.622896e+15, error=1.622896e+15
n=616, result=1.622896e+15, error=1.622896e+15
n=617, result=1.622896e+15, error=1.622896e+15
n=618, result=1.622896e+15, error=1.622896e+15
n=619, result=1.622895e+15, error=1.622895e+15
n=620, result=1.622895e+15, error=1.622895e+15
n=621, result=1.622895e+15, error=1.622895e+15
n=622, result=1.622895e+15, error=1.622895e+15
n=623, result=1.622895e+15, error=1.622895e+15
n=624, result=1.622895e+15, error=1.622895e+15
n=625, result=1.622895e+15, error=1.622895e+15
n=626, result=1.622895e+15, error=1.622895e+15
n=627, result=1.622895e+15, error=1.622895e+15
n=628, result=1.622895e+15, error=1.622895e+15
n=629, result=1.622895e+15, error=1.622895e+15
n=630, result=1.622895e+15, error=1.622895e+15
n=631, result=1.622895e+15, error=1.622895e+15
n=632, result=1.622894e+15, error=1.622894e+15
n=633, result=1.622894e+15, error=1.622894e+15
n=634, result=1.622894e+15, error=1.622894e+15
n=635, result=1.622894e+15, error=1.622894e+15
n=636, result=1.622894e+15, error=1.622894e+15
n=637, result=1.622894e+15, error=1.622894e+15
n=638, result=1.622894e+15, error=1.622894e+15
n=639, result=1.622894e+15, error=1.622894e+15
n=640, result=1.622894e+15, error=1.622894e+15
n=641, result=1.622894e+15, error=1.622894e+15
n=642, result=1.622894e+15, error=1.622894e+15
n=643, result=1.622894e+15, error=1.622894e+15
n=644, result=1.622893e+15, error=1.622893e+15
n=645, result=1.622893e+15, error=1.622893e+15
n=646, result=1.622893e+15, error=1.622893e+15
n=647, result=1.622893e+15, error=1.622893e+15
n=648, result=1.622893e+15, error=1.622893e+15
n=649, result=1.622893e+15, error=1.622893e+15
n=650, result=1.622893e+15, error=1.622893e+15
n=651, result=1.622893e+15, error=1.622893e+15
n=652, result=1.622893e+15, error=1.622893e+15
n=653, result=1.622893e+15, error=1.622893e+15
n=654, result=1.622893e+15, error=1.622893e+15
n=655, result=1.622893e+15, error=1.622893e+15
n=656, result=1.622893e+15, error=1.622893e+15
n=657, result=1.622893e+15, error=1.622893e+15
n=658, result=1.622892e+15, error=1.622892e+15
n=659, result=1.622892e+15, error=1.622892e+15
n=660, result=1.622892e+15, error=1.622892e+15
n=661, result=1.622892e+15, error=1.622892e+15
n=662, result=1.622892e+15, error=1.622892e+15
n=663, result=1.622892e+15, error=1.622892e+15
n=664, result=1.622892e+15, error=1.622892e+15
n=665, result=1.622892e+15, error=1.622892e+15
n=666, result=1.622892e+15, error=1.622892e+15
n=667, result=1.622892e+15, error=1.622892e+15
n=668, result=1.622892e+15, error=1.622892e+15
n=669, result=1.622892e+15, error=1.622892e+15
n=670, result=1.622892e+15, error=1.622892e+15
n=671, result=1.622892e+15, error=1.622892e+15
n=672, result=1.622892e+15, error=1.622892e+15
n=673, result=1.622891e+15, error=1.622891e+15
n=674, result=1.622891e+15, error=1.622891e+15
n=675, result=1.622891e+15, error=1.622891e+15
n=676, result=1.622891e+15, error=1.622891e+15
n=677, result=1.622891e+15, error=1.622891e+15
n=678, result=1.622891e+15, error=1.622891e+15
n=679, result=1.622891e+15, error=1.622891e+15
n=680, result=1.622891e+15, error=1.622891e+15
n=681, result=1.622891e+15, error=1.622891e+15
n=682, result=1.622891e+15, error=1.622891e+15
n=683, result=1.622891e+15, error=1.622891e+15
n=684, result=1.622891e+15, error=1.622891e+15
n=685, result=1.622891e+15, error=1.622891e+15
n=686, result=1.622891e+15, error=1.622891e+15
n=687, result=1.622891e+15, error=1.622891e+15
n=688, result=1.622891e+15, error=1.622891e+15
n=689, result=1.62289e+15, error=1.62289e+15
n=690, result=1.62289e+15, error=1.62289e+15
n=691, result=1.62289e+15, error=1.62289e+15
n=692, result=1.62289e+15, error=1.62289e+15
n=693, result=1.62289e+15, error=1.62289e+15
n=694, result=1.62289e+15, error=1.62289e+15
n=695, result=1.62289e+15, error=1.62289e+15
n=696, result=1.62289e+15, error=1.62289e+15
n=697, result=1.62289e+15, error=1.62289e+15
n=698, result=1.62289e+15, error=1.62289e+15
n=699, result=1.62289e+15, error=1.62289e+15
n=700, result=1.62289e+15, error=1.62289e+15
n=701, result=1.62289e+15, error=1.62289e+15
n=702, result=1.62289e+15, error=1.62289e+15
n=703, result=1.62289e+15, error=1.62289e+15
n=704, result=1.62289e+15, error=1.62289e+15
n=705, result=1.62289e+15, error=1.62289e+15
n=706, result=1.622889e+15, error=1.622889e+15
n=707, result=1.622889e+15, error=1.622889e+15
n=708, result=1.622889e+15, error=1.622889e+15
n=709, result=1.622889e+15, error=1.622889e+15
n=710, result=1.622889e+15, error=1.622889e+15
n=711, result=1.622889e+15, error=1.622889e+15
n=712, result=1.622889e+15, error=1.622889e+15
n=713, result=1.622889e+15, error=1.622889e+15
n=714, result=1.622889e+15, error=1.622889e+15
n=715, result=1.622889e+15, error=1.622889e+15
n=716, result=1.622889e+15, error=1.622889e+15
n=717, result=1.622889e+15, error=1.622889e+15
n=718, result=1.622889e+15, error=1.622889e+15
n=719, result=1.622889e+15, error=1.622889e+15
n=720, result=1.622889e+15, error=1.622889e+15
n=721, result=1.622889e+15, error=1.622889e+15
n=722, result=1.622889e+15, error=1.622889e+15
n=723, result=1.622889e+15, error=1.622889e+15
n=724, result=1.622888e+15, error=1.622888e+15
n=725, result=1.622888e+15, error=1.622888e+15
n=726, result=1.622888e+15, error=1.622888e+15
n=727, result=1.622888e+15, error=1.622888e+15
n=728, result=1.622888e+15, error=1.622888e+15
n=729, result=1.622888e+15, error=1.622888e+15
n=730, result=1.622888e+15, error=1.622888e+15
n=731, result=1.622888e+15, error=1.622888e+15
n=732, result=1.622888e+15, error=1.622888e+15
n=733, result=1.622888e+15, error=1.622888e+15
n=734, result=1.622888e+15, error=1.622888e+15
n=735, result=1.622888e+15, error=1.622888e+15
n=736, result=1.622888e+15, error=1.622888e+15
n=737, result=1.622888e+15, error=1.622888e+15
n=738, result=1.622888e+15, error=1.622888e+15
n=739, result=1.622888e+15, error=1.622888e+15
n=740, result=1.622888e+15, error=1.622888e+15
n=741, result=1.622888e+15, error=1.622888e+15
n=742, result=1.622888e+15, error=1.622888e+15
n=743, result=1.622888e+15, error=1.622888e+15
n=744, result=1.622887e+15, error=1.622887e+15
n=745, result=1.622887e+15, error=1.622887e+15
n=746, result=1.622887e+15, error=1.622887e+15
n=747, result=1.622887e+15, error=1.622887e+15
n=748, result=1.622887e+15, error=1.622887e+15
n=749, result=1.622887e+15, error=1.622887e+15
n=750, result=1.622887e+15, error=1.622887e+15
n=751, result=1.622887e+15, error=1.622887e+15
n=752, result=1.622887e+15, error=1.622887e+15
n=753, result=1.622887e+15, error=1.622887e+15
n=754, result=1.622887e+15, error=1.622887e+15
n=755, result=1.622887e+15, error=1.622887e+15
n=756, result=1.622887e+15, error=1.622887e+15
n=757, result=1.622887e+15, error=1.622887e+15
n=758, result=1.622887e+15, error=1.622887e+15
n=759, result=1.622887e+15, error=1.622887e+15
n=760, result=1.622887e+15, error=1.622887e+15
n=761, result=1.622887e+15, error=1.622887e+15
n=762, result=1.622887e+15, error=1.622887e+15
n=763, result=1.622887e+15, error=1.622887e+15
n=764, result=1.622887e+15, error=1.622887e+15
n=765, result=1.622886e+15, error=1.622886e+15
n=766, result=1.622886e+15, error=1.622886e+15
n=767, result=1.622886e+15, error=1.622886e+15
n=768, result=1.622886e+15, error=1.622886e+15
n=769, result=1.622886e+15, error=1.622886e+15
n=770, result=1.622886e+15, error=1.622886e+15
n=771, result=1.622886e+15, error=1.622886e+15
n=772, result=1.622886e+15, error=1.622886e+15
n=773, result=1.622886e+15, error=1.622886e+15
n=774, result=1.622886e+15, error=1.622886e+15
n=775, result=1.622886e+15, error=1.622886e+15
n=776, result=1.622886e+15, error=1.622886e+15
n=777, result=1.622886e+15, error=1.622886e+15
n=778, result=1.622886e+15, error=1.622886e+15
n=779, result=1.622886e+15, error=1.622886e+15
n=780, result=1.622886e+15, error=1.622886e+15
n=781, result=1.622886e+15, error=1.622886e+15
n=782, result=1.622886e+15, error=1.622886e+15
n=783, result=1.622886e+15, error=1.622886e+15
n=784, result=1.622886e+15, error=1.622886e+15
n=785, result=1.622886e+15, error=1.622886e+15
n=786, result=1.622886e+15, error=1.622886e+15
n=787, result=1.622886e+15, error=1.622886e+15
n=788, result=1.622885e+15, error=1.622885e+15
n=789, result=1.622885e+15, error=1.622885e+15
n=790, result=1.622885e+15, error=1.622885e+15
n=791, result=1.622885e+15, error=1.622885e+15
n=792, result=1.622885e+15, error=1.622885e+15
n=793, result=1.622885e+15, error=1.622885e+15
n=794, result=1.622885e+15, error=1.622885e+15
n=795, result=1.622885e+15, error=1.622885e+15
n=796, result=1.622885e+15, error=1.622885e+15
n=797, result=1.622885e+15, error=1.622885e+15
n=798, result=1.622885e+15, error=1.622885e+15
n=799, result=1.622885e+15, error=1.622885e+15
n=800, result=1.622885e+15, error=1.622885e+15
n=801, result=1.622885e+15, error=1.622885e+15
n=802, result=1.622885e+15, error=1.622885e+15
n=803, result=1.622885e+15, error=1.622885e+15
n=804, result=1.622885e+15, error=1.622885e+15
n=805, result=1.622885e+15, error=1.622885e+15
n=806, result=1.622885e+15, error=1.622885e+15
n=807, result=1.622885e+15, error=1.622885e+15
n=808, result=1.622885e+15, error=1.622885e+15
n=809, result=1.622885e+15, error=1.622885e+15
n=810, result=1.622885e+15, error=1.622885e+15
n=811, result=1.622885e+15, error=1.622885e+15
n=812, result=1.622885e+15, error=1.622885e+15
n=813, result=1.622885e+15, error=1.622885e+15
n=814, result=1.622884e+15, error=1.622884e+15
n=815, result=1.622884e+15, error=1.622884e+15
n=816, result=1.622884e+15, error=1.622884e+15
n=817, result=1.622884e+15, error=1.622884e+15
n=818, result=1.622884e+15, error=1.622884e+15
n=819, result=1.622884e+15, error=1.622884e+15
n=820, result=1.622884e+15, error=1.622884e+15
n=821, result=1.622884e+15, error=1.622884e+15
n=822, result=1.622884e+15, error=1.622884e+15
n=823, result=1.622884e+15, error=1.622884e+15
n=824, result=1.622884e+15, error=1.622884e+15
n=825, result=1.622884e+15, error=1.622884e+15
n=826, result=1.622884e+15, error=1.622884e+15
n=827, result=1.622884e+15, error=1.622884e+15
n=828, result=1.622884e+15, error=1.622884e+15
n=829, result=1.622884e+15, error=1.622884e+15
n=830, result=1.622884e+15, error=1.622884e+15
n=831, result=1.622884e+15, error=1.622884e+15
n=832, result=1.622884e+15, error=1.622884e+15
n=833, result=1.622884e+15, error=1.622884e+15
n=834, result=1.622884e+15, error=1.622884e+15
n=835, result=1.622884e+15, error=1.622884e+15
n=836, result=1.622884e+15, error=1.622884e+15
n=837, result=1.622884e+15, error=1.622884e+15
n=838, result=1.622884e+15, error=1.622884e+15
n=839, result=1.622884e+15, error=1.622884e+15
n=840, result=1.622884e+15, error=1.622884e+15
n=841, result=1.622884e+15, error=1.622884e+15
n=842, result=1.622883e+15, error=1.622883e+15
n=843, result=1.622883e+15, error=1.622883e+15
n=844, result=1.622883e+15, error=1.622883e+15
n=845, result=1.622883e+15, error=1.622883e+15
n=846, result=1.622883e+15, error=1.622883e+15
n=847, result=1.622883e+15, error=1.622883e+15
n=848, result=1.622883e+15, error=1.622883e+15
n=849, result=1.622883e+15, error=1.622883e+15
n=850, result=1.622883e+15, error=1.622883e+15
n=851, result=1.622883e+15, error=1.622883e+15
n=852, result=1.622883e+15, error=1.622883e+15
n=853, result=1.622883e+15, error=1.622883e+15
n=854, result=1.622883e+15, error=1.622883e+15
n=855, result=1.622883e+15, error=1.622883e+15
n=856, result=1.622883e+15, error=1.622883e+15
n=857, result=1.622883e+15, error=1.622883e+15
n=858, result=1.622883e+15, error=1.622883e+15
n=859, result=1.622883e+15, error=1.622883e+15
n=860, result=1.622883e+15, error=1.622883e+15
n=861, result=1.622883e+15, error=1.622883e+15
n=862, result=1.622883e+15, error=1.622883e+15
n=863, result=1.622883e+15, error=1.622883e+15
n=864, result=1.622883e+15, error=1.622883e+15
n=865, result=1.622883e+15, error=1.622883e+15
n=866, result=1.622883e+15, error=1.622883e+15
n=867, result=1.622883e+15, error=1.622883e+15
n=868, result=1.622883e+15, error=1.622883e+15
n=869, result=1.622883e+15, error=1.622883e+15
n=870, result=1.622883e+15, error=1.622883e+15
n=871, result=1.622883e+15, error=1.622883e+15
n=872, result=1.622883e+15, error=1.622883e+15
n=873, result=1.622883e+15, error=1.622883e+15
n=874, result=1.622882e+15, error=1.622882e+15
n=875, result=1.622882e+15, error=1.622882e+15
n=876, result=1.622882e+15, error=1.622882e+15
n=877, result=1.622882e+15, error=1.622882e+15
n=878, result=1.622882e+15, error=1.622882e+15
n=879, result=1.622882e+15, error=1.622882e+15
n=880, result=1.622882e+15, error=1.622882e+15
n=881, result=1.622882e+15, error=1.622882e+15
n=882, result=1.622882e+15, error=1.622882e+15
n=883, result=1.622882e+15, error=1.622882e+15
n=884, result=1.622882e+15, error=1.622882e+15
n=885, result=1.622882e+15, error=1.622882e+15
n=886, result=1.622882e+15, error=1.622882e+15
n=887, result=1.622882e+15, error=1.622882e+15
n=888, result=1.622882e+15, error=1.622882e+15
n=889, result=1.622882e+15, error=1.622882e+15
n=890, result=1.622882e+15, error=1.622882e+15
n=891, result=1.622882e+15, error=1.622882e+15
n=892, result=1.622882e+15, error=1.622882e+15
n=893, result=1.622882e+15, error=1.622882e+15
n=894, result=1.622882e+15, error=1.622882e+15
n=895, result=1.622882e+15, error=1.622882e+15
n=896, result=1.622882e+15, error=1.622882e+15
n=897, result=1.622882e+15, error=1.622882e+15
n=898, result=1.622882e+15, error=1.622882e+15
n=899, result=1.622882e+15, error=1.622882e+15
n=900, result=1.622882e+15, error=1.622882e+15
n=901, result=1.622882e+15, error=1.622882e+15
n=902, result=1.622882e+15, error=1.622882e+15
n=903, result=1.622882e+15, error=1.622882e+15
n=904, result=1.622882e+15, error=1.622882e+15
n=905, result=1.622882e+15, error=1.622882e+15
n=906, result=1.622882e+15, error=1.622882e+15
n=907, result=1.622882e+15, error=1.622882e+15
n=908, result=1.622882e+15, error=1.622882e+15
n=909, result=1.622881e+15, error=1.622881e+15
n=910, result=1.622881e+15, error=1.622881e+15
n=911, result=1.622881e+15, error=1.622881e+15
n=912, result=1.622881e+15, error=1.622881e+15
n=913, result=1.622881e+15, error=1.622881e+15
n=914, result=1.622881e+15, error=1.622881e+15
n=915, result=1.622881e+15, error=1.622881e+15
n=916, result=1.622881e+15, error=1.622881e+15
n=917, result=1.622881e+15, error=1.622881e+15
n=918, result=1.622881e+15, error=1.622881e+15
n=919, result=1.622881e+15, error=1.622881e+15
n=920, result=1.622881e+15, error=1.622881e+15
n=921, result=1.622881e+15, error=1.622881e+15
n=922, result=1.622881e+15, error=1.622881e+15
n=923, result=1.622881e+15, error=1.622881e+15
n=924, result=1.622881e+15, error=1.622881e+15
n=925, result=1.622881e+15, error=1.622881e+15
n=926, result=1.622881e+15, error=1.622881e+15
n=927, result=1.622881e+15, error=1.622881e+15
n=928, result=1.622881e+15, error=1.622881e+15
n=929, result=1.622881e+15, error=1.622881e+15
n=930, result=1.622881e+15, error=1.622881e+15
n=931, result=1.622881e+15, error=1.622881e+15
n=932, result=1.622881e+15, error=1.622881e+15
n=933, result=1.622881e+15, error=1.622881e+15
n=934, result=1.622881e+15, error=1.622881e+15
n=935, result=1.622881e+15, error=1.622881e+15
n=936, result=1.622881e+15, error=1.622881e+15
n=937, result=1.622881e+15, error=1.622881e+15
n=938, result=1.622881e+15, error=1.622881e+15
n=939, result=1.622881e+15, error=1.622881e+15
n=940, result=1.622881e+15, error=1.622881e+15
n=941, result=1.622881e+15, error=1.622881e+15
n=942, result=1.622881e+15, error=1.622881e+15
n=943, result=1.622881e+15, error=1.622881e+15
n=944, result=1.622881e+15, error=1.622881e+15
n=945, result=1.622881e+15, error=1.622881e+15
n=946, result=1.622881e+15, error=1.622881e+15
n=947, result=1.622881e+15, error=1.622881e+15
n=948, result=1.622881e+15, error=1.622881e+15
n=949, result=1.62288e+15, error=1.62288e+15
n=950, result=1.62288e+15, error=1.62288e+15
n=951, result=1.62288e+15, error=1.62288e+15
n=952, result=1.62288e+15, error=1.62288e+15
n=953, result=1.62288e+15, error=1.62288e+15
n=954, result=1.62288e+15, error=1.62288e+15
n=955, result=1.62288e+15, error=1.62288e+15
n=956, result=1.62288e+15, error=1.62288e+15
n=957, result=1.62288e+15, error=1.62288e+15
n=958, result=1.62288e+15, error=1.62288e+15
n=959, result=1.62288e+15, error=1.62288e+15
n=960, result=1.62288e+15, error=1.62288e+15
n=961, result=1.62288e+15, error=1.62288e+15
n=962, result=1.62288e+15, error=1.62288e+15
n=963, result=1.62288e+15, error=1.62288e+15
n=964, result=1.62288e+15, error=1.62288e+15
n=965, result=1.62288e+15, error=1.62288e+15
n=966, result=1.62288e+15, error=1.62288e+15
n=967, result=1.62288e+15, error=1.62288e+15
n=968, result=1.62288e+15, error=1.62288e+15
n=969, result=1.62288e+15, error=1.62288e+15
n=970, result=1.62288e+15, error=1.62288e+15
n=971, result=1.62288e+15, error=1.62288e+15
n=972, result=1.62288e+15, error=1.62288e+15
n=973, result=1.62288e+15, error=1.62288e+15
n=974, result=1.62288e+15, error=1.62288e+15
n=975, result=1.62288e+15, error=1.62288e+15
n=976, result=1.62288e+15, error=1.62288e+15
n=977, result=1.62288e+15, error=1.62288e+15
n=978, result=1.62288e+15, error=1.62288e+15
n=979, result=1.62288e+15, error=1.62288e+15
n=980, result=1.62288e+15, error=1.62288e+15
n=981, result=1.62288e+15, error=1.62288e+15
n=982, result=1.62288e+15, error=1.62288e+15
n=983, result=1.62288e+15, error=1.62288e+15
n=984, result=1.62288e+15, error=1.62288e+15
n=985, result=1.62288e+15, error=1.62288e+15
n=986, result=1.62288e+15, error=1.62288e+15
n=987, result=1.62288e+15, error=1.62288e+15
n=988, result=1.62288e+15, error=1.62288e+15
n=989, result=1.62288e+15, error=1.62288e+15
n=990, result=1.62288e+15, error=1.62288e+15
n=991, result=1.62288e+15, error=1.62288e+15
n=992, result=1.62288e+15, error=1.62288e+15
n=993, result=1.62288e+15, error=1.62288e+15
n=994, result=1.62288e+15, error=1.62288e+15
n=995, result=1.622879e+15, error=1.622879e+15
n=996, result=1.622879e+15, error=1.622879e+15
n=997, result=1.622879e+15, error=1.622879e+15
n=998, result=1.622879e+15, error=1.622879e+15
n=999, result=1.622879e+15, error=1.622879e+15
library(pracma)
a = 5
b = 3
n = 4
f = function(x) {
  x*a*b*(x^a-1)*(1-x^a)^b-1  
} 
#### Simpson ####
xs = seq(0, 1, length.out = 101)
ys = f(xs)
simpson_n <- function(ftn, a, b, n = 100) {
    n <- max(c(2*(n %/% 2), 4))
    h <- (b-a)/n
    x.vec1 <- seq(a+h, b-h, by = 2*h)       # ganjil
    x.vec2 <- seq(a+2*h, b-2*h, by = 2*h)   # genap
    f.vec1 <- sapply(x.vec1, ftn)   # ganjil
    f.vec2 <- sapply(x.vec2, ftn)   # genap
    S <- h/3*(ftn(a) + ftn(b) + 4*sum(f.vec1) + 2*sum(f.vec2))
    return(S)
}
exact_value=0.886207
tol <-  0.0001
err <- 1
n = 4
while(err>tol){
  res_simp <- simpson_n(f,a,b,n = n)
  err <- abs(res_simp-exact_value)
  cat("n=",n,", result=",res_simp,", error=",err,"\n",sep = "")
  n=n+1
  if(n==1000){
    break
  }
}
n=4, result=1.735761e+15, error=1.735761e+15
n=5, result=1.735761e+15, error=1.735761e+15
n=6, result=1.649623e+15, error=1.649623e+15
n=7, result=1.649623e+15, error=1.649623e+15
n=8, result=1.631925e+15, error=1.631925e+15
n=9, result=1.631925e+15, error=1.631925e+15
n=10, result=1.626698e+15, error=1.626698e+15
n=11, result=1.626698e+15, error=1.626698e+15
n=12, result=1.624749e+15, error=1.624749e+15
n=13, result=1.624749e+15, error=1.624749e+15
n=14, result=1.623894e+15, error=1.623894e+15
n=15, result=1.623894e+15, error=1.623894e+15
n=16, result=1.623474e+15, error=1.623474e+15
n=17, result=1.623474e+15, error=1.623474e+15
n=18, result=1.623249e+15, error=1.623249e+15
n=19, result=1.623249e+15, error=1.623249e+15
n=20, result=1.623119e+15, error=1.623119e+15
n=21, result=1.623119e+15, error=1.623119e+15
n=22, result=1.62304e+15, error=1.62304e+15
n=23, result=1.62304e+15, error=1.62304e+15
n=24, result=1.62299e+15, error=1.62299e+15
n=25, result=1.62299e+15, error=1.62299e+15
n=26, result=1.622957e+15, error=1.622957e+15
n=27, result=1.622957e+15, error=1.622957e+15
n=28, result=1.622935e+15, error=1.622935e+15
n=29, result=1.622935e+15, error=1.622935e+15
n=30, result=1.622919e+15, error=1.622919e+15
n=31, result=1.622919e+15, error=1.622919e+15
n=32, result=1.622908e+15, error=1.622908e+15
n=33, result=1.622908e+15, error=1.622908e+15
n=34, result=1.6229e+15, error=1.6229e+15
n=35, result=1.6229e+15, error=1.6229e+15
n=36, result=1.622893e+15, error=1.622893e+15
n=37, result=1.622893e+15, error=1.622893e+15
n=38, result=1.622889e+15, error=1.622889e+15
n=39, result=1.622889e+15, error=1.622889e+15
n=40, result=1.622885e+15, error=1.622885e+15
n=41, result=1.622885e+15, error=1.622885e+15
n=42, result=1.622882e+15, error=1.622882e+15
n=43, result=1.622882e+15, error=1.622882e+15
n=44, result=1.62288e+15, error=1.62288e+15
n=45, result=1.62288e+15, error=1.62288e+15
n=46, result=1.622878e+15, error=1.622878e+15
n=47, result=1.622878e+15, error=1.622878e+15
n=48, result=1.622877e+15, error=1.622877e+15
n=49, result=1.622877e+15, error=1.622877e+15
n=50, result=1.622876e+15, error=1.622876e+15
n=51, result=1.622876e+15, error=1.622876e+15
n=52, result=1.622875e+15, error=1.622875e+15
n=53, result=1.622875e+15, error=1.622875e+15
n=54, result=1.622874e+15, error=1.622874e+15
n=55, result=1.622874e+15, error=1.622874e+15
n=56, result=1.622873e+15, error=1.622873e+15
n=57, result=1.622873e+15, error=1.622873e+15
n=58, result=1.622873e+15, error=1.622873e+15
n=59, result=1.622873e+15, error=1.622873e+15
n=60, result=1.622873e+15, error=1.622873e+15
n=61, result=1.622873e+15, error=1.622873e+15
n=62, result=1.622872e+15, error=1.622872e+15
n=63, result=1.622872e+15, error=1.622872e+15
n=64, result=1.622872e+15, error=1.622872e+15
n=65, result=1.622872e+15, error=1.622872e+15
n=66, result=1.622872e+15, error=1.622872e+15
n=67, result=1.622872e+15, error=1.622872e+15
n=68, result=1.622871e+15, error=1.622871e+15
n=69, result=1.622871e+15, error=1.622871e+15
n=70, result=1.622871e+15, error=1.622871e+15
n=71, result=1.622871e+15, error=1.622871e+15
n=72, result=1.622871e+15, error=1.622871e+15
n=73, result=1.622871e+15, error=1.622871e+15
n=74, result=1.622871e+15, error=1.622871e+15
n=75, result=1.622871e+15, error=1.622871e+15
n=76, result=1.622871e+15, error=1.622871e+15
n=77, result=1.622871e+15, error=1.622871e+15
n=78, result=1.62287e+15, error=1.62287e+15
n=79, result=1.62287e+15, error=1.62287e+15
n=80, result=1.62287e+15, error=1.62287e+15
n=81, result=1.62287e+15, error=1.62287e+15
n=82, result=1.62287e+15, error=1.62287e+15
n=83, result=1.62287e+15, error=1.62287e+15
n=84, result=1.62287e+15, error=1.62287e+15
n=85, result=1.62287e+15, error=1.62287e+15
n=86, result=1.62287e+15, error=1.62287e+15
n=87, result=1.62287e+15, error=1.62287e+15
n=88, result=1.62287e+15, error=1.62287e+15
n=89, result=1.62287e+15, error=1.62287e+15
n=90, result=1.62287e+15, error=1.62287e+15
n=91, result=1.62287e+15, error=1.62287e+15
n=92, result=1.62287e+15, error=1.62287e+15
n=93, result=1.62287e+15, error=1.62287e+15
n=94, result=1.62287e+15, error=1.62287e+15
n=95, result=1.62287e+15, error=1.62287e+15
n=96, result=1.62287e+15, error=1.62287e+15
n=97, result=1.62287e+15, error=1.62287e+15
n=98, result=1.62287e+15, error=1.62287e+15
n=99, result=1.62287e+15, error=1.62287e+15
n=100, result=1.62287e+15, error=1.62287e+15
n=101, result=1.62287e+15, error=1.62287e+15
n=102, result=1.62287e+15, error=1.62287e+15
n=103, result=1.62287e+15, error=1.62287e+15
n=104, result=1.62287e+15, error=1.62287e+15
n=105, result=1.62287e+15, error=1.62287e+15
n=106, result=1.62287e+15, error=1.62287e+15
n=107, result=1.62287e+15, error=1.62287e+15
n=108, result=1.62287e+15, error=1.62287e+15
n=109, result=1.62287e+15, error=1.62287e+15
n=110, result=1.62287e+15, error=1.62287e+15
n=111, result=1.62287e+15, error=1.62287e+15
n=112, result=1.62287e+15, error=1.62287e+15
n=113, result=1.62287e+15, error=1.62287e+15
n=114, result=1.62287e+15, error=1.62287e+15
n=115, result=1.62287e+15, error=1.62287e+15
n=116, result=1.62287e+15, error=1.62287e+15
n=117, result=1.62287e+15, error=1.62287e+15
n=118, result=1.62287e+15, error=1.62287e+15
n=119, result=1.62287e+15, error=1.62287e+15
n=120, result=1.62287e+15, error=1.62287e+15
n=121, result=1.62287e+15, error=1.62287e+15
n=122, result=1.62287e+15, error=1.62287e+15
n=123, result=1.62287e+15, error=1.62287e+15
n=124, result=1.62287e+15, error=1.62287e+15
n=125, result=1.62287e+15, error=1.62287e+15
n=126, result=1.62287e+15, error=1.62287e+15
n=127, result=1.62287e+15, error=1.62287e+15
n=128, result=1.62287e+15, error=1.62287e+15
n=129, result=1.62287e+15, error=1.62287e+15
n=130, result=1.62287e+15, error=1.62287e+15
n=131, result=1.62287e+15, error=1.62287e+15
n=132, result=1.62287e+15, error=1.62287e+15
n=133, result=1.62287e+15, error=1.62287e+15
n=134, result=1.62287e+15, error=1.62287e+15
n=135, result=1.62287e+15, error=1.62287e+15
n=136, result=1.622869e+15, error=1.622869e+15
n=137, result=1.622869e+15, error=1.622869e+15
n=138, result=1.622869e+15, error=1.622869e+15
n=139, result=1.622869e+15, error=1.622869e+15
n=140, result=1.622869e+15, error=1.622869e+15
n=141, result=1.622869e+15, error=1.622869e+15
n=142, result=1.622869e+15, error=1.622869e+15
n=143, result=1.622869e+15, error=1.622869e+15
n=144, result=1.622869e+15, error=1.622869e+15
n=145, result=1.622869e+15, error=1.622869e+15
n=146, result=1.622869e+15, error=1.622869e+15
n=147, result=1.622869e+15, error=1.622869e+15
n=148, result=1.622869e+15, error=1.622869e+15
n=149, result=1.622869e+15, error=1.622869e+15
n=150, result=1.622869e+15, error=1.622869e+15
n=151, result=1.622869e+15, error=1.622869e+15
n=152, result=1.622869e+15, error=1.622869e+15
n=153, result=1.622869e+15, error=1.622869e+15
n=154, result=1.622869e+15, error=1.622869e+15
n=155, result=1.622869e+15, error=1.622869e+15
n=156, result=1.622869e+15, error=1.622869e+15
n=157, result=1.622869e+15, error=1.622869e+15
n=158, result=1.622869e+15, error=1.622869e+15
n=159, result=1.622869e+15, error=1.622869e+15
n=160, result=1.622869e+15, error=1.622869e+15
n=161, result=1.622869e+15, error=1.622869e+15
n=162, result=1.622869e+15, error=1.622869e+15
n=163, result=1.622869e+15, error=1.622869e+15
n=164, result=1.622869e+15, error=1.622869e+15
n=165, result=1.622869e+15, error=1.622869e+15
n=166, result=1.622869e+15, error=1.622869e+15
n=167, result=1.622869e+15, error=1.622869e+15
n=168, result=1.622869e+15, error=1.622869e+15
n=169, result=1.622869e+15, error=1.622869e+15
n=170, result=1.622869e+15, error=1.622869e+15
n=171, result=1.622869e+15, error=1.622869e+15
n=172, result=1.622869e+15, error=1.622869e+15
n=173, result=1.622869e+15, error=1.622869e+15
n=174, result=1.622869e+15, error=1.622869e+15
n=175, result=1.622869e+15, error=1.622869e+15
n=176, result=1.622869e+15, error=1.622869e+15
n=177, result=1.622869e+15, error=1.622869e+15
n=178, result=1.622869e+15, error=1.622869e+15
n=179, result=1.622869e+15, error=1.622869e+15
n=180, result=1.622869e+15, error=1.622869e+15
n=181, result=1.622869e+15, error=1.622869e+15
n=182, result=1.622869e+15, error=1.622869e+15
n=183, result=1.622869e+15, error=1.622869e+15
n=184, result=1.622869e+15, error=1.622869e+15
n=185, result=1.622869e+15, error=1.622869e+15
n=186, result=1.622869e+15, error=1.622869e+15
n=187, result=1.622869e+15, error=1.622869e+15
n=188, result=1.622869e+15, error=1.622869e+15
n=189, result=1.622869e+15, error=1.622869e+15
n=190, result=1.622869e+15, error=1.622869e+15
n=191, result=1.622869e+15, error=1.622869e+15
n=192, result=1.622869e+15, error=1.622869e+15
n=193, result=1.622869e+15, error=1.622869e+15
n=194, result=1.622869e+15, error=1.622869e+15
n=195, result=1.622869e+15, error=1.622869e+15
n=196, result=1.622869e+15, error=1.622869e+15
n=197, result=1.622869e+15, error=1.622869e+15
n=198, result=1.622869e+15, error=1.622869e+15
n=199, result=1.622869e+15, error=1.622869e+15
n=200, result=1.622869e+15, error=1.622869e+15
n=201, result=1.622869e+15, error=1.622869e+15
n=202, result=1.622869e+15, error=1.622869e+15
n=203, result=1.622869e+15, error=1.622869e+15
n=204, result=1.622869e+15, error=1.622869e+15
n=205, result=1.622869e+15, error=1.622869e+15
n=206, result=1.622869e+15, error=1.622869e+15
n=207, result=1.622869e+15, error=1.622869e+15
n=208, result=1.622869e+15, error=1.622869e+15
n=209, result=1.622869e+15, error=1.622869e+15
n=210, result=1.622869e+15, error=1.622869e+15
n=211, result=1.622869e+15, error=1.622869e+15
n=212, result=1.622869e+15, error=1.622869e+15
n=213, result=1.622869e+15, error=1.622869e+15
n=214, result=1.622869e+15, error=1.622869e+15
n=215, result=1.622869e+15, error=1.622869e+15
n=216, result=1.622869e+15, error=1.622869e+15
n=217, result=1.622869e+15, error=1.622869e+15
n=218, result=1.622869e+15, error=1.622869e+15
n=219, result=1.622869e+15, error=1.622869e+15
n=220, result=1.622869e+15, error=1.622869e+15
n=221, result=1.622869e+15, error=1.622869e+15
n=222, result=1.622869e+15, error=1.622869e+15
n=223, result=1.622869e+15, error=1.622869e+15
n=224, result=1.622869e+15, error=1.622869e+15
n=225, result=1.622869e+15, error=1.622869e+15
n=226, result=1.622869e+15, error=1.622869e+15
n=227, result=1.622869e+15, error=1.622869e+15
n=228, result=1.622869e+15, error=1.622869e+15
n=229, result=1.622869e+15, error=1.622869e+15
n=230, result=1.622869e+15, error=1.622869e+15
n=231, result=1.622869e+15, error=1.622869e+15
n=232, result=1.622869e+15, error=1.622869e+15
n=233, result=1.622869e+15, error=1.622869e+15
n=234, result=1.622869e+15, error=1.622869e+15
n=235, result=1.622869e+15, error=1.622869e+15
n=236, result=1.622869e+15, error=1.622869e+15
n=237, result=1.622869e+15, error=1.622869e+15
n=238, result=1.622869e+15, error=1.622869e+15
n=239, result=1.622869e+15, error=1.622869e+15
n=240, result=1.622869e+15, error=1.622869e+15
n=241, result=1.622869e+15, error=1.622869e+15
n=242, result=1.622869e+15, error=1.622869e+15
n=243, result=1.622869e+15, error=1.622869e+15
n=244, result=1.622869e+15, error=1.622869e+15
n=245, result=1.622869e+15, error=1.622869e+15
n=246, result=1.622869e+15, error=1.622869e+15
n=247, result=1.622869e+15, error=1.622869e+15
n=248, result=1.622869e+15, error=1.622869e+15
n=249, result=1.622869e+15, error=1.622869e+15
n=250, result=1.622869e+15, error=1.622869e+15
n=251, result=1.622869e+15, error=1.622869e+15
n=252, result=1.622869e+15, error=1.622869e+15
n=253, result=1.622869e+15, error=1.622869e+15
n=254, result=1.622869e+15, error=1.622869e+15
n=255, result=1.622869e+15, error=1.622869e+15
n=256, result=1.622869e+15, error=1.622869e+15
n=257, result=1.622869e+15, error=1.622869e+15
n=258, result=1.622869e+15, error=1.622869e+15
n=259, result=1.622869e+15, error=1.622869e+15
n=260, result=1.622869e+15, error=1.622869e+15
n=261, result=1.622869e+15, error=1.622869e+15
n=262, result=1.622869e+15, error=1.622869e+15
n=263, result=1.622869e+15, error=1.622869e+15
n=264, result=1.622869e+15, error=1.622869e+15
n=265, result=1.622869e+15, error=1.622869e+15
n=266, result=1.622869e+15, error=1.622869e+15
n=267, result=1.622869e+15, error=1.622869e+15
n=268, result=1.622869e+15, error=1.622869e+15
n=269, result=1.622869e+15, error=1.622869e+15
n=270, result=1.622869e+15, error=1.622869e+15
n=271, result=1.622869e+15, error=1.622869e+15
n=272, result=1.622869e+15, error=1.622869e+15
n=273, result=1.622869e+15, error=1.622869e+15
n=274, result=1.622869e+15, error=1.622869e+15
n=275, result=1.622869e+15, error=1.622869e+15
n=276, result=1.622869e+15, error=1.622869e+15
n=277, result=1.622869e+15, error=1.622869e+15
n=278, result=1.622869e+15, error=1.622869e+15
n=279, result=1.622869e+15, error=1.622869e+15
n=280, result=1.622869e+15, error=1.622869e+15
n=281, result=1.622869e+15, error=1.622869e+15
n=282, result=1.622869e+15, error=1.622869e+15
n=283, result=1.622869e+15, error=1.622869e+15
n=284, result=1.622869e+15, error=1.622869e+15
n=285, result=1.622869e+15, error=1.622869e+15
n=286, result=1.622869e+15, error=1.622869e+15
n=287, result=1.622869e+15, error=1.622869e+15
n=288, result=1.622869e+15, error=1.622869e+15
n=289, result=1.622869e+15, error=1.622869e+15
n=290, result=1.622869e+15, error=1.622869e+15
n=291, result=1.622869e+15, error=1.622869e+15
n=292, result=1.622869e+15, error=1.622869e+15
n=293, result=1.622869e+15, error=1.622869e+15
n=294, result=1.622869e+15, error=1.622869e+15
n=295, result=1.622869e+15, error=1.622869e+15
n=296, result=1.622869e+15, error=1.622869e+15
n=297, result=1.622869e+15, error=1.622869e+15
n=298, result=1.622869e+15, error=1.622869e+15
n=299, result=1.622869e+15, error=1.622869e+15
n=300, result=1.622869e+15, error=1.622869e+15
n=301, result=1.622869e+15, error=1.622869e+15
n=302, result=1.622869e+15, error=1.622869e+15
n=303, result=1.622869e+15, error=1.622869e+15
n=304, result=1.622869e+15, error=1.622869e+15
n=305, result=1.622869e+15, error=1.622869e+15
n=306, result=1.622869e+15, error=1.622869e+15
n=307, result=1.622869e+15, error=1.622869e+15
n=308, result=1.622869e+15, error=1.622869e+15
n=309, result=1.622869e+15, error=1.622869e+15
n=310, result=1.622869e+15, error=1.622869e+15
n=311, result=1.622869e+15, error=1.622869e+15
n=312, result=1.622869e+15, error=1.622869e+15
n=313, result=1.622869e+15, error=1.622869e+15
n=314, result=1.622869e+15, error=1.622869e+15
n=315, result=1.622869e+15, error=1.622869e+15
n=316, result=1.622869e+15, error=1.622869e+15
n=317, result=1.622869e+15, error=1.622869e+15
n=318, result=1.622869e+15, error=1.622869e+15
n=319, result=1.622869e+15, error=1.622869e+15
n=320, result=1.622869e+15, error=1.622869e+15
n=321, result=1.622869e+15, error=1.622869e+15
n=322, result=1.622869e+15, error=1.622869e+15
n=323, result=1.622869e+15, error=1.622869e+15
n=324, result=1.622869e+15, error=1.622869e+15
n=325, result=1.622869e+15, error=1.622869e+15
n=326, result=1.622869e+15, error=1.622869e+15
n=327, result=1.622869e+15, error=1.622869e+15
n=328, result=1.622869e+15, error=1.622869e+15
n=329, result=1.622869e+15, error=1.622869e+15
n=330, result=1.622869e+15, error=1.622869e+15
n=331, result=1.622869e+15, error=1.622869e+15
n=332, result=1.622869e+15, error=1.622869e+15
n=333, result=1.622869e+15, error=1.622869e+15
n=334, result=1.622869e+15, error=1.622869e+15
n=335, result=1.622869e+15, error=1.622869e+15
n=336, result=1.622869e+15, error=1.622869e+15
n=337, result=1.622869e+15, error=1.622869e+15
n=338, result=1.622869e+15, error=1.622869e+15
n=339, result=1.622869e+15, error=1.622869e+15
n=340, result=1.622869e+15, error=1.622869e+15
n=341, result=1.622869e+15, error=1.622869e+15
n=342, result=1.622869e+15, error=1.622869e+15
n=343, result=1.622869e+15, error=1.622869e+15
n=344, result=1.622869e+15, error=1.622869e+15
n=345, result=1.622869e+15, error=1.622869e+15
n=346, result=1.622869e+15, error=1.622869e+15
n=347, result=1.622869e+15, error=1.622869e+15
n=348, result=1.622869e+15, error=1.622869e+15
n=349, result=1.622869e+15, error=1.622869e+15
n=350, result=1.622869e+15, error=1.622869e+15
n=351, result=1.622869e+15, error=1.622869e+15
n=352, result=1.622869e+15, error=1.622869e+15
n=353, result=1.622869e+15, error=1.622869e+15
n=354, result=1.622869e+15, error=1.622869e+15
n=355, result=1.622869e+15, error=1.622869e+15
n=356, result=1.622869e+15, error=1.622869e+15
n=357, result=1.622869e+15, error=1.622869e+15
n=358, result=1.622869e+15, error=1.622869e+15
n=359, result=1.622869e+15, error=1.622869e+15
n=360, result=1.622869e+15, error=1.622869e+15
n=361, result=1.622869e+15, error=1.622869e+15
n=362, result=1.622869e+15, error=1.622869e+15
n=363, result=1.622869e+15, error=1.622869e+15
n=364, result=1.622869e+15, error=1.622869e+15
n=365, result=1.622869e+15, error=1.622869e+15
n=366, result=1.622869e+15, error=1.622869e+15
n=367, result=1.622869e+15, error=1.622869e+15
n=368, result=1.622869e+15, error=1.622869e+15
n=369, result=1.622869e+15, error=1.622869e+15
n=370, result=1.622869e+15, error=1.622869e+15
n=371, result=1.622869e+15, error=1.622869e+15
n=372, result=1.622869e+15, error=1.622869e+15
n=373, result=1.622869e+15, error=1.622869e+15
n=374, result=1.622869e+15, error=1.622869e+15
n=375, result=1.622869e+15, error=1.622869e+15
n=376, result=1.622869e+15, error=1.622869e+15
n=377, result=1.622869e+15, error=1.622869e+15
n=378, result=1.622869e+15, error=1.622869e+15
n=379, result=1.622869e+15, error=1.622869e+15
n=380, result=1.622869e+15, error=1.622869e+15
n=381, result=1.622869e+15, error=1.622869e+15
n=382, result=1.622869e+15, error=1.622869e+15
n=383, result=1.622869e+15, error=1.622869e+15
n=384, result=1.622869e+15, error=1.622869e+15
n=385, result=1.622869e+15, error=1.622869e+15
n=386, result=1.622869e+15, error=1.622869e+15
n=387, result=1.622869e+15, error=1.622869e+15
n=388, result=1.622869e+15, error=1.622869e+15
n=389, result=1.622869e+15, error=1.622869e+15
n=390, result=1.622869e+15, error=1.622869e+15
n=391, result=1.622869e+15, error=1.622869e+15
n=392, result=1.622869e+15, error=1.622869e+15
n=393, result=1.622869e+15, error=1.622869e+15
n=394, result=1.622869e+15, error=1.622869e+15
n=395, result=1.622869e+15, error=1.622869e+15
n=396, result=1.622869e+15, error=1.622869e+15
n=397, result=1.622869e+15, error=1.622869e+15
n=398, result=1.622869e+15, error=1.622869e+15
n=399, result=1.622869e+15, error=1.622869e+15
n=400, result=1.622869e+15, error=1.622869e+15
n=401, result=1.622869e+15, error=1.622869e+15
n=402, result=1.622869e+15, error=1.622869e+15
n=403, result=1.622869e+15, error=1.622869e+15
n=404, result=1.622869e+15, error=1.622869e+15
n=405, result=1.622869e+15, error=1.622869e+15
n=406, result=1.622869e+15, error=1.622869e+15
n=407, result=1.622869e+15, error=1.622869e+15
n=408, result=1.622869e+15, error=1.622869e+15
n=409, result=1.622869e+15, error=1.622869e+15
n=410, result=1.622869e+15, error=1.622869e+15
n=411, result=1.622869e+15, error=1.622869e+15
n=412, result=1.622869e+15, error=1.622869e+15
n=413, result=1.622869e+15, error=1.622869e+15
n=414, result=1.622869e+15, error=1.622869e+15
n=415, result=1.622869e+15, error=1.622869e+15
n=416, result=1.622869e+15, error=1.622869e+15
n=417, result=1.622869e+15, error=1.622869e+15
n=418, result=1.622869e+15, error=1.622869e+15
n=419, result=1.622869e+15, error=1.622869e+15
n=420, result=1.622869e+15, error=1.622869e+15
n=421, result=1.622869e+15, error=1.622869e+15
n=422, result=1.622869e+15, error=1.622869e+15
n=423, result=1.622869e+15, error=1.622869e+15
n=424, result=1.622869e+15, error=1.622869e+15
n=425, result=1.622869e+15, error=1.622869e+15
n=426, result=1.622869e+15, error=1.622869e+15
n=427, result=1.622869e+15, error=1.622869e+15
n=428, result=1.622869e+15, error=1.622869e+15
n=429, result=1.622869e+15, error=1.622869e+15
n=430, result=1.622869e+15, error=1.622869e+15
n=431, result=1.622869e+15, error=1.622869e+15
n=432, result=1.622869e+15, error=1.622869e+15
n=433, result=1.622869e+15, error=1.622869e+15
n=434, result=1.622869e+15, error=1.622869e+15
n=435, result=1.622869e+15, error=1.622869e+15
n=436, result=1.622869e+15, error=1.622869e+15
n=437, result=1.622869e+15, error=1.622869e+15
n=438, result=1.622869e+15, error=1.622869e+15
n=439, result=1.622869e+15, error=1.622869e+15
n=440, result=1.622869e+15, error=1.622869e+15
n=441, result=1.622869e+15, error=1.622869e+15
n=442, result=1.622869e+15, error=1.622869e+15
n=443, result=1.622869e+15, error=1.622869e+15
n=444, result=1.622869e+15, error=1.622869e+15
n=445, result=1.622869e+15, error=1.622869e+15
n=446, result=1.622869e+15, error=1.622869e+15
n=447, result=1.622869e+15, error=1.622869e+15
n=448, result=1.622869e+15, error=1.622869e+15
n=449, result=1.622869e+15, error=1.622869e+15
n=450, result=1.622869e+15, error=1.622869e+15
n=451, result=1.622869e+15, error=1.622869e+15
n=452, result=1.622869e+15, error=1.622869e+15
n=453, result=1.622869e+15, error=1.622869e+15
n=454, result=1.622869e+15, error=1.622869e+15
n=455, result=1.622869e+15, error=1.622869e+15
n=456, result=1.622869e+15, error=1.622869e+15
n=457, result=1.622869e+15, error=1.622869e+15
n=458, result=1.622869e+15, error=1.622869e+15
n=459, result=1.622869e+15, error=1.622869e+15
n=460, result=1.622869e+15, error=1.622869e+15
n=461, result=1.622869e+15, error=1.622869e+15
n=462, result=1.622869e+15, error=1.622869e+15
n=463, result=1.622869e+15, error=1.622869e+15
n=464, result=1.622869e+15, error=1.622869e+15
n=465, result=1.622869e+15, error=1.622869e+15
n=466, result=1.622869e+15, error=1.622869e+15
n=467, result=1.622869e+15, error=1.622869e+15
n=468, result=1.622869e+15, error=1.622869e+15
n=469, result=1.622869e+15, error=1.622869e+15
n=470, result=1.622869e+15, error=1.622869e+15
n=471, result=1.622869e+15, error=1.622869e+15
n=472, result=1.622869e+15, error=1.622869e+15
n=473, result=1.622869e+15, error=1.622869e+15
n=474, result=1.622869e+15, error=1.622869e+15
n=475, result=1.622869e+15, error=1.622869e+15
n=476, result=1.622869e+15, error=1.622869e+15
n=477, result=1.622869e+15, error=1.622869e+15
n=478, result=1.622869e+15, error=1.622869e+15
n=479, result=1.622869e+15, error=1.622869e+15
n=480, result=1.622869e+15, error=1.622869e+15
n=481, result=1.622869e+15, error=1.622869e+15
n=482, result=1.622869e+15, error=1.622869e+15
n=483, result=1.622869e+15, error=1.622869e+15
n=484, result=1.622869e+15, error=1.622869e+15
n=485, result=1.622869e+15, error=1.622869e+15
n=486, result=1.622869e+15, error=1.622869e+15
n=487, result=1.622869e+15, error=1.622869e+15
n=488, result=1.622869e+15, error=1.622869e+15
n=489, result=1.622869e+15, error=1.622869e+15
n=490, result=1.622869e+15, error=1.622869e+15
n=491, result=1.622869e+15, error=1.622869e+15
n=492, result=1.622869e+15, error=1.622869e+15
n=493, result=1.622869e+15, error=1.622869e+15
n=494, result=1.622869e+15, error=1.622869e+15
n=495, result=1.622869e+15, error=1.622869e+15
n=496, result=1.622869e+15, error=1.622869e+15
n=497, result=1.622869e+15, error=1.622869e+15
n=498, result=1.622869e+15, error=1.622869e+15
n=499, result=1.622869e+15, error=1.622869e+15
n=500, result=1.622869e+15, error=1.622869e+15
n=501, result=1.622869e+15, error=1.622869e+15
n=502, result=1.622869e+15, error=1.622869e+15
n=503, result=1.622869e+15, error=1.622869e+15
n=504, result=1.622869e+15, error=1.622869e+15
n=505, result=1.622869e+15, error=1.622869e+15
n=506, result=1.622869e+15, error=1.622869e+15
n=507, result=1.622869e+15, error=1.622869e+15
n=508, result=1.622869e+15, error=1.622869e+15
n=509, result=1.622869e+15, error=1.622869e+15
n=510, result=1.622869e+15, error=1.622869e+15
n=511, result=1.622869e+15, error=1.622869e+15
n=512, result=1.622869e+15, error=1.622869e+15
n=513, result=1.622869e+15, error=1.622869e+15
n=514, result=1.622869e+15, error=1.622869e+15
n=515, result=1.622869e+15, error=1.622869e+15
n=516, result=1.622869e+15, error=1.622869e+15
n=517, result=1.622869e+15, error=1.622869e+15
n=518, result=1.622869e+15, error=1.622869e+15
n=519, result=1.622869e+15, error=1.622869e+15
n=520, result=1.622869e+15, error=1.622869e+15
n=521, result=1.622869e+15, error=1.622869e+15
n=522, result=1.622869e+15, error=1.622869e+15
n=523, result=1.622869e+15, error=1.622869e+15
n=524, result=1.622869e+15, error=1.622869e+15
n=525, result=1.622869e+15, error=1.622869e+15
n=526, result=1.622869e+15, error=1.622869e+15
n=527, result=1.622869e+15, error=1.622869e+15
n=528, result=1.622869e+15, error=1.622869e+15
n=529, result=1.622869e+15, error=1.622869e+15
n=530, result=1.622869e+15, error=1.622869e+15
n=531, result=1.622869e+15, error=1.622869e+15
n=532, result=1.622869e+15, error=1.622869e+15
n=533, result=1.622869e+15, error=1.622869e+15
n=534, result=1.622869e+15, error=1.622869e+15
n=535, result=1.622869e+15, error=1.622869e+15
n=536, result=1.622869e+15, error=1.622869e+15
n=537, result=1.622869e+15, error=1.622869e+15
n=538, result=1.622869e+15, error=1.622869e+15
n=539, result=1.622869e+15, error=1.622869e+15
n=540, result=1.622869e+15, error=1.622869e+15
n=541, result=1.622869e+15, error=1.622869e+15
n=542, result=1.622869e+15, error=1.622869e+15
n=543, result=1.622869e+15, error=1.622869e+15
n=544, result=1.622869e+15, error=1.622869e+15
n=545, result=1.622869e+15, error=1.622869e+15
n=546, result=1.622869e+15, error=1.622869e+15
n=547, result=1.622869e+15, error=1.622869e+15
n=548, result=1.622869e+15, error=1.622869e+15
n=549, result=1.622869e+15, error=1.622869e+15
n=550, result=1.622869e+15, error=1.622869e+15
n=551, result=1.622869e+15, error=1.622869e+15
n=552, result=1.622869e+15, error=1.622869e+15
n=553, result=1.622869e+15, error=1.622869e+15
n=554, result=1.622869e+15, error=1.622869e+15
n=555, result=1.622869e+15, error=1.622869e+15
n=556, result=1.622869e+15, error=1.622869e+15
n=557, result=1.622869e+15, error=1.622869e+15
n=558, result=1.622869e+15, error=1.622869e+15
n=559, result=1.622869e+15, error=1.622869e+15
n=560, result=1.622869e+15, error=1.622869e+15
n=561, result=1.622869e+15, error=1.622869e+15
n=562, result=1.622869e+15, error=1.622869e+15
n=563, result=1.622869e+15, error=1.622869e+15
n=564, result=1.622869e+15, error=1.622869e+15
n=565, result=1.622869e+15, error=1.622869e+15
n=566, result=1.622869e+15, error=1.622869e+15
n=567, result=1.622869e+15, error=1.622869e+15
n=568, result=1.622869e+15, error=1.622869e+15
n=569, result=1.622869e+15, error=1.622869e+15
n=570, result=1.622869e+15, error=1.622869e+15
n=571, result=1.622869e+15, error=1.622869e+15
n=572, result=1.622869e+15, error=1.622869e+15
n=573, result=1.622869e+15, error=1.622869e+15
n=574, result=1.622869e+15, error=1.622869e+15
n=575, result=1.622869e+15, error=1.622869e+15
n=576, result=1.622869e+15, error=1.622869e+15
n=577, result=1.622869e+15, error=1.622869e+15
n=578, result=1.622869e+15, error=1.622869e+15
n=579, result=1.622869e+15, error=1.622869e+15
n=580, result=1.622869e+15, error=1.622869e+15
n=581, result=1.622869e+15, error=1.622869e+15
n=582, result=1.622869e+15, error=1.622869e+15
n=583, result=1.622869e+15, error=1.622869e+15
n=584, result=1.622869e+15, error=1.622869e+15
n=585, result=1.622869e+15, error=1.622869e+15
n=586, result=1.622869e+15, error=1.622869e+15
n=587, result=1.622869e+15, error=1.622869e+15
n=588, result=1.622869e+15, error=1.622869e+15
n=589, result=1.622869e+15, error=1.622869e+15
n=590, result=1.622869e+15, error=1.622869e+15
n=591, result=1.622869e+15, error=1.622869e+15
n=592, result=1.622869e+15, error=1.622869e+15
n=593, result=1.622869e+15, error=1.622869e+15
n=594, result=1.622869e+15, error=1.622869e+15
n=595, result=1.622869e+15, error=1.622869e+15
n=596, result=1.622869e+15, error=1.622869e+15
n=597, result=1.622869e+15, error=1.622869e+15
n=598, result=1.622869e+15, error=1.622869e+15
n=599, result=1.622869e+15, error=1.622869e+15
n=600, result=1.622869e+15, error=1.622869e+15
n=601, result=1.622869e+15, error=1.622869e+15
n=602, result=1.622869e+15, error=1.622869e+15
n=603, result=1.622869e+15, error=1.622869e+15
n=604, result=1.622869e+15, error=1.622869e+15
n=605, result=1.622869e+15, error=1.622869e+15
n=606, result=1.622869e+15, error=1.622869e+15
n=607, result=1.622869e+15, error=1.622869e+15
n=608, result=1.622869e+15, error=1.622869e+15
n=609, result=1.622869e+15, error=1.622869e+15
n=610, result=1.622869e+15, error=1.622869e+15
n=611, result=1.622869e+15, error=1.622869e+15
n=612, result=1.622869e+15, error=1.622869e+15
n=613, result=1.622869e+15, error=1.622869e+15
n=614, result=1.622869e+15, error=1.622869e+15
n=615, result=1.622869e+15, error=1.622869e+15
n=616, result=1.622869e+15, error=1.622869e+15
n=617, result=1.622869e+15, error=1.622869e+15
n=618, result=1.622869e+15, error=1.622869e+15
n=619, result=1.622869e+15, error=1.622869e+15
n=620, result=1.622869e+15, error=1.622869e+15
n=621, result=1.622869e+15, error=1.622869e+15
n=622, result=1.622869e+15, error=1.622869e+15
n=623, result=1.622869e+15, error=1.622869e+15
n=624, result=1.622869e+15, error=1.622869e+15
n=625, result=1.622869e+15, error=1.622869e+15
n=626, result=1.622869e+15, error=1.622869e+15
n=627, result=1.622869e+15, error=1.622869e+15
n=628, result=1.622869e+15, error=1.622869e+15
n=629, result=1.622869e+15, error=1.622869e+15
n=630, result=1.622869e+15, error=1.622869e+15
n=631, result=1.622869e+15, error=1.622869e+15
n=632, result=1.622869e+15, error=1.622869e+15
n=633, result=1.622869e+15, error=1.622869e+15
n=634, result=1.622869e+15, error=1.622869e+15
n=635, result=1.622869e+15, error=1.622869e+15
n=636, result=1.622869e+15, error=1.622869e+15
n=637, result=1.622869e+15, error=1.622869e+15
n=638, result=1.622869e+15, error=1.622869e+15
n=639, result=1.622869e+15, error=1.622869e+15
n=640, result=1.622869e+15, error=1.622869e+15
n=641, result=1.622869e+15, error=1.622869e+15
n=642, result=1.622869e+15, error=1.622869e+15
n=643, result=1.622869e+15, error=1.622869e+15
n=644, result=1.622869e+15, error=1.622869e+15
n=645, result=1.622869e+15, error=1.622869e+15
n=646, result=1.622869e+15, error=1.622869e+15
n=647, result=1.622869e+15, error=1.622869e+15
n=648, result=1.622869e+15, error=1.622869e+15
n=649, result=1.622869e+15, error=1.622869e+15
n=650, result=1.622869e+15, error=1.622869e+15
n=651, result=1.622869e+15, error=1.622869e+15
n=652, result=1.622869e+15, error=1.622869e+15
n=653, result=1.622869e+15, error=1.622869e+15
n=654, result=1.622869e+15, error=1.622869e+15
n=655, result=1.622869e+15, error=1.622869e+15
n=656, result=1.622869e+15, error=1.622869e+15
n=657, result=1.622869e+15, error=1.622869e+15
n=658, result=1.622869e+15, error=1.622869e+15
n=659, result=1.622869e+15, error=1.622869e+15
n=660, result=1.622869e+15, error=1.622869e+15
n=661, result=1.622869e+15, error=1.622869e+15
n=662, result=1.622869e+15, error=1.622869e+15
n=663, result=1.622869e+15, error=1.622869e+15
n=664, result=1.622869e+15, error=1.622869e+15
n=665, result=1.622869e+15, error=1.622869e+15
n=666, result=1.622869e+15, error=1.622869e+15
n=667, result=1.622869e+15, error=1.622869e+15
n=668, result=1.622869e+15, error=1.622869e+15
n=669, result=1.622869e+15, error=1.622869e+15
n=670, result=1.622869e+15, error=1.622869e+15
n=671, result=1.622869e+15, error=1.622869e+15
n=672, result=1.622869e+15, error=1.622869e+15
n=673, result=1.622869e+15, error=1.622869e+15
n=674, result=1.622869e+15, error=1.622869e+15
n=675, result=1.622869e+15, error=1.622869e+15
n=676, result=1.622869e+15, error=1.622869e+15
n=677, result=1.622869e+15, error=1.622869e+15
n=678, result=1.622869e+15, error=1.622869e+15
n=679, result=1.622869e+15, error=1.622869e+15
n=680, result=1.622869e+15, error=1.622869e+15
n=681, result=1.622869e+15, error=1.622869e+15
n=682, result=1.622869e+15, error=1.622869e+15
n=683, result=1.622869e+15, error=1.622869e+15
n=684, result=1.622869e+15, error=1.622869e+15
n=685, result=1.622869e+15, error=1.622869e+15
n=686, result=1.622869e+15, error=1.622869e+15
n=687, result=1.622869e+15, error=1.622869e+15
n=688, result=1.622869e+15, error=1.622869e+15
n=689, result=1.622869e+15, error=1.622869e+15
n=690, result=1.622869e+15, error=1.622869e+15
n=691, result=1.622869e+15, error=1.622869e+15
n=692, result=1.622869e+15, error=1.622869e+15
n=693, result=1.622869e+15, error=1.622869e+15
n=694, result=1.622869e+15, error=1.622869e+15
n=695, result=1.622869e+15, error=1.622869e+15
n=696, result=1.622869e+15, error=1.622869e+15
n=697, result=1.622869e+15, error=1.622869e+15
n=698, result=1.622869e+15, error=1.622869e+15
n=699, result=1.622869e+15, error=1.622869e+15
n=700, result=1.622869e+15, error=1.622869e+15
n=701, result=1.622869e+15, error=1.622869e+15
n=702, result=1.622869e+15, error=1.622869e+15
n=703, result=1.622869e+15, error=1.622869e+15
n=704, result=1.622869e+15, error=1.622869e+15
n=705, result=1.622869e+15, error=1.622869e+15
n=706, result=1.622869e+15, error=1.622869e+15
n=707, result=1.622869e+15, error=1.622869e+15
n=708, result=1.622869e+15, error=1.622869e+15
n=709, result=1.622869e+15, error=1.622869e+15
n=710, result=1.622869e+15, error=1.622869e+15
n=711, result=1.622869e+15, error=1.622869e+15
n=712, result=1.622869e+15, error=1.622869e+15
n=713, result=1.622869e+15, error=1.622869e+15
n=714, result=1.622869e+15, error=1.622869e+15
n=715, result=1.622869e+15, error=1.622869e+15
n=716, result=1.622869e+15, error=1.622869e+15
n=717, result=1.622869e+15, error=1.622869e+15
n=718, result=1.622869e+15, error=1.622869e+15
n=719, result=1.622869e+15, error=1.622869e+15
n=720, result=1.622869e+15, error=1.622869e+15
n=721, result=1.622869e+15, error=1.622869e+15
n=722, result=1.622869e+15, error=1.622869e+15
n=723, result=1.622869e+15, error=1.622869e+15
n=724, result=1.622869e+15, error=1.622869e+15
n=725, result=1.622869e+15, error=1.622869e+15
n=726, result=1.622869e+15, error=1.622869e+15
n=727, result=1.622869e+15, error=1.622869e+15
n=728, result=1.622869e+15, error=1.622869e+15
n=729, result=1.622869e+15, error=1.622869e+15
n=730, result=1.622869e+15, error=1.622869e+15
n=731, result=1.622869e+15, error=1.622869e+15
n=732, result=1.622869e+15, error=1.622869e+15
n=733, result=1.622869e+15, error=1.622869e+15
n=734, result=1.622869e+15, error=1.622869e+15
n=735, result=1.622869e+15, error=1.622869e+15
n=736, result=1.622869e+15, error=1.622869e+15
n=737, result=1.622869e+15, error=1.622869e+15
n=738, result=1.622869e+15, error=1.622869e+15
n=739, result=1.622869e+15, error=1.622869e+15
n=740, result=1.622869e+15, error=1.622869e+15
n=741, result=1.622869e+15, error=1.622869e+15
n=742, result=1.622869e+15, error=1.622869e+15
n=743, result=1.622869e+15, error=1.622869e+15
n=744, result=1.622869e+15, error=1.622869e+15
n=745, result=1.622869e+15, error=1.622869e+15
n=746, result=1.622869e+15, error=1.622869e+15
n=747, result=1.622869e+15, error=1.622869e+15
n=748, result=1.622869e+15, error=1.622869e+15
n=749, result=1.622869e+15, error=1.622869e+15
n=750, result=1.622869e+15, error=1.622869e+15
n=751, result=1.622869e+15, error=1.622869e+15
n=752, result=1.622869e+15, error=1.622869e+15
n=753, result=1.622869e+15, error=1.622869e+15
n=754, result=1.622869e+15, error=1.622869e+15
n=755, result=1.622869e+15, error=1.622869e+15
n=756, result=1.622869e+15, error=1.622869e+15
n=757, result=1.622869e+15, error=1.622869e+15
n=758, result=1.622869e+15, error=1.622869e+15
n=759, result=1.622869e+15, error=1.622869e+15
n=760, result=1.622869e+15, error=1.622869e+15
n=761, result=1.622869e+15, error=1.622869e+15
n=762, result=1.622869e+15, error=1.622869e+15
n=763, result=1.622869e+15, error=1.622869e+15
n=764, result=1.622869e+15, error=1.622869e+15
n=765, result=1.622869e+15, error=1.622869e+15
n=766, result=1.622869e+15, error=1.622869e+15
n=767, result=1.622869e+15, error=1.622869e+15
n=768, result=1.622869e+15, error=1.622869e+15
n=769, result=1.622869e+15, error=1.622869e+15
n=770, result=1.622869e+15, error=1.622869e+15
n=771, result=1.622869e+15, error=1.622869e+15
n=772, result=1.622869e+15, error=1.622869e+15
n=773, result=1.622869e+15, error=1.622869e+15
n=774, result=1.622869e+15, error=1.622869e+15
n=775, result=1.622869e+15, error=1.622869e+15
n=776, result=1.622869e+15, error=1.622869e+15
n=777, result=1.622869e+15, error=1.622869e+15
n=778, result=1.622869e+15, error=1.622869e+15
n=779, result=1.622869e+15, error=1.622869e+15
n=780, result=1.622869e+15, error=1.622869e+15
n=781, result=1.622869e+15, error=1.622869e+15
n=782, result=1.622869e+15, error=1.622869e+15
n=783, result=1.622869e+15, error=1.622869e+15
n=784, result=1.622869e+15, error=1.622869e+15
n=785, result=1.622869e+15, error=1.622869e+15
n=786, result=1.622869e+15, error=1.622869e+15
n=787, result=1.622869e+15, error=1.622869e+15
n=788, result=1.622869e+15, error=1.622869e+15
n=789, result=1.622869e+15, error=1.622869e+15
n=790, result=1.622869e+15, error=1.622869e+15
n=791, result=1.622869e+15, error=1.622869e+15
n=792, result=1.622869e+15, error=1.622869e+15
n=793, result=1.622869e+15, error=1.622869e+15
n=794, result=1.622869e+15, error=1.622869e+15
n=795, result=1.622869e+15, error=1.622869e+15
n=796, result=1.622869e+15, error=1.622869e+15
n=797, result=1.622869e+15, error=1.622869e+15
n=798, result=1.622869e+15, error=1.622869e+15
n=799, result=1.622869e+15, error=1.622869e+15
n=800, result=1.622869e+15, error=1.622869e+15
n=801, result=1.622869e+15, error=1.622869e+15
n=802, result=1.622869e+15, error=1.622869e+15
n=803, result=1.622869e+15, error=1.622869e+15
n=804, result=1.622869e+15, error=1.622869e+15
n=805, result=1.622869e+15, error=1.622869e+15
n=806, result=1.622869e+15, error=1.622869e+15
n=807, result=1.622869e+15, error=1.622869e+15
n=808, result=1.622869e+15, error=1.622869e+15
n=809, result=1.622869e+15, error=1.622869e+15
n=810, result=1.622869e+15, error=1.622869e+15
n=811, result=1.622869e+15, error=1.622869e+15
n=812, result=1.622869e+15, error=1.622869e+15
n=813, result=1.622869e+15, error=1.622869e+15
n=814, result=1.622869e+15, error=1.622869e+15
n=815, result=1.622869e+15, error=1.622869e+15
n=816, result=1.622869e+15, error=1.622869e+15
n=817, result=1.622869e+15, error=1.622869e+15
n=818, result=1.622869e+15, error=1.622869e+15
n=819, result=1.622869e+15, error=1.622869e+15
n=820, result=1.622869e+15, error=1.622869e+15
n=821, result=1.622869e+15, error=1.622869e+15
n=822, result=1.622869e+15, error=1.622869e+15
n=823, result=1.622869e+15, error=1.622869e+15
n=824, result=1.622869e+15, error=1.622869e+15
n=825, result=1.622869e+15, error=1.622869e+15
n=826, result=1.622869e+15, error=1.622869e+15
n=827, result=1.622869e+15, error=1.622869e+15
n=828, result=1.622869e+15, error=1.622869e+15
n=829, result=1.622869e+15, error=1.622869e+15
n=830, result=1.622869e+15, error=1.622869e+15
n=831, result=1.622869e+15, error=1.622869e+15
n=832, result=1.622869e+15, error=1.622869e+15
n=833, result=1.622869e+15, error=1.622869e+15
n=834, result=1.622869e+15, error=1.622869e+15
n=835, result=1.622869e+15, error=1.622869e+15
n=836, result=1.622869e+15, error=1.622869e+15
n=837, result=1.622869e+15, error=1.622869e+15
n=838, result=1.622869e+15, error=1.622869e+15
n=839, result=1.622869e+15, error=1.622869e+15
n=840, result=1.622869e+15, error=1.622869e+15
n=841, result=1.622869e+15, error=1.622869e+15
n=842, result=1.622869e+15, error=1.622869e+15
n=843, result=1.622869e+15, error=1.622869e+15
n=844, result=1.622869e+15, error=1.622869e+15
n=845, result=1.622869e+15, error=1.622869e+15
n=846, result=1.622869e+15, error=1.622869e+15
n=847, result=1.622869e+15, error=1.622869e+15
n=848, result=1.622869e+15, error=1.622869e+15
n=849, result=1.622869e+15, error=1.622869e+15
n=850, result=1.622869e+15, error=1.622869e+15
n=851, result=1.622869e+15, error=1.622869e+15
n=852, result=1.622869e+15, error=1.622869e+15
n=853, result=1.622869e+15, error=1.622869e+15
n=854, result=1.622869e+15, error=1.622869e+15
n=855, result=1.622869e+15, error=1.622869e+15
n=856, result=1.622869e+15, error=1.622869e+15
n=857, result=1.622869e+15, error=1.622869e+15
n=858, result=1.622869e+15, error=1.622869e+15
n=859, result=1.622869e+15, error=1.622869e+15
n=860, result=1.622869e+15, error=1.622869e+15
n=861, result=1.622869e+15, error=1.622869e+15
n=862, result=1.622869e+15, error=1.622869e+15
n=863, result=1.622869e+15, error=1.622869e+15
n=864, result=1.622869e+15, error=1.622869e+15
n=865, result=1.622869e+15, error=1.622869e+15
n=866, result=1.622869e+15, error=1.622869e+15
n=867, result=1.622869e+15, error=1.622869e+15
n=868, result=1.622869e+15, error=1.622869e+15
n=869, result=1.622869e+15, error=1.622869e+15
n=870, result=1.622869e+15, error=1.622869e+15
n=871, result=1.622869e+15, error=1.622869e+15
n=872, result=1.622869e+15, error=1.622869e+15
n=873, result=1.622869e+15, error=1.622869e+15
n=874, result=1.622869e+15, error=1.622869e+15
n=875, result=1.622869e+15, error=1.622869e+15
n=876, result=1.622869e+15, error=1.622869e+15
n=877, result=1.622869e+15, error=1.622869e+15
n=878, result=1.622869e+15, error=1.622869e+15
n=879, result=1.622869e+15, error=1.622869e+15
n=880, result=1.622869e+15, error=1.622869e+15
n=881, result=1.622869e+15, error=1.622869e+15
n=882, result=1.622869e+15, error=1.622869e+15
n=883, result=1.622869e+15, error=1.622869e+15
n=884, result=1.622869e+15, error=1.622869e+15
n=885, result=1.622869e+15, error=1.622869e+15
n=886, result=1.622869e+15, error=1.622869e+15
n=887, result=1.622869e+15, error=1.622869e+15
n=888, result=1.622869e+15, error=1.622869e+15
n=889, result=1.622869e+15, error=1.622869e+15
n=890, result=1.622869e+15, error=1.622869e+15
n=891, result=1.622869e+15, error=1.622869e+15
n=892, result=1.622869e+15, error=1.622869e+15
n=893, result=1.622869e+15, error=1.622869e+15
n=894, result=1.622869e+15, error=1.622869e+15
n=895, result=1.622869e+15, error=1.622869e+15
n=896, result=1.622869e+15, error=1.622869e+15
n=897, result=1.622869e+15, error=1.622869e+15
n=898, result=1.622869e+15, error=1.622869e+15
n=899, result=1.622869e+15, error=1.622869e+15
n=900, result=1.622869e+15, error=1.622869e+15
n=901, result=1.622869e+15, error=1.622869e+15
n=902, result=1.622869e+15, error=1.622869e+15
n=903, result=1.622869e+15, error=1.622869e+15
n=904, result=1.622869e+15, error=1.622869e+15
n=905, result=1.622869e+15, error=1.622869e+15
n=906, result=1.622869e+15, error=1.622869e+15
n=907, result=1.622869e+15, error=1.622869e+15
n=908, result=1.622869e+15, error=1.622869e+15
n=909, result=1.622869e+15, error=1.622869e+15
n=910, result=1.622869e+15, error=1.622869e+15
n=911, result=1.622869e+15, error=1.622869e+15
n=912, result=1.622869e+15, error=1.622869e+15
n=913, result=1.622869e+15, error=1.622869e+15
n=914, result=1.622869e+15, error=1.622869e+15
n=915, result=1.622869e+15, error=1.622869e+15
n=916, result=1.622869e+15, error=1.622869e+15
n=917, result=1.622869e+15, error=1.622869e+15
n=918, result=1.622869e+15, error=1.622869e+15
n=919, result=1.622869e+15, error=1.622869e+15
n=920, result=1.622869e+15, error=1.622869e+15
n=921, result=1.622869e+15, error=1.622869e+15
n=922, result=1.622869e+15, error=1.622869e+15
n=923, result=1.622869e+15, error=1.622869e+15
n=924, result=1.622869e+15, error=1.622869e+15
n=925, result=1.622869e+15, error=1.622869e+15
n=926, result=1.622869e+15, error=1.622869e+15
n=927, result=1.622869e+15, error=1.622869e+15
n=928, result=1.622869e+15, error=1.622869e+15
n=929, result=1.622869e+15, error=1.622869e+15
n=930, result=1.622869e+15, error=1.622869e+15
n=931, result=1.622869e+15, error=1.622869e+15
n=932, result=1.622869e+15, error=1.622869e+15
n=933, result=1.622869e+15, error=1.622869e+15
n=934, result=1.622869e+15, error=1.622869e+15
n=935, result=1.622869e+15, error=1.622869e+15
n=936, result=1.622869e+15, error=1.622869e+15
n=937, result=1.622869e+15, error=1.622869e+15
n=938, result=1.622869e+15, error=1.622869e+15
n=939, result=1.622869e+15, error=1.622869e+15
n=940, result=1.622869e+15, error=1.622869e+15
n=941, result=1.622869e+15, error=1.622869e+15
n=942, result=1.622869e+15, error=1.622869e+15
n=943, result=1.622869e+15, error=1.622869e+15
n=944, result=1.622869e+15, error=1.622869e+15
n=945, result=1.622869e+15, error=1.622869e+15
n=946, result=1.622869e+15, error=1.622869e+15
n=947, result=1.622869e+15, error=1.622869e+15
n=948, result=1.622869e+15, error=1.622869e+15
n=949, result=1.622869e+15, error=1.622869e+15
n=950, result=1.622869e+15, error=1.622869e+15
n=951, result=1.622869e+15, error=1.622869e+15
n=952, result=1.622869e+15, error=1.622869e+15
n=953, result=1.622869e+15, error=1.622869e+15
n=954, result=1.622869e+15, error=1.622869e+15
n=955, result=1.622869e+15, error=1.622869e+15
n=956, result=1.622869e+15, error=1.622869e+15
n=957, result=1.622869e+15, error=1.622869e+15
n=958, result=1.622869e+15, error=1.622869e+15
n=959, result=1.622869e+15, error=1.622869e+15
n=960, result=1.622869e+15, error=1.622869e+15
n=961, result=1.622869e+15, error=1.622869e+15
n=962, result=1.622869e+15, error=1.622869e+15
n=963, result=1.622869e+15, error=1.622869e+15
n=964, result=1.622869e+15, error=1.622869e+15
n=965, result=1.622869e+15, error=1.622869e+15
n=966, result=1.622869e+15, error=1.622869e+15
n=967, result=1.622869e+15, error=1.622869e+15
n=968, result=1.622869e+15, error=1.622869e+15
n=969, result=1.622869e+15, error=1.622869e+15
n=970, result=1.622869e+15, error=1.622869e+15
n=971, result=1.622869e+15, error=1.622869e+15
n=972, result=1.622869e+15, error=1.622869e+15
n=973, result=1.622869e+15, error=1.622869e+15
n=974, result=1.622869e+15, error=1.622869e+15
n=975, result=1.622869e+15, error=1.622869e+15
n=976, result=1.622869e+15, error=1.622869e+15
n=977, result=1.622869e+15, error=1.622869e+15
n=978, result=1.622869e+15, error=1.622869e+15
n=979, result=1.622869e+15, error=1.622869e+15
n=980, result=1.622869e+15, error=1.622869e+15
n=981, result=1.622869e+15, error=1.622869e+15
n=982, result=1.622869e+15, error=1.622869e+15
n=983, result=1.622869e+15, error=1.622869e+15
n=984, result=1.622869e+15, error=1.622869e+15
n=985, result=1.622869e+15, error=1.622869e+15
n=986, result=1.622869e+15, error=1.622869e+15
n=987, result=1.622869e+15, error=1.622869e+15
n=988, result=1.622869e+15, error=1.622869e+15
n=989, result=1.622869e+15, error=1.622869e+15
n=990, result=1.622869e+15, error=1.622869e+15
n=991, result=1.622869e+15, error=1.622869e+15
n=992, result=1.622869e+15, error=1.622869e+15
n=993, result=1.622869e+15, error=1.622869e+15
n=994, result=1.622869e+15, error=1.622869e+15
n=995, result=1.622869e+15, error=1.622869e+15
n=996, result=1.622869e+15, error=1.622869e+15
n=997, result=1.622869e+15, error=1.622869e+15
n=998, result=1.622869e+15, error=1.622869e+15
n=999, result=1.622869e+15, error=1.622869e+15
library(pracma)
a = 5
b = 3
n = 4
f = function(x) {
  x*a*b*(x^a-1)*(1-x^a)^b-1  
} 
#### gauss quadrature ####
xs = seq(0, 1, length.out = 101)
ys = f(xs)
## cara 1
exact_value=0.886207
tol <-  0.0001
err <- 1
while(err>tol){
  gL <- gaussLegendre(n = n,a = 0,3)
  Ci <- gL$w # koefisien
  xi <- gL$x # gauss point
  res_gl <- sum(Ci * f(xi))
  err <- abs(res_gl-exact_value)
  cat("n=",n,", result=",res_gl,", error=",err,"\n",sep = "")
  n=n+1
  if(n==10){
    break
  }
}
n=4, result=-17672833407, error=17672833408
n=5, result=-20337395882, error=20337395882
n=6, result=-20877023407, error=20877023408
n=7, result=-20940117401, error=20940117401
n=8, result=-20944218445, error=20944218446
n=9, result=-20944353455, error=20944353456

Soal 2:


library(pracma)
a = 5
b = 3
n = 100
lambda = 2
exact_value = 0.886207
tol <-  0.0001
err <- 1
f = function(x) {
  lambda*exp(-lambda*x)  
} 
#### trapezoida ####
trapezoid <- function(ftn, a, b, n = 100) {
     h <- (b-a)/n
     x.vec <- seq(a, b, by = h)
     f.vec <- sapply(x.vec, ftn)     # ftn(x.vec)
     Trap <- h*(f.vec[1]/2 + sum(f.vec[2:n]) + f.vec[n+1]/2)
     return(Trap)
}
while(err>tol){
  res_trap <- trapezoid(f,a,b,n = n)
  err <- abs(res_trap-exact_value)
  cat("n=",n,", result=",res_trap,", error=",err,"\n",sep = "")
  n=n+1
  if(n==1000){
    break
  }
}
n=100, result=-0.002433677, error=0.8886407
n=101, result=-0.00243367, error=0.8886407
n=102, result=-0.002433664, error=0.8886407
n=103, result=-0.002433658, error=0.8886407
n=104, result=-0.002433652, error=0.8886407
n=105, result=-0.002433647, error=0.8886406
n=106, result=-0.002433641, error=0.8886406
n=107, result=-0.002433636, error=0.8886406
n=108, result=-0.00243363, error=0.8886406
n=109, result=-0.002433625, error=0.8886406
n=110, result=-0.00243362, error=0.8886406
n=111, result=-0.002433616, error=0.8886406
n=112, result=-0.002433611, error=0.8886406
n=113, result=-0.002433606, error=0.8886406
n=114, result=-0.002433602, error=0.8886406
n=115, result=-0.002433598, error=0.8886406
n=116, result=-0.002433593, error=0.8886406
n=117, result=-0.002433589, error=0.8886406
n=118, result=-0.002433585, error=0.8886406
n=119, result=-0.002433581, error=0.8886406
n=120, result=-0.002433578, error=0.8886406
n=121, result=-0.002433574, error=0.8886406
n=122, result=-0.00243357, error=0.8886406
n=123, result=-0.002433567, error=0.8886406
n=124, result=-0.002433563, error=0.8886406
n=125, result=-0.00243356, error=0.8886406
n=126, result=-0.002433557, error=0.8886406
n=127, result=-0.002433553, error=0.8886406
n=128, result=-0.00243355, error=0.8886406
n=129, result=-0.002433547, error=0.8886405
n=130, result=-0.002433544, error=0.8886405
n=131, result=-0.002433541, error=0.8886405
n=132, result=-0.002433538, error=0.8886405
n=133, result=-0.002433536, error=0.8886405
n=134, result=-0.002433533, error=0.8886405
n=135, result=-0.00243353, error=0.8886405
n=136, result=-0.002433528, error=0.8886405
n=137, result=-0.002433525, error=0.8886405
n=138, result=-0.002433523, error=0.8886405
n=139, result=-0.00243352, error=0.8886405
n=140, result=-0.002433518, error=0.8886405
n=141, result=-0.002433515, error=0.8886405
n=142, result=-0.002433513, error=0.8886405
n=143, result=-0.002433511, error=0.8886405
n=144, result=-0.002433509, error=0.8886405
n=145, result=-0.002433507, error=0.8886405
n=146, result=-0.002433504, error=0.8886405
n=147, result=-0.002433502, error=0.8886405
n=148, result=-0.0024335, error=0.8886405
n=149, result=-0.002433498, error=0.8886405
n=150, result=-0.002433496, error=0.8886405
n=151, result=-0.002433495, error=0.8886405
n=152, result=-0.002433493, error=0.8886405
n=153, result=-0.002433491, error=0.8886405
n=154, result=-0.002433489, error=0.8886405
n=155, result=-0.002433487, error=0.8886405
n=156, result=-0.002433486, error=0.8886405
n=157, result=-0.002433484, error=0.8886405
n=158, result=-0.002433482, error=0.8886405
n=159, result=-0.002433481, error=0.8886405
n=160, result=-0.002433479, error=0.8886405
n=161, result=-0.002433477, error=0.8886405
n=162, result=-0.002433476, error=0.8886405
n=163, result=-0.002433474, error=0.8886405
n=164, result=-0.002433473, error=0.8886405
n=165, result=-0.002433471, error=0.8886405
n=166, result=-0.00243347, error=0.8886405
n=167, result=-0.002433469, error=0.8886405
n=168, result=-0.002433467, error=0.8886405
n=169, result=-0.002433466, error=0.8886405
n=170, result=-0.002433465, error=0.8886405
n=171, result=-0.002433463, error=0.8886405
n=172, result=-0.002433462, error=0.8886405
n=173, result=-0.002433461, error=0.8886405
n=174, result=-0.002433459, error=0.8886405
n=175, result=-0.002433458, error=0.8886405
n=176, result=-0.002433457, error=0.8886405
n=177, result=-0.002433456, error=0.8886405
n=178, result=-0.002433455, error=0.8886405
n=179, result=-0.002433454, error=0.8886405
n=180, result=-0.002433452, error=0.8886405
n=181, result=-0.002433451, error=0.8886405
n=182, result=-0.00243345, error=0.8886405
n=183, result=-0.002433449, error=0.8886404
n=184, result=-0.002433448, error=0.8886404
n=185, result=-0.002433447, error=0.8886404
n=186, result=-0.002433446, error=0.8886404
n=187, result=-0.002433445, error=0.8886404
n=188, result=-0.002433444, error=0.8886404
n=189, result=-0.002433443, error=0.8886404
n=190, result=-0.002433442, error=0.8886404
n=191, result=-0.002433441, error=0.8886404
n=192, result=-0.00243344, error=0.8886404
n=193, result=-0.002433439, error=0.8886404
n=194, result=-0.002433438, error=0.8886404
n=195, result=-0.002433438, error=0.8886404
n=196, result=-0.002433437, error=0.8886404
n=197, result=-0.002433436, error=0.8886404
n=198, result=-0.002433435, error=0.8886404
n=199, result=-0.002433434, error=0.8886404
n=200, result=-0.002433433, error=0.8886404
n=201, result=-0.002433433, error=0.8886404
n=202, result=-0.002433432, error=0.8886404
n=203, result=-0.002433431, error=0.8886404
n=204, result=-0.00243343, error=0.8886404
n=205, result=-0.002433429, error=0.8886404
n=206, result=-0.002433429, error=0.8886404
n=207, result=-0.002433428, error=0.8886404
n=208, result=-0.002433427, error=0.8886404
n=209, result=-0.002433427, error=0.8886404
n=210, result=-0.002433426, error=0.8886404
n=211, result=-0.002433425, error=0.8886404
n=212, result=-0.002433424, error=0.8886404
n=213, result=-0.002433424, error=0.8886404
n=214, result=-0.002433423, error=0.8886404
n=215, result=-0.002433422, error=0.8886404
n=216, result=-0.002433422, error=0.8886404
n=217, result=-0.002433421, error=0.8886404
n=218, result=-0.002433421, error=0.8886404
n=219, result=-0.00243342, error=0.8886404
n=220, result=-0.002433419, error=0.8886404
n=221, result=-0.002433419, error=0.8886404
n=222, result=-0.002433418, error=0.8886404
n=223, result=-0.002433417, error=0.8886404
n=224, result=-0.002433417, error=0.8886404
n=225, result=-0.002433416, error=0.8886404
n=226, result=-0.002433416, error=0.8886404
n=227, result=-0.002433415, error=0.8886404
n=228, result=-0.002433415, error=0.8886404
n=229, result=-0.002433414, error=0.8886404
n=230, result=-0.002433414, error=0.8886404
n=231, result=-0.002433413, error=0.8886404
n=232, result=-0.002433413, error=0.8886404
n=233, result=-0.002433412, error=0.8886404
n=234, result=-0.002433411, error=0.8886404
n=235, result=-0.002433411, error=0.8886404
n=236, result=-0.00243341, error=0.8886404
n=237, result=-0.00243341, error=0.8886404
n=238, result=-0.00243341, error=0.8886404
n=239, result=-0.002433409, error=0.8886404
n=240, result=-0.002433409, error=0.8886404
n=241, result=-0.002433408, error=0.8886404
n=242, result=-0.002433408, error=0.8886404
n=243, result=-0.002433407, error=0.8886404
n=244, result=-0.002433407, error=0.8886404
n=245, result=-0.002433406, error=0.8886404
n=246, result=-0.002433406, error=0.8886404
n=247, result=-0.002433405, error=0.8886404
n=248, result=-0.002433405, error=0.8886404
n=249, result=-0.002433405, error=0.8886404
n=250, result=-0.002433404, error=0.8886404
n=251, result=-0.002433404, error=0.8886404
n=252, result=-0.002433403, error=0.8886404
n=253, result=-0.002433403, error=0.8886404
n=254, result=-0.002433403, error=0.8886404
n=255, result=-0.002433402, error=0.8886404
n=256, result=-0.002433402, error=0.8886404
n=257, result=-0.002433401, error=0.8886404
n=258, result=-0.002433401, error=0.8886404
n=259, result=-0.002433401, error=0.8886404
n=260, result=-0.0024334, error=0.8886404
n=261, result=-0.0024334, error=0.8886404
n=262, result=-0.0024334, error=0.8886404
n=263, result=-0.002433399, error=0.8886404
n=264, result=-0.002433399, error=0.8886404
n=265, result=-0.002433398, error=0.8886404
n=266, result=-0.002433398, error=0.8886404
n=267, result=-0.002433398, error=0.8886404
n=268, result=-0.002433397, error=0.8886404
n=269, result=-0.002433397, error=0.8886404
n=270, result=-0.002433397, error=0.8886404
n=271, result=-0.002433396, error=0.8886404
n=272, result=-0.002433396, error=0.8886404
n=273, result=-0.002433396, error=0.8886404
n=274, result=-0.002433395, error=0.8886404
n=275, result=-0.002433395, error=0.8886404
n=276, result=-0.002433395, error=0.8886404
n=277, result=-0.002433395, error=0.8886404
n=278, result=-0.002433394, error=0.8886404
n=279, result=-0.002433394, error=0.8886404
n=280, result=-0.002433394, error=0.8886404
n=281, result=-0.002433393, error=0.8886404
n=282, result=-0.002433393, error=0.8886404
n=283, result=-0.002433393, error=0.8886404
n=284, result=-0.002433392, error=0.8886404
n=285, result=-0.002433392, error=0.8886404
n=286, result=-0.002433392, error=0.8886404
n=287, result=-0.002433392, error=0.8886404
n=288, result=-0.002433391, error=0.8886404
n=289, result=-0.002433391, error=0.8886404
n=290, result=-0.002433391, error=0.8886404
n=291, result=-0.002433391, error=0.8886404
n=292, result=-0.00243339, error=0.8886404
n=293, result=-0.00243339, error=0.8886404
n=294, result=-0.00243339, error=0.8886404
n=295, result=-0.00243339, error=0.8886404
n=296, result=-0.002433389, error=0.8886404
n=297, result=-0.002433389, error=0.8886404
n=298, result=-0.002433389, error=0.8886404
n=299, result=-0.002433389, error=0.8886404
n=300, result=-0.002433388, error=0.8886404
n=301, result=-0.002433388, error=0.8886404
n=302, result=-0.002433388, error=0.8886404
n=303, result=-0.002433388, error=0.8886404
n=304, result=-0.002433387, error=0.8886404
n=305, result=-0.002433387, error=0.8886404
n=306, result=-0.002433387, error=0.8886404
n=307, result=-0.002433387, error=0.8886404
n=308, result=-0.002433386, error=0.8886404
n=309, result=-0.002433386, error=0.8886404
n=310, result=-0.002433386, error=0.8886404
n=311, result=-0.002433386, error=0.8886404
n=312, result=-0.002433386, error=0.8886404
n=313, result=-0.002433385, error=0.8886404
n=314, result=-0.002433385, error=0.8886404
n=315, result=-0.002433385, error=0.8886404
n=316, result=-0.002433385, error=0.8886404
n=317, result=-0.002433385, error=0.8886404
n=318, result=-0.002433384, error=0.8886404
n=319, result=-0.002433384, error=0.8886404
n=320, result=-0.002433384, error=0.8886404
n=321, result=-0.002433384, error=0.8886404
n=322, result=-0.002433384, error=0.8886404
n=323, result=-0.002433383, error=0.8886404
n=324, result=-0.002433383, error=0.8886404
n=325, result=-0.002433383, error=0.8886404
n=326, result=-0.002433383, error=0.8886404
n=327, result=-0.002433383, error=0.8886404
n=328, result=-0.002433382, error=0.8886404
n=329, result=-0.002433382, error=0.8886404
n=330, result=-0.002433382, error=0.8886404
n=331, result=-0.002433382, error=0.8886404
n=332, result=-0.002433382, error=0.8886404
n=333, result=-0.002433382, error=0.8886404
n=334, result=-0.002433381, error=0.8886404
n=335, result=-0.002433381, error=0.8886404
n=336, result=-0.002433381, error=0.8886404
n=337, result=-0.002433381, error=0.8886404
n=338, result=-0.002433381, error=0.8886404
n=339, result=-0.00243338, error=0.8886404
n=340, result=-0.00243338, error=0.8886404
n=341, result=-0.00243338, error=0.8886404
n=342, result=-0.00243338, error=0.8886404
n=343, result=-0.00243338, error=0.8886404
n=344, result=-0.00243338, error=0.8886404
n=345, result=-0.00243338, error=0.8886404
n=346, result=-0.002433379, error=0.8886404
n=347, result=-0.002433379, error=0.8886404
n=348, result=-0.002433379, error=0.8886404
n=349, result=-0.002433379, error=0.8886404
n=350, result=-0.002433379, error=0.8886404
n=351, result=-0.002433379, error=0.8886404
n=352, result=-0.002433378, error=0.8886404
n=353, result=-0.002433378, error=0.8886404
n=354, result=-0.002433378, error=0.8886404
n=355, result=-0.002433378, error=0.8886404
n=356, result=-0.002433378, error=0.8886404
n=357, result=-0.002433378, error=0.8886404
n=358, result=-0.002433378, error=0.8886404
n=359, result=-0.002433377, error=0.8886404
n=360, result=-0.002433377, error=0.8886404
n=361, result=-0.002433377, error=0.8886404
n=362, result=-0.002433377, error=0.8886404
n=363, result=-0.002433377, error=0.8886404
n=364, result=-0.002433377, error=0.8886404
n=365, result=-0.002433377, error=0.8886404
n=366, result=-0.002433376, error=0.8886404
n=367, result=-0.002433376, error=0.8886404
n=368, result=-0.002433376, error=0.8886404
n=369, result=-0.002433376, error=0.8886404
n=370, result=-0.002433376, error=0.8886404
n=371, result=-0.002433376, error=0.8886404
n=372, result=-0.002433376, error=0.8886404
n=373, result=-0.002433376, error=0.8886404
n=374, result=-0.002433375, error=0.8886404
n=375, result=-0.002433375, error=0.8886404
n=376, result=-0.002433375, error=0.8886404
n=377, result=-0.002433375, error=0.8886404
n=378, result=-0.002433375, error=0.8886404
n=379, result=-0.002433375, error=0.8886404
n=380, result=-0.002433375, error=0.8886404
n=381, result=-0.002433375, error=0.8886404
n=382, result=-0.002433374, error=0.8886404
n=383, result=-0.002433374, error=0.8886404
n=384, result=-0.002433374, error=0.8886404
n=385, result=-0.002433374, error=0.8886404
n=386, result=-0.002433374, error=0.8886404
n=387, result=-0.002433374, error=0.8886404
n=388, result=-0.002433374, error=0.8886404
n=389, result=-0.002433374, error=0.8886404
n=390, result=-0.002433374, error=0.8886404
n=391, result=-0.002433373, error=0.8886404
n=392, result=-0.002433373, error=0.8886404
n=393, result=-0.002433373, error=0.8886404
n=394, result=-0.002433373, error=0.8886404
n=395, result=-0.002433373, error=0.8886404
n=396, result=-0.002433373, error=0.8886404
n=397, result=-0.002433373, error=0.8886404
n=398, result=-0.002433373, error=0.8886404
n=399, result=-0.002433373, error=0.8886404
n=400, result=-0.002433373, error=0.8886404
n=401, result=-0.002433372, error=0.8886404
n=402, result=-0.002433372, error=0.8886404
n=403, result=-0.002433372, error=0.8886404
n=404, result=-0.002433372, error=0.8886404
n=405, result=-0.002433372, error=0.8886404
n=406, result=-0.002433372, error=0.8886404
n=407, result=-0.002433372, error=0.8886404
n=408, result=-0.002433372, error=0.8886404
n=409, result=-0.002433372, error=0.8886404
n=410, result=-0.002433372, error=0.8886404
n=411, result=-0.002433371, error=0.8886404
n=412, result=-0.002433371, error=0.8886404
n=413, result=-0.002433371, error=0.8886404
n=414, result=-0.002433371, error=0.8886404
n=415, result=-0.002433371, error=0.8886404
n=416, result=-0.002433371, error=0.8886404
n=417, result=-0.002433371, error=0.8886404
n=418, result=-0.002433371, error=0.8886404
n=419, result=-0.002433371, error=0.8886404
n=420, result=-0.002433371, error=0.8886404
n=421, result=-0.002433371, error=0.8886404
n=422, result=-0.00243337, error=0.8886404
n=423, result=-0.00243337, error=0.8886404
n=424, result=-0.00243337, error=0.8886404
n=425, result=-0.00243337, error=0.8886404
n=426, result=-0.00243337, error=0.8886404
n=427, result=-0.00243337, error=0.8886404
n=428, result=-0.00243337, error=0.8886404
n=429, result=-0.00243337, error=0.8886404
n=430, result=-0.00243337, error=0.8886404
n=431, result=-0.00243337, error=0.8886404
n=432, result=-0.00243337, error=0.8886404
n=433, result=-0.00243337, error=0.8886404
n=434, result=-0.002433369, error=0.8886404
n=435, result=-0.002433369, error=0.8886404
n=436, result=-0.002433369, error=0.8886404
n=437, result=-0.002433369, error=0.8886404
n=438, result=-0.002433369, error=0.8886404
n=439, result=-0.002433369, error=0.8886404
n=440, result=-0.002433369, error=0.8886404
n=441, result=-0.002433369, error=0.8886404
n=442, result=-0.002433369, error=0.8886404
n=443, result=-0.002433369, error=0.8886404
n=444, result=-0.002433369, error=0.8886404
n=445, result=-0.002433369, error=0.8886404
n=446, result=-0.002433369, error=0.8886404
n=447, result=-0.002433368, error=0.8886404
n=448, result=-0.002433368, error=0.8886404
n=449, result=-0.002433368, error=0.8886404
n=450, result=-0.002433368, error=0.8886404
n=451, result=-0.002433368, error=0.8886404
n=452, result=-0.002433368, error=0.8886404
n=453, result=-0.002433368, error=0.8886404
n=454, result=-0.002433368, error=0.8886404
n=455, result=-0.002433368, error=0.8886404
n=456, result=-0.002433368, error=0.8886404
n=457, result=-0.002433368, error=0.8886404
n=458, result=-0.002433368, error=0.8886404
n=459, result=-0.002433368, error=0.8886404
n=460, result=-0.002433368, error=0.8886404
n=461, result=-0.002433368, error=0.8886404
n=462, result=-0.002433367, error=0.8886404
n=463, result=-0.002433367, error=0.8886404
n=464, result=-0.002433367, error=0.8886404
n=465, result=-0.002433367, error=0.8886404
n=466, result=-0.002433367, error=0.8886404
n=467, result=-0.002433367, error=0.8886404
n=468, result=-0.002433367, error=0.8886404
n=469, result=-0.002433367, error=0.8886404
n=470, result=-0.002433367, error=0.8886404
n=471, result=-0.002433367, error=0.8886404
n=472, result=-0.002433367, error=0.8886404
n=473, result=-0.002433367, error=0.8886404
n=474, result=-0.002433367, error=0.8886404
n=475, result=-0.002433367, error=0.8886404
n=476, result=-0.002433367, error=0.8886404
n=477, result=-0.002433367, error=0.8886404
n=478, result=-0.002433366, error=0.8886404
n=479, result=-0.002433366, error=0.8886404
n=480, result=-0.002433366, error=0.8886404
n=481, result=-0.002433366, error=0.8886404
n=482, result=-0.002433366, error=0.8886404
n=483, result=-0.002433366, error=0.8886404
n=484, result=-0.002433366, error=0.8886404
n=485, result=-0.002433366, error=0.8886404
n=486, result=-0.002433366, error=0.8886404
n=487, result=-0.002433366, error=0.8886404
n=488, result=-0.002433366, error=0.8886404
n=489, result=-0.002433366, error=0.8886404
n=490, result=-0.002433366, error=0.8886404
n=491, result=-0.002433366, error=0.8886404
n=492, result=-0.002433366, error=0.8886404
n=493, result=-0.002433366, error=0.8886404
n=494, result=-0.002433366, error=0.8886404
n=495, result=-0.002433365, error=0.8886404
n=496, result=-0.002433365, error=0.8886404
n=497, result=-0.002433365, error=0.8886404
n=498, result=-0.002433365, error=0.8886404
n=499, result=-0.002433365, error=0.8886404
n=500, result=-0.002433365, error=0.8886404
n=501, result=-0.002433365, error=0.8886404
n=502, result=-0.002433365, error=0.8886404
n=503, result=-0.002433365, error=0.8886404
n=504, result=-0.002433365, error=0.8886404
n=505, result=-0.002433365, error=0.8886404
n=506, result=-0.002433365, error=0.8886404
n=507, result=-0.002433365, error=0.8886404
n=508, result=-0.002433365, error=0.8886404
n=509, result=-0.002433365, error=0.8886404
n=510, result=-0.002433365, error=0.8886404
n=511, result=-0.002433365, error=0.8886404
n=512, result=-0.002433365, error=0.8886404
n=513, result=-0.002433365, error=0.8886404
n=514, result=-0.002433365, error=0.8886404
n=515, result=-0.002433364, error=0.8886404
n=516, result=-0.002433364, error=0.8886404
n=517, result=-0.002433364, error=0.8886404
n=518, result=-0.002433364, error=0.8886404
n=519, result=-0.002433364, error=0.8886404
n=520, result=-0.002433364, error=0.8886404
n=521, result=-0.002433364, error=0.8886404
n=522, result=-0.002433364, error=0.8886404
n=523, result=-0.002433364, error=0.8886404
n=524, result=-0.002433364, error=0.8886404
n=525, result=-0.002433364, error=0.8886404
n=526, result=-0.002433364, error=0.8886404
n=527, result=-0.002433364, error=0.8886404
n=528, result=-0.002433364, error=0.8886404
n=529, result=-0.002433364, error=0.8886404
n=530, result=-0.002433364, error=0.8886404
n=531, result=-0.002433364, error=0.8886404
n=532, result=-0.002433364, error=0.8886404
n=533, result=-0.002433364, error=0.8886404
n=534, result=-0.002433364, error=0.8886404
n=535, result=-0.002433364, error=0.8886404
n=536, result=-0.002433364, error=0.8886404
n=537, result=-0.002433363, error=0.8886404
n=538, result=-0.002433363, error=0.8886404
n=539, result=-0.002433363, error=0.8886404
n=540, result=-0.002433363, error=0.8886404
n=541, result=-0.002433363, error=0.8886404
n=542, result=-0.002433363, error=0.8886404
n=543, result=-0.002433363, error=0.8886404
n=544, result=-0.002433363, error=0.8886404
n=545, result=-0.002433363, error=0.8886404
n=546, result=-0.002433363, error=0.8886404
n=547, result=-0.002433363, error=0.8886404
n=548, result=-0.002433363, error=0.8886404
n=549, result=-0.002433363, error=0.8886404
n=550, result=-0.002433363, error=0.8886404
n=551, result=-0.002433363, error=0.8886404
n=552, result=-0.002433363, error=0.8886404
n=553, result=-0.002433363, error=0.8886404
n=554, result=-0.002433363, error=0.8886404
n=555, result=-0.002433363, error=0.8886404
n=556, result=-0.002433363, error=0.8886404
n=557, result=-0.002433363, error=0.8886404
n=558, result=-0.002433363, error=0.8886404
n=559, result=-0.002433363, error=0.8886404
n=560, result=-0.002433363, error=0.8886404
n=561, result=-0.002433363, error=0.8886404
n=562, result=-0.002433363, error=0.8886404
n=563, result=-0.002433362, error=0.8886404
n=564, result=-0.002433362, error=0.8886404
n=565, result=-0.002433362, error=0.8886404
n=566, result=-0.002433362, error=0.8886404
n=567, result=-0.002433362, error=0.8886404
n=568, result=-0.002433362, error=0.8886404
n=569, result=-0.002433362, error=0.8886404
n=570, result=-0.002433362, error=0.8886404
n=571, result=-0.002433362, error=0.8886404
n=572, result=-0.002433362, error=0.8886404
n=573, result=-0.002433362, error=0.8886404
n=574, result=-0.002433362, error=0.8886404
n=575, result=-0.002433362, error=0.8886404
n=576, result=-0.002433362, error=0.8886404
n=577, result=-0.002433362, error=0.8886404
n=578, result=-0.002433362, error=0.8886404
n=579, result=-0.002433362, error=0.8886404
n=580, result=-0.002433362, error=0.8886404
n=581, result=-0.002433362, error=0.8886404
n=582, result=-0.002433362, error=0.8886404
n=583, result=-0.002433362, error=0.8886404
n=584, result=-0.002433362, error=0.8886404
n=585, result=-0.002433362, error=0.8886404
n=586, result=-0.002433362, error=0.8886404
n=587, result=-0.002433362, error=0.8886404
n=588, result=-0.002433362, error=0.8886404
n=589, result=-0.002433362, error=0.8886404
n=590, result=-0.002433362, error=0.8886404
n=591, result=-0.002433362, error=0.8886404
n=592, result=-0.002433362, error=0.8886404
n=593, result=-0.002433361, error=0.8886404
n=594, result=-0.002433361, error=0.8886404
n=595, result=-0.002433361, error=0.8886404
n=596, result=-0.002433361, error=0.8886404
n=597, result=-0.002433361, error=0.8886404
n=598, result=-0.002433361, error=0.8886404
n=599, result=-0.002433361, error=0.8886404
n=600, result=-0.002433361, error=0.8886404
n=601, result=-0.002433361, error=0.8886404
n=602, result=-0.002433361, error=0.8886404
n=603, result=-0.002433361, error=0.8886404
n=604, result=-0.002433361, error=0.8886404
n=605, result=-0.002433361, error=0.8886404
n=606, result=-0.002433361, error=0.8886404
n=607, result=-0.002433361, error=0.8886404
n=608, result=-0.002433361, error=0.8886404
n=609, result=-0.002433361, error=0.8886404
n=610, result=-0.002433361, error=0.8886404
n=611, result=-0.002433361, error=0.8886404
n=612, result=-0.002433361, error=0.8886404
n=613, result=-0.002433361, error=0.8886404
n=614, result=-0.002433361, error=0.8886404
n=615, result=-0.002433361, error=0.8886404
n=616, result=-0.002433361, error=0.8886404
n=617, result=-0.002433361, error=0.8886404
n=618, result=-0.002433361, error=0.8886404
n=619, result=-0.002433361, error=0.8886404
n=620, result=-0.002433361, error=0.8886404
n=621, result=-0.002433361, error=0.8886404
n=622, result=-0.002433361, error=0.8886404
n=623, result=-0.002433361, error=0.8886404
n=624, result=-0.002433361, error=0.8886404
n=625, result=-0.002433361, error=0.8886404
n=626, result=-0.002433361, error=0.8886404
n=627, result=-0.00243336, error=0.8886404
n=628, result=-0.00243336, error=0.8886404
n=629, result=-0.00243336, error=0.8886404
n=630, result=-0.00243336, error=0.8886404
n=631, result=-0.00243336, error=0.8886404
n=632, result=-0.00243336, error=0.8886404
n=633, result=-0.00243336, error=0.8886404
n=634, result=-0.00243336, error=0.8886404
n=635, result=-0.00243336, error=0.8886404
n=636, result=-0.00243336, error=0.8886404
n=637, result=-0.00243336, error=0.8886404
n=638, result=-0.00243336, error=0.8886404
n=639, result=-0.00243336, error=0.8886404
n=640, result=-0.00243336, error=0.8886404
n=641, result=-0.00243336, error=0.8886404
n=642, result=-0.00243336, error=0.8886404
n=643, result=-0.00243336, error=0.8886404
n=644, result=-0.00243336, error=0.8886404
n=645, result=-0.00243336, error=0.8886404
n=646, result=-0.00243336, error=0.8886404
n=647, result=-0.00243336, error=0.8886404
n=648, result=-0.00243336, error=0.8886404
n=649, result=-0.00243336, error=0.8886404
n=650, result=-0.00243336, error=0.8886404
n=651, result=-0.00243336, error=0.8886404
n=652, result=-0.00243336, error=0.8886404
n=653, result=-0.00243336, error=0.8886404
n=654, result=-0.00243336, error=0.8886404
n=655, result=-0.00243336, error=0.8886404
n=656, result=-0.00243336, error=0.8886404
n=657, result=-0.00243336, error=0.8886404
n=658, result=-0.00243336, error=0.8886404
n=659, result=-0.00243336, error=0.8886404
n=660, result=-0.00243336, error=0.8886404
n=661, result=-0.00243336, error=0.8886404
n=662, result=-0.00243336, error=0.8886404
n=663, result=-0.00243336, error=0.8886404
n=664, result=-0.00243336, error=0.8886404
n=665, result=-0.00243336, error=0.8886404
n=666, result=-0.00243336, error=0.8886404
n=667, result=-0.00243336, error=0.8886404
n=668, result=-0.00243336, error=0.8886404
n=669, result=-0.002433359, error=0.8886404
n=670, result=-0.002433359, error=0.8886404
n=671, result=-0.002433359, error=0.8886404
n=672, result=-0.002433359, error=0.8886404
n=673, result=-0.002433359, error=0.8886404
n=674, result=-0.002433359, error=0.8886404
n=675, result=-0.002433359, error=0.8886404
n=676, result=-0.002433359, error=0.8886404
n=677, result=-0.002433359, error=0.8886404
n=678, result=-0.002433359, error=0.8886404
n=679, result=-0.002433359, error=0.8886404
n=680, result=-0.002433359, error=0.8886404
n=681, result=-0.002433359, error=0.8886404
n=682, result=-0.002433359, error=0.8886404
n=683, result=-0.002433359, error=0.8886404
n=684, result=-0.002433359, error=0.8886404
n=685, result=-0.002433359, error=0.8886404
n=686, result=-0.002433359, error=0.8886404
n=687, result=-0.002433359, error=0.8886404
n=688, result=-0.002433359, error=0.8886404
n=689, result=-0.002433359, error=0.8886404
n=690, result=-0.002433359, error=0.8886404
n=691, result=-0.002433359, error=0.8886404
n=692, result=-0.002433359, error=0.8886404
n=693, result=-0.002433359, error=0.8886404
n=694, result=-0.002433359, error=0.8886404
n=695, result=-0.002433359, error=0.8886404
n=696, result=-0.002433359, error=0.8886404
n=697, result=-0.002433359, error=0.8886404
n=698, result=-0.002433359, error=0.8886404
n=699, result=-0.002433359, error=0.8886404
n=700, result=-0.002433359, error=0.8886404
n=701, result=-0.002433359, error=0.8886404
n=702, result=-0.002433359, error=0.8886404
n=703, result=-0.002433359, error=0.8886404
n=704, result=-0.002433359, error=0.8886404
n=705, result=-0.002433359, error=0.8886404
n=706, result=-0.002433359, error=0.8886404
n=707, result=-0.002433359, error=0.8886404
n=708, result=-0.002433359, error=0.8886404
n=709, result=-0.002433359, error=0.8886404
n=710, result=-0.002433359, error=0.8886404
n=711, result=-0.002433359, error=0.8886404
n=712, result=-0.002433359, error=0.8886404
n=713, result=-0.002433359, error=0.8886404
n=714, result=-0.002433359, error=0.8886404
n=715, result=-0.002433359, error=0.8886404
n=716, result=-0.002433359, error=0.8886404
n=717, result=-0.002433359, error=0.8886404
n=718, result=-0.002433359, error=0.8886404
n=719, result=-0.002433359, error=0.8886404
n=720, result=-0.002433359, error=0.8886404
n=721, result=-0.002433358, error=0.8886404
n=722, result=-0.002433358, error=0.8886404
n=723, result=-0.002433358, error=0.8886404
n=724, result=-0.002433358, error=0.8886404
n=725, result=-0.002433358, error=0.8886404
n=726, result=-0.002433358, error=0.8886404
n=727, result=-0.002433358, error=0.8886404
n=728, result=-0.002433358, error=0.8886404
n=729, result=-0.002433358, error=0.8886404
n=730, result=-0.002433358, error=0.8886404
n=731, result=-0.002433358, error=0.8886404
n=732, result=-0.002433358, error=0.8886404
n=733, result=-0.002433358, error=0.8886404
n=734, result=-0.002433358, error=0.8886404
n=735, result=-0.002433358, error=0.8886404
n=736, result=-0.002433358, error=0.8886404
n=737, result=-0.002433358, error=0.8886404
n=738, result=-0.002433358, error=0.8886404
n=739, result=-0.002433358, error=0.8886404
n=740, result=-0.002433358, error=0.8886404
n=741, result=-0.002433358, error=0.8886404
n=742, result=-0.002433358, error=0.8886404
n=743, result=-0.002433358, error=0.8886404
n=744, result=-0.002433358, error=0.8886404
n=745, result=-0.002433358, error=0.8886404
n=746, result=-0.002433358, error=0.8886404
n=747, result=-0.002433358, error=0.8886404
n=748, result=-0.002433358, error=0.8886404
n=749, result=-0.002433358, error=0.8886404
n=750, result=-0.002433358, error=0.8886404
n=751, result=-0.002433358, error=0.8886404
n=752, result=-0.002433358, error=0.8886404
n=753, result=-0.002433358, error=0.8886404
n=754, result=-0.002433358, error=0.8886404
n=755, result=-0.002433358, error=0.8886404
n=756, result=-0.002433358, error=0.8886404
n=757, result=-0.002433358, error=0.8886404
n=758, result=-0.002433358, error=0.8886404
n=759, result=-0.002433358, error=0.8886404
n=760, result=-0.002433358, error=0.8886404
n=761, result=-0.002433358, error=0.8886404
n=762, result=-0.002433358, error=0.8886404
n=763, result=-0.002433358, error=0.8886404
n=764, result=-0.002433358, error=0.8886404
n=765, result=-0.002433358, error=0.8886404
n=766, result=-0.002433358, error=0.8886404
n=767, result=-0.002433358, error=0.8886404
n=768, result=-0.002433358, error=0.8886404
n=769, result=-0.002433358, error=0.8886404
n=770, result=-0.002433358, error=0.8886404
n=771, result=-0.002433358, error=0.8886404
n=772, result=-0.002433358, error=0.8886404
n=773, result=-0.002433358, error=0.8886404
n=774, result=-0.002433358, error=0.8886404
n=775, result=-0.002433358, error=0.8886404
n=776, result=-0.002433358, error=0.8886404
n=777, result=-0.002433358, error=0.8886404
n=778, result=-0.002433358, error=0.8886404
n=779, result=-0.002433358, error=0.8886404
n=780, result=-0.002433358, error=0.8886404
n=781, result=-0.002433358, error=0.8886404
n=782, result=-0.002433358, error=0.8886404
n=783, result=-0.002433358, error=0.8886404
n=784, result=-0.002433358, error=0.8886404
n=785, result=-0.002433358, error=0.8886404
n=786, result=-0.002433357, error=0.8886404
n=787, result=-0.002433357, error=0.8886404
n=788, result=-0.002433357, error=0.8886404
n=789, result=-0.002433357, error=0.8886404
n=790, result=-0.002433357, error=0.8886404
n=791, result=-0.002433357, error=0.8886404
n=792, result=-0.002433357, error=0.8886404
n=793, result=-0.002433357, error=0.8886404
n=794, result=-0.002433357, error=0.8886404
n=795, result=-0.002433357, error=0.8886404
n=796, result=-0.002433357, error=0.8886404
n=797, result=-0.002433357, error=0.8886404
n=798, result=-0.002433357, error=0.8886404
n=799, result=-0.002433357, error=0.8886404
n=800, result=-0.002433357, error=0.8886404
n=801, result=-0.002433357, error=0.8886404
n=802, result=-0.002433357, error=0.8886404
n=803, result=-0.002433357, error=0.8886404
n=804, result=-0.002433357, error=0.8886404
n=805, result=-0.002433357, error=0.8886404
n=806, result=-0.002433357, error=0.8886404
n=807, result=-0.002433357, error=0.8886404
n=808, result=-0.002433357, error=0.8886404
n=809, result=-0.002433357, error=0.8886404
n=810, result=-0.002433357, error=0.8886404
n=811, result=-0.002433357, error=0.8886404
n=812, result=-0.002433357, error=0.8886404
n=813, result=-0.002433357, error=0.8886404
n=814, result=-0.002433357, error=0.8886404
n=815, result=-0.002433357, error=0.8886404
n=816, result=-0.002433357, error=0.8886404
n=817, result=-0.002433357, error=0.8886404
n=818, result=-0.002433357, error=0.8886404
n=819, result=-0.002433357, error=0.8886404
n=820, result=-0.002433357, error=0.8886404
n=821, result=-0.002433357, error=0.8886404
n=822, result=-0.002433357, error=0.8886404
n=823, result=-0.002433357, error=0.8886404
n=824, result=-0.002433357, error=0.8886404
n=825, result=-0.002433357, error=0.8886404
n=826, result=-0.002433357, error=0.8886404
n=827, result=-0.002433357, error=0.8886404
n=828, result=-0.002433357, error=0.8886404
n=829, result=-0.002433357, error=0.8886404
n=830, result=-0.002433357, error=0.8886404
n=831, result=-0.002433357, error=0.8886404
n=832, result=-0.002433357, error=0.8886404
n=833, result=-0.002433357, error=0.8886404
n=834, result=-0.002433357, error=0.8886404
n=835, result=-0.002433357, error=0.8886404
n=836, result=-0.002433357, error=0.8886404
n=837, result=-0.002433357, error=0.8886404
n=838, result=-0.002433357, error=0.8886404
n=839, result=-0.002433357, error=0.8886404
n=840, result=-0.002433357, error=0.8886404
n=841, result=-0.002433357, error=0.8886404
n=842, result=-0.002433357, error=0.8886404
n=843, result=-0.002433357, error=0.8886404
n=844, result=-0.002433357, error=0.8886404
n=845, result=-0.002433357, error=0.8886404
n=846, result=-0.002433357, error=0.8886404
n=847, result=-0.002433357, error=0.8886404
n=848, result=-0.002433357, error=0.8886404
n=849, result=-0.002433357, error=0.8886404
n=850, result=-0.002433357, error=0.8886404
n=851, result=-0.002433357, error=0.8886404
n=852, result=-0.002433357, error=0.8886404
n=853, result=-0.002433357, error=0.8886404
n=854, result=-0.002433357, error=0.8886404
n=855, result=-0.002433357, error=0.8886404
n=856, result=-0.002433357, error=0.8886404
n=857, result=-0.002433357, error=0.8886404
n=858, result=-0.002433357, error=0.8886404
n=859, result=-0.002433357, error=0.8886404
n=860, result=-0.002433357, error=0.8886404
n=861, result=-0.002433357, error=0.8886404
n=862, result=-0.002433357, error=0.8886404
n=863, result=-0.002433357, error=0.8886404
n=864, result=-0.002433357, error=0.8886404
n=865, result=-0.002433357, error=0.8886404
n=866, result=-0.002433357, error=0.8886404
n=867, result=-0.002433357, error=0.8886404
n=868, result=-0.002433357, error=0.8886404
n=869, result=-0.002433357, error=0.8886404
n=870, result=-0.002433357, error=0.8886404
n=871, result=-0.002433357, error=0.8886404
n=872, result=-0.002433357, error=0.8886404
n=873, result=-0.002433357, error=0.8886404
n=874, result=-0.002433356, error=0.8886404
n=875, result=-0.002433356, error=0.8886404
n=876, result=-0.002433356, error=0.8886404
n=877, result=-0.002433356, error=0.8886404
n=878, result=-0.002433356, error=0.8886404
n=879, result=-0.002433356, error=0.8886404
n=880, result=-0.002433356, error=0.8886404
n=881, result=-0.002433356, error=0.8886404
n=882, result=-0.002433356, error=0.8886404
n=883, result=-0.002433356, error=0.8886404
n=884, result=-0.002433356, error=0.8886404
n=885, result=-0.002433356, error=0.8886404
n=886, result=-0.002433356, error=0.8886404
n=887, result=-0.002433356, error=0.8886404
n=888, result=-0.002433356, error=0.8886404
n=889, result=-0.002433356, error=0.8886404
n=890, result=-0.002433356, error=0.8886404
n=891, result=-0.002433356, error=0.8886404
n=892, result=-0.002433356, error=0.8886404
n=893, result=-0.002433356, error=0.8886404
n=894, result=-0.002433356, error=0.8886404
n=895, result=-0.002433356, error=0.8886404
n=896, result=-0.002433356, error=0.8886404
n=897, result=-0.002433356, error=0.8886404
n=898, result=-0.002433356, error=0.8886404
n=899, result=-0.002433356, error=0.8886404
n=900, result=-0.002433356, error=0.8886404
n=901, result=-0.002433356, error=0.8886404
n=902, result=-0.002433356, error=0.8886404
n=903, result=-0.002433356, error=0.8886404
n=904, result=-0.002433356, error=0.8886404
n=905, result=-0.002433356, error=0.8886404
n=906, result=-0.002433356, error=0.8886404
n=907, result=-0.002433356, error=0.8886404
n=908, result=-0.002433356, error=0.8886404
n=909, result=-0.002433356, error=0.8886404
n=910, result=-0.002433356, error=0.8886404
n=911, result=-0.002433356, error=0.8886404
n=912, result=-0.002433356, error=0.8886404
n=913, result=-0.002433356, error=0.8886404
n=914, result=-0.002433356, error=0.8886404
n=915, result=-0.002433356, error=0.8886404
n=916, result=-0.002433356, error=0.8886404
n=917, result=-0.002433356, error=0.8886404
n=918, result=-0.002433356, error=0.8886404
n=919, result=-0.002433356, error=0.8886404
n=920, result=-0.002433356, error=0.8886404
n=921, result=-0.002433356, error=0.8886404
n=922, result=-0.002433356, error=0.8886404
n=923, result=-0.002433356, error=0.8886404
n=924, result=-0.002433356, error=0.8886404
n=925, result=-0.002433356, error=0.8886404
n=926, result=-0.002433356, error=0.8886404
n=927, result=-0.002433356, error=0.8886404
n=928, result=-0.002433356, error=0.8886404
n=929, result=-0.002433356, error=0.8886404
n=930, result=-0.002433356, error=0.8886404
n=931, result=-0.002433356, error=0.8886404
n=932, result=-0.002433356, error=0.8886404
n=933, result=-0.002433356, error=0.8886404
n=934, result=-0.002433356, error=0.8886404
n=935, result=-0.002433356, error=0.8886404
n=936, result=-0.002433356, error=0.8886404
n=937, result=-0.002433356, error=0.8886404
n=938, result=-0.002433356, error=0.8886404
n=939, result=-0.002433356, error=0.8886404
n=940, result=-0.002433356, error=0.8886404
n=941, result=-0.002433356, error=0.8886404
n=942, result=-0.002433356, error=0.8886404
n=943, result=-0.002433356, error=0.8886404
n=944, result=-0.002433356, error=0.8886404
n=945, result=-0.002433356, error=0.8886404
n=946, result=-0.002433356, error=0.8886404
n=947, result=-0.002433356, error=0.8886404
n=948, result=-0.002433356, error=0.8886404
n=949, result=-0.002433356, error=0.8886404
n=950, result=-0.002433356, error=0.8886404
n=951, result=-0.002433356, error=0.8886404
n=952, result=-0.002433356, error=0.8886404
n=953, result=-0.002433356, error=0.8886404
n=954, result=-0.002433356, error=0.8886404
n=955, result=-0.002433356, error=0.8886404
n=956, result=-0.002433356, error=0.8886404
n=957, result=-0.002433356, error=0.8886404
n=958, result=-0.002433356, error=0.8886404
n=959, result=-0.002433356, error=0.8886404
n=960, result=-0.002433356, error=0.8886404
n=961, result=-0.002433356, error=0.8886404
n=962, result=-0.002433356, error=0.8886404
n=963, result=-0.002433356, error=0.8886404
n=964, result=-0.002433356, error=0.8886404
n=965, result=-0.002433356, error=0.8886404
n=966, result=-0.002433356, error=0.8886404
n=967, result=-0.002433356, error=0.8886404
n=968, result=-0.002433356, error=0.8886404
n=969, result=-0.002433356, error=0.8886404
n=970, result=-0.002433356, error=0.8886404
n=971, result=-0.002433356, error=0.8886404
n=972, result=-0.002433356, error=0.8886404
n=973, result=-0.002433356, error=0.8886404
n=974, result=-0.002433356, error=0.8886404
n=975, result=-0.002433356, error=0.8886404
n=976, result=-0.002433356, error=0.8886404
n=977, result=-0.002433356, error=0.8886404
n=978, result=-0.002433356, error=0.8886404
n=979, result=-0.002433356, error=0.8886404
n=980, result=-0.002433356, error=0.8886404
n=981, result=-0.002433356, error=0.8886404
n=982, result=-0.002433356, error=0.8886404
n=983, result=-0.002433356, error=0.8886404
n=984, result=-0.002433356, error=0.8886404
n=985, result=-0.002433356, error=0.8886404
n=986, result=-0.002433356, error=0.8886404
n=987, result=-0.002433356, error=0.8886404
n=988, result=-0.002433356, error=0.8886404
n=989, result=-0.002433356, error=0.8886404
n=990, result=-0.002433356, error=0.8886404
n=991, result=-0.002433356, error=0.8886404
n=992, result=-0.002433356, error=0.8886404
n=993, result=-0.002433356, error=0.8886404
n=994, result=-0.002433356, error=0.8886404
n=995, result=-0.002433356, error=0.8886404
n=996, result=-0.002433356, error=0.8886404
n=997, result=-0.002433356, error=0.8886404
n=998, result=-0.002433356, error=0.8886404
n=999, result=-0.002433355, error=0.8886404