James Tran | 25 May 12:26 2015
Picon

Save matrix to file

Dear all,
The matrix in sympy save as dictionary. I want to save a big matrix with size 30000x30000. Is there any method to save it to hard-disk driver? I tried with numpy but
it cannot work.

Thank you,

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/65675cce-dbc5-421c-a990-67b81c8b0a91%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
dorislee | 24 May 21:18 2015
Picon

Expressing equation in terms of variables

Hi all,

I am new to SymPy and I am trying to rearrange equations in order to express one variable in terms of another in SymPy.
For example, I have two physics equations F=ma and rho=m/v which I defined in the beginning. I want to re-express ``a`` in terms of f,rho, and v.
However, the ``solve`` function sets the right hand side of the equation so that it is equal to zero so then when I try to get ``a`` in terms of `f` it returns zero.
Is there a way  I could do this SymPy, if so, which function should I be looking at instead?

Thank you.



In [6]:
from sympy import *
In [11]:
f = Symbol('f')m = Symbol('m')a = Symbol('a')rho = Symbol('rho')v = Symbol('v')
In [37]:
f=m*arho=m*v
In [38]:
solve(a,[f])
Out[38]:
[]
In [39]:
solve(rho,[v])
Out[39]:
[0]
In [42]:
solve_linear(f-m*a,f)
Out[42]:
(m, 0)

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/b3475c31-357a-4f59-abe1-a4b43a78892e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
drazioti | 20 May 00:14 2015
Picon

theano and sympy

Hi,

I was experimenting with the following code:

import sympy
from sympy.abc import x
expr = sympy.exp(-x ** 2)
from sympy.printing.theanocode import theano_function
fn_theano  = theano_function([x], [expr], dims={x: 1}, dtypes={x: 'float64'})
print fn_theano([29.]),sympy.exp(-29.**2)

I got 

[ 0.] 5.73245586032578e-366
My question is why fn_theano does not give the same value?Thank you,Costas


--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/4662668c-68b0-482e-b467-92a6d2206d2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Oscar Benjamin | 19 May 23:00 2015
Picon

Magnitude of a complex number

Am I misunderstanding something here (using master):

$ isympy
Couldn't locate IPython. Having IPython installed is greatly recommended.
...
>>> z = (4+3*I)/(3-4*I)
>>> z
4 + 3⋅ⅈ
───────
3 - 4⋅ⅈ
>>> abs(z)
  │   1   │
5⋅│───────│
  │3 - 4⋅ⅈ│
>>> simplify(abs(z))
  │   1   │
5⋅│───────│
  │3 - 4⋅ⅈ│
>>> abs(z).evalf()
1.00000000000000
>>> abs(z) ** 2
            2
   │   1   │
25⋅│───────│
   │3 - 4⋅ⅈ│
>>> z * z.conjugate()
(4 - 3⋅ⅈ)⋅(4 + 3⋅ⅈ)
───────────────────
(3 - 4⋅ⅈ)⋅(3 + 4⋅ⅈ)
>>> simplify(z * z.conjugate())
1

Why doesn't abs(z) simplify (or should I open an issue)?


--
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+unsubscribe <at> googlegroups.com.
To post to this group, send email to sympy <at> googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxS6DNZR8dPJ5AZ96V7MKtZQrvug_Pjs2%3DLejVOP6e73aw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Jonathan Lindgren | 19 May 21:16 2015
Picon

Bug with substituting derivatives

I recently updated from sympy 0.7.4 (I tihnk) to 0.7.6 and now I have some very strange behaviour with subs. The following code

from sympy.abc import phi
import sympy as sp

z=sp.Symbol('z')
t=sp.Symbol('t')
sp.pprint((phi(z,t).diff(t,2)).subs(phi(z,t).diff(z),sp.Symbol('b')(z,t)).expand())


gives me the output    
  2        
 ∂         
───(b(z, t))
  2        
∂t  
but I would expect the output
  2        
 ∂         
───(φ(z, t))
  2        
∂t 

