Hi Petr, On Wed, Feb 18, 2015 at 10:01 AM, Aaron Meurer <[email protected]> wrote: > On Tue, Feb 17, 2015 at 10:41 PM, Petr Baudis <[email protected]> wrote: >> On Tue, Feb 17, 2015 at 02:58:35AM -0800, Petr Baudis wrote: >>> >>> On Tuesday, February 17, 2015 at 3:54:32 AM UTC+9, Jason Moore wrote: >>> > >>> > Here is one way to do it: >>> > >>> > https://gist.github.com/moorepants/858503aa180df60a7829 >>> >>> Oh, thanks a lot! I didn't think about approaching it this way, and it >>> makes a lot of sense. >>> I'll play with this more, but it's a big step forward for me! >> >> I have rewrote your solution a bit to lend better to autogeneration from >> predicate form that I use as an intermediate form: >> >> import sympy as sym >> from sympy import init_printing >> t = sym.symbols('t', real=True) >> eqs = [] >> >> g = sym.symbols('g', real=True, positive=True) >> >> x_r, v_r = sym.symbols('x_r, v_r', cls=sym.Function) # functions of >> time >> x0_r, v0_r = sym.symbols('x0_r, v0_r', real=True) >> accel_r = sym.Eq(x_r(t).diff(t, 2), -g) >> position_r = sym.dsolve(accel_r, x_r(t)).subs({'C1': x0_r, 'C2': >> v0_r}) >> eqs.append(position_r) >> velocity_r = sym.dsolve(accel_r.subs({x_r(t).diff(t): v_r(t)}), >> v_r(t)).subs({'C1': v0_r}) >> eqs.append(velocity_r) >> >> h = sym.symbols('h', real=True) >> eqs.append(position_r.subs({x_r(t): h, t: 0})) >> eqs.append(velocity_r.subs({v_r(t): 0, t: 0})) >> >> t_e2 = sym.symbols('t_e2', real=True) >> eqs.append(position_r.subs({x_r(t): 0, t: t_e2})) >> >> print(eqs) >> print(sym.solve(eqs, v_r(t))) >> >> So one curious observation I have is that even if sym.solve() is given >> multiple equations and only a single variable, it does yield a solution >> in this case. I'm still confused about what the exact API contract of >> sym.solve() is. Working "sometimes" leaves me unsure about what I can >> or cannot rely on... > > Sadly, there is none. Part of this is due to algorithmic limitations > (solve() is basically a bunch of heuristics, there are few guarantees > that it will find a solution if it exists). But a lot of it is just > poor design. We are trying to make the design better with the new > solveset module. > > Aaron Meurer > >> >> Of course, the much more important problem for me is that this will >> again generate just a formula of v_r(t) depending on t, instead of the >> other parameters, and I see no easy way to ask SymPy for a solution >> without t in it. Jason's solution is to first compute the time: >> >> # Remove position_r, velocity_r from eqs >> sol = sym.solve(eqs, t_e2, x0_r, v0_r, dict=True) >> final_velocity = velocity.subs({t: tf}).subs(sol[0]) >> >> but that's the problem - I need to know I need to compute the time >> first, and it's not clear what kind of rules to figure out what to >> compute I will need with different combinations of equations. (In other >> words, I would have hoped a CAS would have this figured out already. :-) >> >> (The other thing of also including x0_r, v0_r in solve set is not so >> bad, that might be fixed by a simple semi-automated substitution step.) >> >> Right now I'm inclined to conclude that what I want to do *is* rather >> hard and I'd have to come up with some new algorithms to deal with this. >> (Or likely take a look at some other CASes first if any handle this case >> for me already.)
If you find some other CAS that can do this better, please let us know and post here your solution. As Aaron said, we would like to improve our solver module. Thanks, Ondrej >> >> -- >> Petr Baudis >> If you do not work on an important problem, it's unlikely >> you'll do important work. -- R. Hamming >> http://www.cs.virginia.edu/~robins/YouAndYourResearch.html >> >> -- >> 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 post to this group, send email to [email protected]. >> 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/20150218044144.GI6082%40machine.or.cz. >> For more options, visit https://groups.google.com/d/optout. > > -- > 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 post to this group, send email to [email protected]. > 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/CAKgW%3D6LcGaCDCJWcvHwsrTq39nEuYY8xopbYLesa839bHk6MGA%40mail.gmail.com. > For more options, visit https://groups.google.com/d/optout. -- 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 post to this group, send email to [email protected]. 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/CADDwiVA_UEqm-EGiT1zrypqoERk7Dc6De1XMcjATvUwuMq8XxA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
