- Join over
**1.5M+ people** - Join over
**100K+ communities** - Free
**without limits** - Create
**your own community**

- 04:12sylee957 commented #18369
- 04:06oscarbenjamin commented #18367
- 04:04namannimmo10 commented #10961
- 04:03klim- commented #18367
- 04:02klim- commented #18367
- 03:58klim- commented #18367
- 03:53klim- commented #18367
- 03:50klim- commented #18367
- 03:49klim- commented #18367
- 03:49klim- commented #18367
- 03:43sympy-bot commented #18371
- 03:43sylee957 labeled #18371
- 03:43sylee957 opened #18371
- 03:11
oscarbenjamin on master

Fixed Pretty Printing for Condiā¦ Test Case Fixed Hotfix and 2 more (compare)

- 03:11oscarbenjamin closed #18364
- 03:11oscarbenjamin closed #17339
- 03:11oscarbenjamin closed #18272
- 03:11codecov[bot] commented #18244
- 03:11oscarbenjamin commented #18364
- 03:06oscarbenjamin labeled #18363

@Ashwin-Shenoy-NITK How exactly are you specifying the upstream?

'Coz `git remote add upstream git@github.com:sympy/sympy.git`

might throw that error as you don't own the repository and you won't have the access rights.

If that is the case, you could simply use `git remote add upstream https://github.com/sympy/sympy`

there.

I'm using sympy to solve some linear systems in my finite difference model (since I need nullspaces, I cannot use numpy least square directly).

Also since I don't know beforehand the size of my linear system (not big for now, not bigger than 10 variavles). I'm solving it without specify the "symbols" because I really don't care.

the line to solve is simpleand looks like

`linsolve(Matrix(np.c_[V,o]))`

.
in this specific case (i think 6 variables involved), I got a free variable as response

`{(-1.0*tau0 - 0.916666666666667, 5.0*tau0 + 0.708333333333333, -10.0*tau0 + 0.375, 10.0*tau0 - 0.208333333333333, -5.0*tau0 + 0.0416666666666667, tau0)}`

, seems is autonamed `tau0`

I want to eval

`tau0 = 0`

, but without know the variable name before hand.
something like

`lin(Matrix(np.c_[V, o])) | all_free_variables = 0`

`r.evalf(subs={tau0: 0})`

doesn't works, and also ) don't want to specify the variable name, since I will not know beforehand
neither

`r.subs(tau0, 0)`

, both complain about `tau0`

not being defined
the

`mysolution`

is a numpy array as you could notice.
`If no symbols are given, internally generated symbols will be used.`

It seems that you can give the names that you would like to use instead of the generated names like

`tau0`

.
@jksuom in fact, I don't even know the size of the matrix beforehand. It will depend on size of the grid loaded. can have 500 variables.

@valglad The

`solution_as_list`

, didn't returns a list per se, but a set with a tuple, as in: `{(-0.916666666666667, 0.708333333333333, 0.375, -0.208333333333333, 0.0416666666666667, 0)}`

of type `sympy.sets.sets.FiniteSet`

.
@valglad Regarding to the numpy line. I'm very sticky to numpy, since I oftern work with it. Maybe I will keep everything inside sympy, until get the final solution.

Ah, wait, that doesn't flatten it. So you'll have to do what you did or use SymPy's

`flatten`

anyway... Never mind then
Actually,

`solution = np.array(*[e for e in r_tmp]).astype(float)`

should flatten it as well

wow. :-( Given the matrix `PI`

```
array([[ -0.917, 0.042, 0. , 0. , -1. ],
[ 0.708, -1.125, 0.042, 0. , 5. ],
[ 0.375, 1.125, -1.125, 0.042, -10. ],
[ -0.208, -0.042, 1.125, -1.125, 10. ],
[ 0.042, 0. , -0.042, 1.125, -5. ],
[ 0. , 0. , 0. , -0.042, 1. ]])
```

and the vector `c`

`array([-1. , 0. , 0. , -0.042, 1.083, -0.042])`

the solution given by

`linsolve(Matrix(np.c_[PI,c]))`

returns an `EmptySet()`

while the same operation in Maple 16 returns non empty, and exactly

`np.array([649/576, 143/192, 75/64, 551/576, -25/13824])`

that in float is around

`array([ 1.127, 0.745, 1.172, 0.957, -0.002])`

Any ideas?

the example in maple is shown above

for sake of this test it was created using the ratios, as in

```
PI = np.array([
[-11/12, 1/24, 0, 0, -1],
[ 17/24, -9/8, 1/24, 0 ,5],
[3/8, 9/8, -9/8, 1/24, -10],
[-5/24, -1/24, 9/8, -9/8, 10],
[1/24, 0, -1/24, 9/8, -5],
[0, 0, 0, -1/24, 1]
])
```

Ideas, are very likely welcome.

It seems that your system is over-determined. It has 6 equations in 5 variables. It can have solutions only if the determinant of the extended system is 0.

```
>>> P = Matrix([[ -0.917, 0.042, 0. , 0. , -1. ],
... [ 0.708, -1.125, 0.042, 0. , 5. ],
... [ 0.375, 1.125, -1.125, 0.042, -10. ],
... [ -0.208, -0.042, 1.125, -1.125, 10. ],
... [ 0.042, 0. , -0.042, 1.125, -5. ],
... [ 0. , 0. , 0. , -0.042, 1. ]])
>>> c = Matrix([-1. , 0. , 0. , -0.042, 1.083, -0.042])
>>> Pc = P.row_join(c)
>>> Pc.det()
0.000998125750125132
```

In this example, the determinant not 0 because of the inaccuracy of floating point numbers. Hence there is no solution.

i am learning python megacourse on udemy and it is also teaching numpy, so i was wondering if it might be useful

A potential solution could be to define

`rationalize = lambda x: [nsimplify(e) for e in x]`

(this will turn numbers from a list into rationals). And then do

```
PI = Matrix(map(rationalize, [
[-11/12, 1/24, 0, 0, -1],
[ 17/24, -9/8, 1/24, 0 ,5],
[3/8, 9/8, -9/8, 1/24, -10],
[-5/24, -1/24, 9/8, -9/8, 10],
[1/24, 0, -1/24, 9/8, -5],
[0, 0, 0, -1/24, 1]
]))
```

and similarly for `c`

. I've just checked and this returns the right solutions

@valglad Amazing! I will test.

There are 6 rows and only 5 columns. One row could be omitted.