clojure-numerics / expresso

Clojure library for symbolic computation
312 stars 20 forks source link

Solving for Variables doesn't work always #8

Closed LittleHelicase closed 9 years ago

LittleHelicase commented 10 years ago

Hello,

I just discovered expresso and I'm very glad that I found it. It's really helpful but I had a little issue while solving for some variables. I tried to create a minimal example where I get the following problem:

user=> (solve 'dx (ex (= 4 dx)) (ex (= dt 5)) (ex (= cs (/ dt dx))))
#{{dx (/ (* (- cs) -1/5))}}
user=> (solve 'dt (ex (= 4 dx)) (ex (= dt 5)) (ex (= cs (/ dt dx))))
#{{dt 5}}
user=> (solve 'cs (ex (= 4 dx)) (ex (= dt 5)) (ex (= cs (/ dt dx))))
#{{cs 5/4}}

The dx is explicitly defined and cs is calculable as shown below. The equation gives the right dx but expresso somehow gives thinks it cannot solve for dx. I can solve for all variables at once and it works:

user=> (solve ['cs 'dt 'dx] (ex (= 4 dx)) (ex (= dt 5)) (ex (= cs (/ dt dx))))
#{{cs 5/4, dx 4, dt 5}}
mschuene commented 10 years ago

Hi, thanks for the report, I'll look into this. The solve 'dx behaviour is indeed strange. It seems to miss the first equation... Another thing that may be good is to make the symbol vector optional and default to solve for all variables. What do you think about it ?

arrdem commented 10 years ago

Seems like a sane default as that's probably the most frequent & obvious use case for such a solve operation, however it also seems like it will also rather frequently result in failure to find a solution for under-constrained systems of equations.

LittleHelicase commented 10 years ago

Hey,

thank you for looking into it. Getting all variables is probably the default behaviour you would expect. Seems to be a good solution for me.

mschuene commented 10 years ago

I pushed a fix to develop. solve general system could not recover when it looked at the equations at the wrong order. I am surprised this didn't come up earlier in my tests... Can you recheck with the develop branch if it works for you ? Could also do a snapshot release if it is better for you

mschuene commented 10 years ago

I pushed a new snapshot release to clojars, could you test again with it?

mschuene commented 9 years ago

I think it is solved now