Oh ! I put the 1st eq wrong. It is this :
In [15]: fv,ev = symbols('fv,ev')
In [17]: expr1 = -fv + ev+sample_volume
In [18]: expr2 = final_concentration*fv - ev*ethanol_concentration
In [19]: solve([expr1,expr2], [fv,ev])
Out[19]: {ev: 26.8292682926829, fv: 46.8292682926829}
In [20]: linsolve([expr1,expr2], [fv,ev])
Out[20]: {(46.8292682926829, 26.8292682926829)}
linsolve <http://docs.sympy.org/dev/modules/solvers/solveset.html#linsolve>
is newly implemented linear system solver for solveset. You can use
invert_real
<http://docs.sympy.org/latest/modules/solvers/solveset.html#sympy.solvers.solveset.invert_real>
to
get particular symbol at lhs side.
--
Shekhar
On Friday, 16 December 2016 20:09:59 UTC+5:30, Bjorn wrote:
>
> Hi and thanks for the reply,
>
> Your solution seems correct except for the values being negatives.
> how is linsolve different from solve? I would also like to have the
> equation simplified so that
> the unknown is expressed in terms of the knowns like:
>
> ethanol_vol =
> final_concentration*sample_volume/(ethanol_concentration-final_concentration)
>
> see first cell in this sympy notebook
> <https://anaconda.org/BjornFJohansson/sympy/notebook>.
>
> /bjorn
>
>
>
> On Thursday, December 15, 2016 at 6:07:04 AM UTC, Shekhar Prasad Rajak
> wrote:
>>
>> I think you want to solve for final_volume, ethanol_vol
>>
>> In [2]: sample_volume=20
>> ...: final_concentration=0.55
>> ...: ethanol_concentration=0.96
>> ...:
>>
>> In [4]: fv,ev = symbols('fv,ev')
>>
>> In [5]: expr1 = fv - ev+sample_volume
>>
>> In [6]: expr2 = final_concentration*fv - ev*ethanol_concentration
>>
>> In [7]: solve([expr1,expr2], [fv,ev])
>> Out[7]: {ev: -26.8292682926829, fv: -46.8292682926829}
>>
>> # I will recommend you to use solveset's linear system solver (linsolve)
>> In [8]: linsolve([expr1,expr2], [fv,ev])
>> Out[8]: {(-46.8292682926829, -26.8292682926829)}
>>
>>
>> --
>> Shekhar
>>
>> On Wednesday, 9 November 2016 15:48:56 UTC+5:30, Bjorn wrote:
>>>
>>> Hi, I am a sympy newbie, and I would like to use sympy to solve equation
>>> systems. I don't expect these systems to be huge or complicated.
>>>
>>> I would like to be able to process equations in plaintext such as this:
>>>
>>> sample_volume=20
>>> final_concentration=0.55
>>> ethanol_concentration=0.96
>>>
>>> final_volume = ethanol_vol+sample_volume
>>> final_concentration*final_volume=ethanol_vol*ethanol_concentration
>>>
>>> I have hacked together a simple sympy script
>>> <https://anaconda.org/BjornFJohansson/sympy/notebook> that solves the
>>> above system.
>>> I have a couple of questions regarding this:
>>>
>>> - has this been done before? I would like to use tested code if possible.
>>> - is it possible to incorporate units in the calculations? This issue
>>> <https://github.com/sympy/sympy/issues/5156> suggests that it is not.
>>> - are there any immediately apparent gotchas the code above? I would
>>> like to have a system for solving equations not much more complex than the
>>> example.
>>>
>>> Grateful for input. I asked the same question on stackoverflow
>>> <http://stackoverflow.com/questions/40459915/solving-set-of-linear-equations-in-plaintext-using-sympy>
>>> but
>>> I got no response.
>>>
>>> Thanks,
>>> Björn
>>>
>>
--
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 https://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/c79f132b-4c6e-4b13-bac7-5f1c55ae9ff9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.