Hi Priit! I pushed your patches in. But could you please create more tests for the line_integrate? So that it is more tested.
Nice job and welcome to sympy: http://git.sympy.org/?p=sympy.git;a=commitdiff;h=0860a354534696040143d874378dd122eafdeb02 Ondrej On Thu, Nov 27, 2008 at 10:03 PM, Ondrej Certik <[EMAIL PROTECTED]> wrote: > This looks good to me. Could you please also create more tests for the > line_integrate? You can add them as additional patches. > > Ondrej > > On Thu, Nov 27, 2008 at 9:57 PM, Ondrej Certik <[EMAIL PROTECTED]> wrote: >> From: Priit Laes <[EMAIL PROTECTED]> >> >> --- >> sympy/integrals/__init__.py | 2 +- >> sympy/integrals/integrals.py | 45 >> +++++++++++++++++++++++++++ >> sympy/integrals/tests/test_lineintegrals.py | 9 +++++ >> 3 files changed, 55 insertions(+), 1 deletions(-) >> create mode 100644 sympy/integrals/tests/test_lineintegrals.py >> >> diff --git a/sympy/integrals/__init__.py b/sympy/integrals/__init__.py >> index 6027264..7abce35 100644 >> --- a/sympy/integrals/__init__.py >> +++ b/sympy/integrals/__init__.py >> @@ -5,4 +5,4 @@ Out[3]: log(x) >> In [4]: integrate(sin(x),x) >> Out[4]: -cos(x) >> """ >> -from integrals import integrate, Integral >> +from integrals import integrate, Integral, line_integrate >> diff --git a/sympy/integrals/integrals.py b/sympy/integrals/integrals.py >> index 8094919..d541569 100644 >> --- a/sympy/integrals/integrals.py >> +++ b/sympy/integrals/integrals.py >> @@ -10,6 +10,7 @@ from sympy.series import limit >> from sympy.polys import Poly >> from sympy.solvers import solve >> from sympy.functions import DiracDelta, Heaviside, Piecewise >> +from sympy.geometry import Curve >> >> class Integral(Basic): >> """Represents unevaluated integral.""" >> @@ -377,3 +378,47 @@ def integrate(*args, **kwargs): >> return integral.doit() >> else: >> return integral >> + >> + >> [EMAIL PROTECTED](use_add=False) >> +def line_integrate(field, curve, vars): >> + """line_integrate(field, Curve, variables) >> + >> + Compute the line integral. >> + >> + Examples >> + -------- >> + >>> from sympy import * >> + >>> x, y, t = symbols('xyt') >> + >>> C = Curve([E**t + 1, E**t - 1], (t, 0, ln(2))) >> + >>> line_integrate(x + y, C, [x, y]) >> + 3*sqrt(2) >> + >> + """ >> + F = sympify(field) >> + if not F: >> + raise ValueError("Expecting function specifying field as first >> argument.") >> + if not isinstance(curve, Curve): >> + raise ValueError("Expecting Curve entity as second argument.") >> + if not isinstance(vars, (list, tuple)): >> + raise ValueError("Expecting list/tuple for variables.") >> + if len(curve.functions) != len(vars): >> + raise ValueError("Field variable size does not match curve >> dimension.") >> + >> + if curve.parameter in vars: >> + raise ValueError("Curve parameter clashes with field parameters.") >> + >> + # Calculate derivatives for line parameter functions >> + # F(r) -> F(r(t)) and finally F(r(t)*r'(t)) >> + Ft = F >> + dldt = 0 >> + for i, var in enumerate(vars): >> + _f = curve.functions[i] >> + _dn = diff(_f, curve.parameter) >> + # ...arc length >> + dldt = dldt + (_dn * _dn) >> + Ft = Ft.subs(var, _f) >> + Ft = Ft * dldt**(S(1)/2) >> + >> + integral = Integral(Ft, curve.limits).doit() >> + return integral >> diff --git a/sympy/integrals/tests/test_lineintegrals.py >> b/sympy/integrals/tests/test_lineintegrals.py >> new file mode 100644 >> index 0000000..1cb8a8c >> --- /dev/null >> +++ b/sympy/integrals/tests/test_lineintegrals.py >> @@ -0,0 +1,9 @@ >> +from sympy import (symbols, integrate, Integral, diff, sin, cos, pi, E, ln, >> + sympify, Curve, line_integrate, sqrt) >> + >> +s, t, x, y, z = symbols('stxyz') >> + >> +def test_lineintegral(): >> + c = Curve([E**t + 1, E**t - 1], (t, 0, ln(2))) >> + assert line_integrate(x + y, c, [x, y]) == 3*sqrt(2) >> + >> -- >> 1.6.0.4 >> >> > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-patches" group. To post to this group, send email to sympy-patches@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sympy-patches?hl=en -~----------~----~----~----~------~----~------~--~---