Ruby Tutorial Ruby References

Ruby - Math.erf() Method



The Ruby Math.erf() method returns the error function of the argument. The error function of x is defined as:

erf function

Error functions usually occur in probability, statistics and partial differential equation describing diffusion.

Error Function

Syntax

Math.erf(x)

Parameters

x Specify the value.

Return Value

Returns the error function of the argument.

Example:

In the example below, Math.erf() method returns the error function of the given value.

puts "Math.erf(-2) = #{Math.erf(-2)}"
puts "Math.erf(-1) = #{Math.erf(-1)}"
puts "Math.erf(-0.5) = #{Math.erf(-0.5)}"
puts "Math.erf(0) = #{Math.erf(0)}"
puts "Math.erf(1) = #{Math.erf(1)}"
puts "Math.erf(2) = #{Math.erf(2)}"

The output of the above code will be:

Math.erf(-2) = -0.9953222650189527
Math.erf(-1) = -0.8427007929497149
Math.erf(-0.5) = -0.5204998778130465
Math.erf(0) = 0.0
Math.erf(1) = 0.8427007929497149
Math.erf(2) = 0.9953222650189527

❮ Ruby Math Module