Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

2016/8/11

Rubycode9linescodepad

codepad [ create a new paste ]


Link: http://codepad.org/e8K2T7if [ raw code | output | fork ]

login | about
Save this paste
Delete this paste

Ruby, pasted 1 second ago:


1
2
3
4
5
6
7
8
9

a = 0.0; b = 1.0; s = 0.0; n=100


def f(x)
return x
end
n.times do |k|
s += (b-a)/n * f(a+(b-a)*k/n); p s
end

Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

0.0
0.0001
0.0003
0.0006
0.001
0.0015
0.0021
0.0028
0.0036
0.0045
0.0055
0.0066
0.0078
0.0091
0.0105
0.012
0.0136
0.0153
0.0171
0.019
0.021
0.0231
0.0253
0.0276
0.03
0.0325
0.0351
0.0378
0.0406
0.0435
0.0465
0.0496
0.0528
0.0561
0.0595
0.063
0.0666
0.0703
0.0741
0.078
0.082
0.0861
0.0903
0.0946
0.099
0.1035
0.1081
0.1128
0.1176
0.1225

http://codepad.org/e8K2T7if

1/3

2016/8/11

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

Rubycode9linescodepad

0.1275
0.1326
0.1378
0.1431
0.1485
0.154
0.1596
0.1653
0.1711
0.177
0.183
0.1891
0.1953
0.2016
0.208
0.2145
0.2211
0.2278
0.2346
0.2415
0.2485
0.2556
0.2628
0.2701
0.2775
0.285
0.2926
0.3003
0.3081
0.316
0.324
0.3321
0.3403
0.3486
0.357
0.3655
0.3741
0.3828
0.3916
0.4005
0.4095
0.4186
0.4278
0.4371
0.4465
0.456
0.4656
0.4753
0.4851
0.495

New paste:
Language: Ruby
a = 0.0; b = 1.0; s = 0.0; n=100
def f(x)
return x
end
n.times do |k|
s += (b-a)/n * f(a+(b-a)*k/n); p s
end

Private
http://codepad.org/e8K2T7if

[?]

Run code Submit


2/3

2016/8/11

Rubycode9linescodepad

Comments:

PostComment

http://codepad.org/e8K2T7if

3/3

You might also like