Created
July 14, 2014 20:12
-
-
Save agarie/0870390f94b0085fe37f to your computer and use it in GitHub Desktop.
DSL for symbolic integration of polynomials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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