asdas

Ruby code posted by asfd
created at 23 Nov 15:38

Edit | Back
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
tr=6.0155030729515095
def g(x)
  6.28+Math.sin(x)
end
results=Array.new
eps= 0.00001
x0 = 6
x1 = x0+eps*10.0
i = 0
while ((x1-x0).abs>eps) do 
  x0=i==0 ? 6 : x1
  x1=g(x0)
  results[i]= x1
  i +=1
end

results.length.times{|i|
  puts "#{i}.\t\t\t#{results[i]}\t\t#{(tr-results[i]).abs}"
}

tr=6.0155030729515095
def g(x)
  6.28+Math.sin(x)
end
results=Array.new
eps= 0.0000001
x0 = 6
x1 = 0
x2 = 0
l2 = 0
x3 = x0+eps*10.0
i = 0
while ((x3-x0).abs>eps) do 
  x0=i==0 ? 6 : x1
  x1=g(x0)
  x2=g(x1)
  l2=(x2-x1)/(x1-x0)
  x3=x2+l2*(x2-x1)/(1-l2)
  results[i]= x1
  i +=1
end

results.length.times{|i|
  puts "#{i}.\t\t\t#{results[i]}\t\t#{(tr-results[i]).abs}"
}

694 Bytes in 4 ms with coderay