Ask Your Question

loSuarezB's profile - activity

2020-12-20 22:18:48 +0200 received badge  Popular Question (source)
2018-11-20 17:47:28 +0200 commented answer Evaluate from string an equation that has integer division

I'm using 'SageMath version 7.5.1, Release Date: 2017-01-15' because I could not install the new SageMath 8.X., this is another problem I would afford next.

2018-11-20 17:45:13 +0200 commented answer Evaluate from string an equation that has integer division

I put the sentence from __future__ import division at the beginning of my file 'twophasevolumeweightunsat.sage' and I become the following Error Message:

sage: load('twophasevolumeweightunsat.sage')
  File "<string>", line 2
SyntaxError: from __future__ imports must occur at the beginning of the file
2018-11-20 17:44:54 +0200 answered a question Evaluate from string an equation that has integer division

I put the sentence from __future__ import division at the beginning of my file 'twophasevolumeweightunsat.sage' and I become the following Error Message:

sage: load('twophasevolumeweightunsat.sage')
  File "<string>", line 2
SyntaxError: from __future__ imports must occur at the beginning of the file
2018-11-20 17:20:40 +0200 received badge  Editor
2018-11-20 17:18:50 +0200 answered a question Converting strings into expressions

Well, but this does no work for the following case. I want to define an equation from a string, by changing the value of gammaWStr='9.81' by a string that is a number.

gammaW - gammaWStr == 0

If I follow the suggested construction like

exprString = 'gammaW - ' + gammaWStr + ' == 0'
eq0 = SR(exprString)

I get the Error Message

TypeError: Malformed expression: gammaW - 9.81 == !!!  0

In other words, and referring to the first question, How about an expression like expression = "x1^2*x2*x3*4==0"?

2018-11-19 18:11:45 +0200 received badge  Autobiographer
2018-11-19 18:07:42 +0200 received badge  Scholar (source)
2018-11-18 19:49:37 +0200 received badge  Student (source)
2018-11-18 19:09:33 +0200 asked a question Evaluate from string an equation that has integer division

I have the following Python list that contains strings of equations.

L = ['651/349*t + 5382747/9778631000', 't + 57879/196133000', '1000/349*t + 57879/68450417']

You can see that all of the equations have integer division. Because this is obtained by some program, I can not edit the strings.

When I evaluate for t=1.0 with the following code in SageMath (for example), it does not evaluate as an Euclidean division.

F = function('F')(t)
for k in L:
    F(t) = eval(k)
    Fc = fast_callable(F, vars=[t])
    val2eval = 1.0
    print(Fc(val2eval).n(13))

It gives

1.00000000000000
1.00000000000000
2.00000000000000

And should be give

1.86587997307599
1.00029510077345
2.86617507384944

Of course I can solve this by modifying MANUALLY the strings of the equations by indicating that the denominator is a real number and not an integer (I put a decimal point at the end of the integer in the denominator) as following.

L = ['651/349.*t + 5382747/9778631000.', 't + 57879/196133000.', '1000/349.*t + 57879/68450417.']

But this is not the idea, the strings of the equations are generated automatically and one can not modify by editing manually, because it will be implemented in a process where it should be create at least 2000 equations.

Is there some elegant solution for this? --Many thanks!