Skip to content

Instantly share code, notes, and snippets.

@agarie
Created July 14, 2014 20:12
Show Gist options
  • Save agarie/0870390f94b0085fe37f to your computer and use it in GitHub Desktop.
Save agarie/0870390f94b0085fe37f to your computer and use it in GitHub Desktop.
DSL for symbolic integration of polynomials
def polynomial(&block)
varX = Variable::Local.new('x')
x = Polynomial.valueOf(Real::ONE,varX)
yield x
end
# Creating a polynomial fx = 1(x^5) + 6(x^2).
fx = polynomial do |x|
x.pow(5).plus(x.pow(2).times(Real.valueOf(6)))
end
# Integrating with respect to variable 'x'.
puts fx.integrate(varX)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment