Dear Oscar, Fully clear now! My main 'toy' ( I am a semi retired salesman and do all this programing for the fun of it only) is symy.physics.mechanics, which gives the first order ODE's. So, I did not think about your points. I agree, such an 'interface', to avoid the trouble and the mistakes would be excellent! Thanks,
Peter Am Do., 17. März 2022 um 01:54 Uhr schrieb Oscar Benjamin < [email protected]>: > On Wed, 16 Mar 2022 at 23:33, Peter Stahlecker > <[email protected]> wrote: > > > > Dear Oscar, > > Hi Peter! > > > Just for my understanding: > > > > Why do you feel, it would be useful for sympy to be able to numerically > solve ordinary differential equations? > > Scipy seems to have very good routines to do this - or am I wrong, and > they are not as good as I think? > > The SciPy routines are good for most usage. The mpmath library that > sympy depends on also has routines that can do high accuracy > multiprecision routines. I don't propose that SymPy should reimplement > what those libraries do. > > What is lacking is simply the code that connects from SymPy to the > existing routines in the other libraries. It should be > straight-forward for someone to use SymPy to build up a system of ODEs > and then obtain a numerical solution. Currently that is possible using > lambdify but it's more awkward than it should be given that it is a > common task. > > Those of us who are used to numerical libraries are used to the idea > that you have to transform your system to obtain a numerical solution. > Let's give an example: > > You want to solve x'' = -x with initial conditions x(0) = 1 and > x'(0)=0. How do I do that with SciPy: > > 1. First transform the 2nd order ODE into a system of 1st order ODEs: > > x' = v > v' = -x > > 2. Imagine that this is a matrix ODE X' = f(X, t) and create the function > f: > > def f(X, t): > x, v = X > dxdt = v > dvdt = -x > dXdt = [dxdt, dvdt] > return dXdt > > 3. Now pass this to the numerical solver: > > from scipy.integrate import ... > X0 = [1, 0] > t = np.linspace(0, 100, 1000) > (etc.) > > My point is that it would be nice if SymPy could do most of these > steps for you. Why should you have to translate a 2nd order ODE to 1st > order when the computer can do that for you? Why should you have to > explicitly write out the function f when you already have equations > that describe your ODE? > > The example I gave above was very simple but it takes time for people > to get their heads round how to implement those steps. (I have run > classes that teach this so I know it's not trivial!) > > Yesterday I sat next to a student and carefully compared his code with > the relevant paper and I found three mistakes in one equation. That > equation spanned several lines of code and the comparison (code vs > paper) was painstaking. If the code had built up a SymPy equation then > the equation could have been printed and compared with the paper and > then the differences would have been much more obvious. Also by using > subs etc the chance of a mistake is lower. > > That's one reason why it is better to build up your function f using > something like SymPy. Why shouldn't you do that and then ask for the > numerical solution (which the computer would then find with no other > input needed)? The chance of making mistakes could be much smaller. > > -- > Oscar > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/CAHVvXxTgmsQd7T%2B%2BkXYUngkMskk6TM9NK5iZyXzNVKa2pqPDJA%40mail.gmail.com > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CABKqA0amnZ8r%2BcQ3csVT8rniTVxxDm6w_YwqZzteA-U8fBjXpA%40mail.gmail.com.
