Regarding PR 7290

126 views
Skip to first unread message

Kundan Kumar

unread,
Mar 17, 2014, 2:41:01 PM3/17/14
to sy...@googlegroups.com
I sent a PR https://github.com/sympy/sympy/pull/7290 but its travis build failed. I have not used github for too long so I am unable to figure out the problem.

Any suggestion knows why it is failing?

Ondřej Čertík

unread,
Mar 17, 2014, 4:44:35 PM3/17/14
to sympy
Hi Kundan,
Yes, just click on the red "X", which goes to:

https://travis-ci.org/sympy/sympy/builds/20913459

then click on any of the failed tests, e.g. the first one:

https://travis-ci.org/sympy/sympy/jobs/20913460

and scroll all the way down to see the failure:


File "/home/travis/virtualenv/python2.6/lib/python2.6/site-packages/sympy/solvers/ode.py",
line 3267, in sympy.solvers.ode.ode_nth_linear_euler_eq_nonhomogeneous
Failed example:
dsolve(x**2*diff(f(x), x, x) - 2*x*diff(f(x), x) + 2*f(x), x**3), f(x),
hint='nth_linear_euler_eq_nonhomogeneous')
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python2.6/doctest.py", line 1253, in __run
compileflags, 1) in test.globs
File "<doctest sympy.solvers.ode.ode_nth_linear_euler_eq_nonhomogeneous[3]>",
line 1, in <module>
dsolve(x**2*diff(f(x), x, x) - 2*x*diff(f(x), x) + 2*f(x), x**3), f(x),
NameError: name 'diff' is not defined



(see the link above for a nice formatting)

Btw, to easily see this yourself, just run tests by hand on your local
machine, instead of waiting for 1h for Travis.

Ondrej

Kundan Kumar

unread,
Mar 18, 2014, 2:33:30 AM3/18/14
to sy...@googlegroups.com
Thanks Ondrej,

There are four errors, out of which two are concerned with changes I have done. And about the rest two errors I dont know as I have not done any change in respective file.
The concerned two error I was getting was one in doctest, which I have pointed out, and another in test, assertion error of dsolve.
I am using undetermined coefficients and variation of parameters to solve non homogeneous euler eq.
Any idea why is this assertion error of dsolve is coming as it is able to pass assertion of classify_ode and checkodesol. 

Ondřej Čertík

unread,
Mar 18, 2014, 2:54:24 PM3/18/14
to sympy
Hi Kundan,
Push in your fixes to the PR and let's see which tests fail. Then
we'll try to figure out the problem
in the PR discussion, where we can comment on the actual patch.

Ondrej

Kundan Kumar

unread,
Mar 18, 2014, 4:13:39 PM3/18/14
to sy...@googlegroups.com
FoA Thanks Ondrej for pointing me out with Travis.
I have fixed the doc error and commited the respective changes and now I am still looking for assertion error in dsolve. Now, please review my PR and help me with the problem.
As this is first patch I require it for passing the primary criteria of sympy selection.
Thanks again.

Kundan Kumar

unread,
Mar 20, 2014, 2:50:29 PM3/20/14
to asme...@gmail.com, sy...@googlegroups.com
Aaron,
When I am running dsolve for nonhomogeneous euler equation it is giving error

NotImplementedError: Could not solve `-x + 2*f(x) - exp(x) - 3*Derivative(f(x), x) + Derivative(f(x), x, x)` using the method of undetermined coefficients (unable to solve for coefficients File "sympy/solvers/ode.py", line 561, in dsolve
    return _helper_simplify(eq, hint, hints, simplify)
  File "sympy/solvers/ode.py", line 583, in _helper_simplify
    rv = odesimp(solvefunc(eq, func, order, match), func, order, hint)
  File "sympy/solvers/ode.py", line 3300, in ode_nth_linear_euler_eq_nonhomogeneous
    return ode_nth_linear_constant_coeff_undetermined_coefficients(eq, func, order, match).replace(x,log(x))
  File "sympy/solvers/ode.py", line 3862, in ode_nth_linear_constant_coeff_undetermined_coefficients
    return _solve_undetermined_coefficients(eq, func, order, match)
  File "sympy/solvers/ode.py", line 3963, in _solve_undetermined_coefficients
    "(unable to solve for coefficients)." % eq)
NotImplementedError: Could not solve `-x + 2*f(x) - exp(x) - 3*Derivative(f(x), x) + Derivative(f(x), x, x)` using the method of undetermined coefficients (unable to solve for coefficients))

I read the code of undetermined coefficients, this error comes only when there is no value of "list" of coefficients of Particular solution like a0, a1, ..
Since the equation it is showing is perfect and it can easily solved by method of undetermined coefficients. I checked collectterms, r['list'], r['sol'], these are working fine. The most probably error may be arising due to trialset.
Since you know the inside-out of this undetermined function, can you suggest why this is happening?

Aaron Meurer

unread,
Mar 20, 2014, 8:12:41 PM3/20/14
to Kundan Kumar, sy...@googlegroups.com
The error message gives a hint (unable to solve for coefficients). So
somehow the point where solve() is called on the coefficients it
doesn't work. You'll have to put some print statements in the code to
see what is the input and output of solve that doesn't work.

Aaron Meurer

Kundan Kumar

unread,
Mar 21, 2014, 2:15:11 AM3/21/14
to sy...@googlegroups.com, Kundan Kumar
The code is able to solve for "x**2*Derivative(f(x), x, x) - 2*x*Derivative(f(x), x) + 2*f(x) - log(x) = 0" but is giving very complex solution. Is there any way to simplify complex equations.

The solution it is giving is
"(C1*sin(log(x)*Abs(im(sqrt(-log(x)**2)/log(x)**2) - arg(x)/(log(Abs(x))**2 + arg(x)**2))) + C2*cos((im(sqrt(-log(x)**2)/log(x)**2) - arg(x)/(log(Abs(x))**2 + arg(x)**2))*log(x)))*exp((re(sqrt(-log(x)**2)/log(x)**2) + log(Abs(x))/(log(Abs(x))**2 + arg(x)**2))*log(x)) + (C3*sin(log(x)*Abs(im(sqrt(-log(x)**2)/log(x)**2) + arg(x)/(log(Abs(x))**2 + arg(x)**2))) + C4*cos(-(-im(sqrt(-log(x)**2)/log(x)**2) - arg(x)/(log(Abs(x))**2 + arg(x)**2))*log(x)))*exp((-re(sqrt(-log(x)**2)/log(x)**2) + log(Abs(x))/(log(Abs(x))**2 + arg(x)**2))*log(x)) + log(x)/2 + 3/4"

while the actual solution is "c1*x + c2*x**2 + log(x)/2 + 3/4"
Here last two term that is particular solution is coming same, there is problem with general solution.

But code is not able to solve if I replace log(x) with any thing else like "x or x**2" in the question, in this case it is giving this error

```File "sympy/solvers/ode.py", line 3963, in _solve_undetermined_coefficients

    "(unable to solve for coefficients)." % eq)
NotImplementedError: Could not solve `2*f(x) - exp(x) - 3*Derivative(f(x), x) + Derivative(f(x), x, x)` using the method of undetermined coefficients (unable to solve for coefficients)```

@Ondrej @Aaron Any comments on this?

Kundan Kumar

unread,
Mar 21, 2014, 7:05:05 AM3/21/14
to sy...@googlegroups.com, Kundan Kumar
The problem is in match, it stores the coefficient of non homogeneous euler eq even after transformation into linear one.
for ex. the equation I used
eq = Eq(x**2*Derivative(f(x), x, x) - 2*x*Derivative(f(x), x) + 2*f(x), log(x**2))

after transformation it becomes
Derivative(f(x), x, x) - 3*Derivative(f(x), x) + 2*f(x), log(x**2)

when I printed match inside
"def ode_nth_linear_constant_coeff_undetermined_coefficients(eq, func, order, match):"

it returns
"{0: 2, 1: -2*x, 2: x**2, 'trialset': set([1, x]), -1: -log(x**2)}"

that is match for 1st eq but in
"ode_nth_linear_constant_coeff_undetermined_coefficients(eq, func, order, match):"
I need to pass different match according to transformed eq

Ondřej Čertík

unread,
Mar 21, 2014, 10:38:51 AM3/21/14
to sympy
Try to put these comments into the PR itself ---- it allows better
formatting and everything will be in one place.

If other people come around that PR and want to help, you want them to
be able to see your debugging messages.

Ondrej
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/22c8e03c-3b2b-4024-9b21-e36fac0717b7%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Ondřej Čertík

unread,
Mar 21, 2014, 10:39:36 AM3/21/14
to sympy
On Fri, Mar 21, 2014 at 8:38 AM, Ondřej Čertík <ondrej...@gmail.com> wrote:
> Try to put these comments into the PR itself ---- it allows better
> formatting and everything will be in one place.

I.e. into the comments on github.

Ondrej

Kundan Kumar

unread,
Mar 21, 2014, 11:18:23 AM3/21/14
to sy...@googlegroups.com
Ondrej,
Thanks, I will so that. I added match for above mentioned problem and now it is able to solve all those equations which are after transformation solvable by undetermined coefficients.

Aaron Meurer

unread,
Mar 21, 2014, 7:44:01 PM3/21/14
to sy...@googlegroups.com
This is a known issue. We need to add better handling for the complex
case, so that it just outputs complex exponentials, rather than some
complicated expression in terms of re and im.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/d796cf81-1cb1-4381-9d89-a2494817b80f%40googlegroups.com.

Kundan Kumar

unread,
Mar 22, 2014, 4:18:41 AM3/22/14
to sy...@googlegroups.com
Yeah, thats a different issue but earlier problem was in match. Now I edited the code so that it take modified match of transformed equation and then solve the equation. Please have a look at the PR. Also there is coming assertion error in "test_2nd_power_series_regular" in two equations. I have not changed anything in that. But when I remove those two equation all tests passes.

I checked answer for those two its correctly written in assert. I dont know why its failing.
Should I do any changes in that failing test case?

Kundan Kumar

unread,
Mar 25, 2014, 11:55:07 AM3/25/14
to sy...@googlegroups.com
Aaron,
I have updated PR https://github.com/sympy/sympy/pull/7290 as per your suggestion accordingly.Please have a look at it.
I have included both method undetermined coefficients and variation of parameters to solve nonhomogeneous euler eq. I have provided hints to use either of them to solve the ODE. Also, added test cases for both method.
Reply all
Reply to author
Forward
0 new messages