How to determine which one is free variable in the result of sympy.linsolve
Asked Answered
A

1

4

I want to solve the linear equation for n given points in n dimensional space to get the equation of hyper-plane.

for example, in two dimensional case, Ax + By + C = 0.

How can I get one solution if there are infinite solutions in a linear equations ?

I have tried scipy.linalg.solve() but it requires coefficient matrix A to be nonsingular.

I also tried sympy

A = Matrix([[0, 0, 1], [1, 1, 1]])
b = Matrix([0, 0])
linsolve((A, b), [x, y, z])

It returned me this {(−y,y,0)} I have to parse the result to determine which one is the free variable and then assign a number to it to get a solution.

Is there a more convenient way since I only want to get a specific solution ?

Acclamation answered 24/5, 2018 at 13:23 Comment(9)
If you are only interested in any solution, could you not add entries to the matrix to make it solveable? I guess theoretically you have to be careful to not be too close to singularity by accident, but I think solvers should warn in that case anyway and you can redisturb the systemUptown
Sorry, I don't catch the idea of not adding entries to the matrix. Could you please tell me more about it? There does exist situations the solver need to face a singular matrix. Like (0, 0) (1, 1), I want the solver could return me y - x = 0 rather than throw an exception.Acclamation
As far as I understood you don't want a specific solution or all solutions but only any specific solution. So if you change (0, 0) (1,1) to (1, 0), (1, 1) you would get one solution which still fullfills y-x=0. I.e. if you are underdetermined add arbitrary constraints until your solution is determined. I think this should work if you only need any solution, shouldn't it?Uptown
Thanks! I think I understand. But how could I know I should change (0, 0) to (1, 0) ? Actually the solution I want is the line it self. I set the form AX + BY + CZ = 0, then send it with (0, 0, 1) (1, 1, 1). wish it give me one possible set of A, B, C.Acclamation
The line itself? So you actually want to have all solutions, not just one?Uptown
yes, I want a equation of the line, I given those points on the line just in order to calculate the line equation . Not one solution of points on the line ~Acclamation
How does (-y, y, 0) differ from the result you want? Do you always want the equation in x?Uptown
(-y, y, 0) is actually what I want. Thanks! I have already solved it. just simply substitute y for a certain value using .sub method. I have no idea at the beginning because I'm new to sympy ^_^Acclamation
Greate you could solve your own problem! You can write an answer here and accept it so that future readers with the same problem as you can benefit from your solution.Uptown
S
0

Here, obviously, your equation has a free variable which is your second one. Because the first one (x) is represented by your second variable (y) as the negative relationship, your second is a "y" value, which theoretically can be any value so it is a free variable. And your third variable z is 0 and is a not free variable.

Shroudlaid answered 4/6, 2023 at 1:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.