This was working perfectly in my previous version of sympy.

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/a50b1e03-3c37-4207-bc4b-7b6663c80c84%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Arnaud Usciati | 19 May 13:29 2015
Picon

Bug with solve

Hello,

I tried to find the roots of : 2*sqrt(x)*sqrt(x**3 - x**2 + 1) + 2*x**3 - x**2 + x*sqrt(x**3 - x**2 + 1) + 2*x**1.5 + 2*x**2.5*sqrt(x**3 - x**2 + 1) - 3*x**2.5 - 4*x**3.5*sqrt(x**3 - x**2 + 1) - 2*x**3.5 + 5*x**4.5 - 3*x**5.5 - 1 = 0.

x = symbols('x', real=True)
f = Lambda(x, 2*sqrt(x)*sqrt(x**3 - x**2 + 1) + 2*x**3 - x**2 + x*sqrt(x**3 - x**2 + 1) + 2*x**1.5 + 2*x**2.5*sqrt(x**3 - x**2 + 1) - 3*x**2.5 - 4*x**3.5*sqrt(x**3 - x**2 + 1) - 2*x**3.5 + 5*x**4.5 - 3*x**5.5 - 1)

Input : solve(f(x), x)
Output : [0.149910458676117, 0.865324593883105, 1.00000000000000, 1.24896947842683, 2.56371129870321, 3.02429035798029]

But only 0.149910458676117 and 1 are really roots :
f(0.865324593883105) = 0.735269457206734
f(1.24896947842683) = -4.09736628717860
f(2.56371129870321) = -509.709822051607
f(3.02429035798029) = -1361.51149028959

Arnaud,

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/ece1f69e-919b-4bde-ab31-9213adf06c35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Carsten Knoll | 18 May 15:56 2015
Picon
Picon

How to equip a Symbol with an additional attribute?

I want to equip an Symbol with an additional attribute to store some
specific information right in place.

For 'normal' Python classes it is no problem to dynamically create an
additional attribute for an already existing instance.

However, for sympy Symbols if I try

x = Symbol('x')
x.k = 0

I get the error

AttributeError: 'Symbol' object has no attribute 'k'

Is there any possibility to equip the Symbol x with this attribute?

I already tried this workarround:

class ExtendedSymbol(sp.Symbol):
    pass

x = ExtendendSymbol('x')

x.k = 0 # no problem here

However then I have the following unwanted behavior:

x2 = sp.Symbol('x')
x2 == x # -> False

Any ideas?

Best regards,
Carsten.

--

-- 
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+unsubscribe@...
To post to this group, send email to sympy@...
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/5559EF9B.3090106%40gmx.de.
For more options, visit https://groups.google.com/d/optout.

ravas | 17 May 20:00 2015

floating away from the rational

My goal is to input the coordinates of the vertices of a triangle and have significant properties printed for a human to read.
I'm aware of the limitation of floating point arithmetic, and I was able to produce an accurate area with the decimal module.

return (sp*(sp-a)*(sp-b)*(sp-c)).sqrt().quantize(dec('1.0000000000'))

However, a version using sympy is also desirable. Do I need to install mpmath / gmpy to compensate for the floating point errors?
Here is the test code:

import sympy.functions as sym
import sympy.geometry as geo

sqrt
= sym.sqrt

def distance(A, B):
 
"""
 A & B are objects with x and y attributes
 :return: the distance between A and B
 """

 dx
= B.x - A.x
 dy
= B.y - A.y
 
return sqrt(dx**2 + dy**2)

def sides(A, B, C):
 
"""
 A, B & C are objects with x and y attributes
 :return: sorted side lengths (smallest to largest)
 """

 a
= distance(B, C)
 b
= distance(A, C)
 c
= distance(A, B)
 
return sorted((a, b, c,), key=float)

def area(a, b, c):
 
"""
 a, b & c are the side lengths of the trigon
 :return: area of the trigon
 """

 p
= a + b + c # perimeter
 sp
= p / 2 # semi-perimeter
 
return sqrt(sp*(sp-a)*(sp-b)*(sp-c))

