Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- # coding: utf-8
- def df(x, y) 2 * x * y end
- n = 128
- ret = []
- ret << [0.0, 1.0]
- h = 1.0 / n
- n.times do |i|
- k1 = h * df(ret[i][0], ret[i][1])
- k2 = h * df(ret[i][0] + h / 2, ret[i][1] + k1 / 2)
- k3 = h * df(ret[i][0] + h / 2, ret[i][1] + k2 / 2)
- k4 = h * df(ret[i][0] + h, ret[i][1] + k3)
- ret << [(i + 1) * h, ret[i][1] + (k1 + 2 * k2 + 2 * k3 + k4) / 6]
- end
- open('outpu.dat', 'w') do |f|
- ret.each {|x, y| f.puts "#{x} #{y}"}
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement