# sympy/sympy

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

# Initial conditions in dsolve() #4720

Closed
opened this Issue Aug 29, 2009 · 15 comments

## Comments

Projects
None yet
7 participants
Member

### asmeurer commented Aug 29, 2009

 ``````I finished up the ODE module, and it is now in the master branch (see issue 4710 ), but I never got around to doing initial conditions. I think we need them, and it should be easy to implement. You just need to substitute the points into the solution and solve for the arbitrary constants. The problem is that the best syntax would be to pass a dictionary of f(0):1, f'(0):2 like terms (or use **ics). But we don't yet have a way to represent f'(0) in SymPy (see issue 4719 ). `````` Original issue for #4720: http://code.google.com/p/sympy/issues/detail?id=1621 Original author: https://code.google.com/u/asmeurer@gmail.com/ Referenced issues: #4710 Original owner: https://code.google.com/u/asmeurer@gmail.com/
Member

### asmeurer commented Aug 28, 2009

 ``````**Blockedon:** 4719 `````` Referenced issues: #4719 Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c1 Original author: https://code.google.com/u/asmeurer@gmail.com/
Contributor

### saptman commented Apr 3, 2011

 ``````Not that simple. Occasionally you will get a solution like this: exp(C0 + x). Putting this simply in the solver will cause it to choke because it gives rise to a non linear equation. `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c2 Original author: https://code.google.com/u/108133104953261185619/
Contributor

### vks commented Apr 3, 2011

 ``````Please note that our solver supports nonlinear equations too. `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c3 Original author: https://code.google.com/u/Vinzent.Steinberg@gmail.com/
Member

### asmeurer commented Apr 4, 2011

 ``````I think we should just pass it to solve() and if it can't handle it, raise NotImplementedError. In other words, if solve() can't handle it, it is a problem with solve(), not dsolve(). Note that it will also be possible that someone passes conditions to dsolve() which do not actually determine unique values for the constants. We can tell if this is the case in the linear case, so we should probably raise an error to that effect in that case. But in the non-linear case, I don't think we can tell the difference between the system being inconsistent or non zero-dimensional and solve() not implementing it in general, so we will just have to raise NotImplementedError with a note that it might be solve's fault, or it might be a bad set of initial conditions. By the way, this is only "EasyToFix" after issue 4719 is fixed. **Labels:** -EasyToFix `````` Referenced issues: #4719 Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c4 Original author: https://code.google.com/u/asmeurer@gmail.com/
Contributor

### renatocoutinho commented Jun 16, 2011

 ``````Passing incomplete initial conditions may be useful, too. Perhaps the user wants to solve a second order ODE and wants to give only one initial condition to obtain a 1-parameter family of solutions. Sapta has a point in comment 2: this will be hard to do in the non-linear case if the order of tthe EDO is higher than 1. solve() is seriously broken for systems of equations that are not polynomial. `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c5 Original author: https://code.google.com/u/115599828448622896355/
Contributor

### renatocoutinho commented Jun 16, 2011

 ``````Another question: what should the interface be? The only way to keep full compatibility is accepting initial conditions in kwargs, but it feels more natural to have a named keyword arg ics explicitly. I agree that a dict like {f(0):1, f'(0):2} is a good choice. `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c6 Original author: https://code.google.com/u/115599828448622896355/
Member

### asmeurer commented Jun 17, 2011

 ``````I think the syntax should be dsolve(ode, f(x), ics={f(0):1, f'(0):2}). As far as solving, I think we should just try to solve for the constants with what's given. If it can do it, then great. If it can't then either you gave an inconsistent or underdetermined set of initial conditions, or solve() isn't good enough. Either way, it's the problem of solve(). I would be nice to be able to say "these initial conditions are underdetermined/inconsistent" instead of just "maybe the ics aren't any good, or maybe solve() isn't good enough," and also to be a able to give a parameterized family of solutions when they are underdetermined, but these are all things that would have to be implemented in solve() first. By the way, the nicer syntax from issue 4719 would make these much easier to enter for derivatives (right now you would have to call .subs, which is a little clunky). `````` Referenced issues: #4719 Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c7 Original author: https://code.google.com/u/asmeurer@gmail.com/
Member

### asmeurer commented Jun 17, 2011

 ``````By the way, you can't have dsolve(**ics) anyway because named keyword args have to be valid Python identifiers, not f(0). `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c8 Original author: https://code.google.com/u/asmeurer@gmail.com/
Contributor

### renatocoutinho commented Jun 17, 2011

 ``````> By the way, the nicer syntax from issue 4719 would make these much easier to enter for derivatives (right now you would have to call .subs, which is a little clunky) One possibility is to add a keyword arg 'point' to diff(). Of course that doesn't preclude the implementation of the D(f)(x) syntax. `````` Referenced issues: #4719 Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c9 Original author: https://code.google.com/u/115599828448622896355/
Member

### asmeurer commented Mar 20, 2012

 ``````**Status:** Valid `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c10 Original author: https://code.google.com/u/asmeurer@gmail.com/
Member

### asmeurer commented May 25, 2013

 ``````The new pdsolve needs this too. `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c11 Original author: https://code.google.com/u/asmeurer@gmail.com/
Member

### Krastanov commented May 25, 2013

 ``````some of this is done here[1], but it depends on actually creating a "IntegrationConstant" object (done) and fixing all the tests (not done). [1] https://github.com/sympy/sympy/pull/1322 `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c12 Original author: https://code.google.com/u/100157245271348669141/
Contributor

### ppuedom commented Oct 30, 2013

 ``````Maybe we can start implementing a simple solution that does not require a Differentiation operator or IntegrationConstant. To express initial conditions we could start with a list of tuples. dsolve(Derivative(f(x), x, 2) + 4*f(x) - sin(2*x), f(x), initial_conds=((0, 1, 2), (1, 2, 3)) ) initial_conds is a tuple of triplets. Each tuple is an initial contition with 3 values (order, point, value). Order is the derivative order, 0=f(x), 1=f'(x) etc. point is where initial condition is evaluated, and value the initial condition value. Example of triplets: (0,1,2) encodes f(1) = 2 (1,2,3) encodes f'(2) = 3 `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c13 Original author: https://code.google.com/u/118279007905392951376/
Member

### Krastanov commented Oct 30, 2013

 ``````This and more is already implemented in the pull request mentioned above. The issues with it are *not* related to math, but to integration in the current code base. On another note, I personally dislike the API you are proposing, because it has very restricted domain of applicability (but there is no consensus on this, so feel free to investigate more). `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c14 Original author: https://code.google.com/u/100157245271348669141/
Member

### asmeurer commented Nov 5, 2013

 ``````I dislike it too. {f(1):2, diff(f(x), x).subs(x, 2): 3} is much more readable, even more so if we get a D operator that lets us write the second one as D(f)(2). Furthermore, it easily extends to PDE conditions. **Labels:** Solvers `````` Original comment: http://code.google.com/p/sympy/issues/detail?id=1621#c15 Original author: https://code.google.com/u/asmeurer@gmail.com/

Open

Open

### asmeurer referenced this issue Jun 20, 2016

Merged

#### Enabling initial condition solving in dsolve #11264

1 of 4 tasks complete

### skirpichev added a commit to skirpichev/diofant that referenced this issue Sep 16, 2016

``` UnXFAIL Wester's test Z5 ```
`This finally fixes sympy/sympy#4720`
``` 8034fd9 ```

### skirpichev added a commit to skirpichev/diofant that referenced this issue Sep 16, 2016

``` UnXFAIL Wester's test Z5 ```
`This finally fixes sympy/sympy#4720`
``` f90105d ```

### skirpichev added a commit to skirpichev/diofant that referenced this issue Sep 16, 2016

``` UnXFAIL Wester's test Z5 ```
`This finally fixes sympy/sympy#4720`
``` 7be95d7 ```

### asmeurer closed this in #11264 Jul 22, 2017

to join this conversation on GitHub. Already have an account? Sign in to comment