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 <javascript:>> 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)) > > H1=H.subs({RB:1e3,CA:1e-6}) > display(H1) > H1.simplify() > display(H1) > > H2 = H.simplify() > display(H2) > H3=H2.subs({RB:1e3,CA:1e-6}) > H3=H3.simplify() > display(H3) > > > Here it is : > > 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. > > > I imagined that I could mix symbolic and numerical values in the > description of the circuit (for example we want to study de variations of a > single component, not of all), and it seems to be a bad idea because mixed > expressions seem to be really difficult to handle for Sympy. > > Generally speaking simplification will work better with numbers rather > than symbols. However this is only true if you give numbers in exact > form. When you pass a float to sympy it will be treated as an > inherently imprecise object. As a result many simplifications will be > refused and also any arithmetic will be computed in floating point. > The kind of simplification needed here is most likely factorisation > and cancellation of polynomials which is poorly conditioned in > floating point. > ok. > > > So I will have to make 100% symbolic treatment and then only replace the > values of the components. It was to explore the possibilities for my ? > students : this kind of question will help me giving to them good > orientations during classroom work. > > If the class work involves using sympy then good orientation would be > to avoid the use of floats in symbolic computation. > Indeed. > > -- > 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/dcd80f3b-6394-4460-aa81-76209fb67880o%40googlegroups.com.