Title / Description
Code tr=0.85260550201372549135 def g(x) 2.0*Math.exp(-x) end results=Array.new eps= 0.00001 x0 = 0.8 x1 = x0+eps*10.0 i = 0 while ((x1-x0).abs>eps) do x0 = i==0 ? 0.8 : x1 x1 = g(x0) results[i]= x1 i +=1 end #p x1 #p tr-x1 results.length.times{|i| puts "#{i}. #{results[i]} #{tr-results[i]}" } tr=0.85260550201372549135 def g(x) 2.0*Math.exp(-x) end results=Array.new eps= 0.00001 x0 = 0.8 x1 = 0 x2 = 0 l2 = 0 x3 = x0+eps*10.0 i = 0 while ((x3-x0).abs>eps ) do x0=i==0 ? 0.8 : x3 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}. #{results[i]} #{tr-results[i]}" }
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code