On Fri, 31 Jul 2020 at 21:06, Mikhael Myara
<mikhael.my...@umontpellier.fr> wrote:
>
> Le vendredi 31 juillet 2020 20:46:08 UTC+2, Oscar a écrit :
>>
>> On Fri, 31 Jul 2020 at 17:26, Mikhael Myara
>> <mikhae...@umontpellier.fr> wrote:
>> >
>> > Thanks for your answer.
>> >
>> > I don’t do it « for sport » ;-) My example is a reduced example coming 
>> > from a practical situation I encountered.
>>
>> I understand that you have reduced this but it is a lot better if the
>> reduction is self-contained so that others can literally copy-paste
>> the code to test what is happening with an expression that
>> demonstrates the issue. I could probably tell you exactly what the
>> problem is in a given example if you provided minimal code for that
>> example.
>>
> That's what I did in my first post + screen copies :
>>
>> import sympy as sp
>>
>> H=-(-CB*Ve*s*(-CA*s - 1/RA)**2/(RB*(CB*s + 1/RB)*(CA*s - (-CA*s - 
>> 1/RA)**2/(CA*s - CB**2*s**2/(CB*s + 1/RB) + CB*s + 1/RA) + 2/RA)*(CA*s - 
>> CB**2*s**2/(CB*s + 1/RB) + CB*s + 1/RA)) - CB*Ve*s/(RB*(CB*s + 
>> 1/RB)))/(Ve*(CA*s - CB**2*s**2/(CB*s + 1/RB) + CB*s + 1/RA))

Have you tried copy-pasting that? I get this:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'CB' is not defined

Of course I'm being pedantic because I can guess that all of those are
supposed to be symbols but it takes some time for me to figure out
what symbols they are and write the small piece of code that defines
them (presumably that's what Aaron did). More importantly there are
multiple ways to define a symbol (real, positive, ...) and some
simplifications depend on that so even if I do fill in the missing
code then I won't know if I'm seeing the same behaviour as you.

>> > I developed a small software that solves the voltages and currents of an 
>> > electronic circuit described by means of a standard format (« netlist »). 
>> > This file is parsed, equations are solved. In this netlist file, the 
>> > values of the components are given.
>>
>> How exactly are they given in the file (e.g. to how many digits)?
>>
>> If the file has something like 0.12 then you can read that in directly
>> as Rational('0.12') rather than converting the string to a float. Then
>> you will have an object that represents the value from the file
>> exactly with no rounding error. Alternatively you can use nsimplify to
>> convert the floats to an approximate rational representation (direct
>> string to Rational is better though).
>
> Values can change a lot, from 1é-10 to 1e10 typically. In most cases 2 to 3 
> significant numbers, but can be much more.

It sounds like these would be fine to parse directly as Rational when
reading the file:

>>> from sympy import *
>>> Rational('1e-10')
1/10000000000
>>> Rational('0.112345e-10')
22469/2000000000000000

If you want to display the result with decimal dot notation then you
can convert the Rationals in any expression to Float at the end for
printing using the nfloat function:

>>> nfloat(_)
1.12345000000000e-11


-- 
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 sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxQKZCWpJSmjXPsDa8oQYxRBG%2B%2BfBwpWhK8720S2wnm2eg%40mail.gmail.com.

Reply via email to