if __name__ == '__main__':
 p
= geo.Point
 A
= p(0, 0)
 B
= p(3, 0)
 C
= p(3, 3)
 sides
= sides(A,B,C)
 
print(sides)
 
print(area(*sides))

Output: 

[3, 3, 3*sqrt(2)]
sqrt
(-3*sqrt(2)/2 + 3)*sqrt(27*sqrt(2)/4 + 27/2)

Obviously I want 9/2 as the result for the area... but it is giving me a representation of 4.4999999999...
What can I do about this?

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/f0e6480a-f56d-43c7-a07d-883c97103834%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Gaurav Dhingra | 17 May 09:13 2015
Picon

Expressions Involving Infinity

>>> from sympy import Symbol, oo, simplify
>>> x = Symbol('x', real=True)
>>> simplify( x*oo )
oo*x

Do we use extended real number system(Affinely Extended Real Number System) in sympy ?
If we do use them, then why not expressions like these  "x*oo" evaluated to a Piecewise function like 
>>> Symbol('x')
>>> simplify( x*oo )
Piecewise( ( -oo, x< 0 ), ( oo, x > 0), (Nan, x==0 ))       # i expect this to happen.

Gaurav Dhingra

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/33347c95-dba2-47a5-99f1-b8d7cbdd3c59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
John | 16 May 21:56 2015
Picon

best way to solve time-dependent series of equations

Hello:
I am seeking the most elegant way to use Sympy to solve a time-dependent series of equations.  As a simple example, consider a three-compartment model with compartments A, B, and C.  Flow occur from A to B, and from B to C.  The following solves such a system that is not time-dependent:

import sympy as sym
import numpy as np

fractAB = .1
fractBC = .2

A, B, C, flowAB, flowBA, flowBC, flowCB = sym.S('A, B, C, flowAB, flowBA, flowBC, flowCB'.split(',')) 

equations = [
  sym.Eq(A,10),
  sym.Eq(flowAB, A*fractAB),
  sym.Eq(flowBC, B*fractBC),
  sym.Eq(A, flowBA - flowAB),
  sym.Eq(B, flowAB + flowCB - flowBA - flowBC),
  sym.Eq(C, flowBC - flowCB),
  sym.Eq(C, 0)
  ]   
 
res = sym.solve(equations)

My question is, what is the most elegant way to solve the system of equations if fractAB and fractBC are both functions of time (perhaps specified as a numpy array, with each element representing a time step).  Can someone please suggest a snipit of code to do this?  One way would be to hold fractAB and fract BC in a 2xn matrix, M, where n is the number of time steps.  Then the code above could simply be put in a for loop, as in:

for i in range(n):
    fractAB = M[0,i]
    fractBC = M[1,i]
    ... same code as above, with each iteration producing a result from the call to solve.

But there is probably a more elegant way to do this.  Thanks in advance for the suggestions.

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/dbc03f22-e060-4ba0-bd29-3eb6b2496a84%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The Lartians | 15 May 12:56 2015
Picon

Reliable Sympy

Hello,

I'm a physics student from Göttingen and currently working on scientific simulation software in c++. I am currently using sympy in my python wrappers as it allows a convenient way for users to define and view simulation functions (they get compiled on-the-fly and are passed as function pointers to the simulation). However I've run into a few issues on the way. For example, simplify on small imaginary numbers yields 0 (which in my case can have a huge impact on the simulation). Additionally, integrals of piecewise functions often return bad results (if they evaluate at all). These bugs make it impossible for me to use sympy in good conscience with scientific projects.

I was therefore wondering if a "reliable" version of sympy exists, meaning a version where all code known to contain bugs or produce bad results is excluded until fixed. Otherwise I would probably create a branch.


Thanks and regards,

Lars


FYI I was talking about these Issues:
- https://github.com/sympy/sympy/issues/9398
- http://stackoverflow.com/questions/30155166/integral-of-piecewise-function-gives-incorrect-result/30179185

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/757f9348-5c7a-4e54-8144-ccc8ed305991%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gmane