On Fri, 31 Jul 2020 at 17:26, Mikhael Myara
<[email protected]> 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.
> 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).
> 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.
> 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.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/CAHVvXxSYoquYGqOCdavwGnafPEb%3DnqWU-L8fK%3DYkYKSs8UR%3DrA%40mail.gmail.com.