linear-equation

Solve the linear equations system AX = B in Python, np.linalg.solve not working

痴心易碎 提交于 2021-01-29 11:29:42
问题 I'm trying to solve the linear equation AX=B where A,X,B are Matrices. I've tried using the np.linalg.solve function of numpy but the result seems to be wrong. Example: Matrix A [9 1 8] [3 2 5] [1 6 5] Matrix B [7 0 5] [7 8 4] [5 6 7] So to solve X, i've used: X = np.linalg.solve(A,B) The result is: X [ 1.17521368 -0.17948718 0.40598291] [ 0.20512821 -0.30769231 0.74358974] [-0.56410256 -0.15384615 1.20512821] But if i try to verify the result by multiplying A by X, the result is anything but

LAPACK inversion routine strangely mixes up all variables

我怕爱的太早我们不能终老 提交于 2020-01-25 02:19:10
问题 I'm programming in fortran and trying to use the DGETRI matrix inverter from the Lapack package: http://www.netlib.org/lapack/explore-html/df/da4/dgetri_8f.html But very strangely it seems to be messing with all my variables. In this very simple example, my matrix A initialised at the beginning of the program changes as DGETRI is applied, even though DGETRI doesn't involve A… Can anybody tell me what is going on? Thanks! PROGRAM solvelinear REAL(8), dimension(2,2) :: A,Ainv REAL(8)

Trying to solve a system of linear equations in matlab

半腔热情 提交于 2020-01-05 09:02:52
问题 I've been set a question asking me to solve a system of linear equations. In the question it states I should set up a matrix A and column vector b to solve the equation A x = b , where x is the column vector (w x y z). A = [1 1 1 1; 0 1 4 -2; 2 0 -2 1; 1 -2 -1 1] b = [28;7;22;-4] A1 = inv(A).*b sum(A1,2) This is what I've done so far, however I know the answer that MATLAB gives me is incorrect, as the right solutions should be w=10.5, x=9, y=2.5, z=6. Can someone point me in the right

Parse Coefficient of an Linear equation

牧云@^-^@ 提交于 2020-01-03 20:14:31
问题 In java i am trying to find the coefficients of a linear equation to find solution of linear equation in my calculator application for example : 3x +2*(6x-3) = 2 -4x what i am dying to get is the coefficients of x and the constant in the form ax+b =0 , in this particular example coefficient = 19 constant = -8 Please suggest a generalized idea 回答1: As already suggested by my comment: This may be arbitrarily complicated, depending on what exactly this parser should support. There are several

Solving a system of linear equations in a non-square matrix [closed]

微笑、不失礼 提交于 2020-01-01 09:54:11
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 months ago . I have a system of linear equations that make up an NxM matrix (i.e. Non-square) which I need to solve - or at least attempt to solve in order to show that there is no solution to the system. (more likely than not, there will be no solution) As I understand it, if my matrix is not square (over or under

How to extend the line of 2 PolyFit from either side to intersect and get a combined fit line

99封情书 提交于 2019-12-25 08:34:41
问题 I am trying to get combined fit line made from two linear polyfit from either side (should intersect), here is the picture of fit lines: I am trying to make the two fit (blue) lines intersect and produce a combined fit line as shown in the picture below: Note that the crest can happen anywhere so I cannot assume to be in the center. Here is the code that creates the first plot: xdatPart1 = R; zdatPart1 = z; n = 3000; ln = length(R); [sX,In] = sort(R,1); sZ = z(In); xdatP1 = sX(1:n,1); zdatP1

Why is an empty list returned when solving for this linear system in Maxima?

房东的猫 提交于 2019-12-24 19:38:35
问题 I'm trying to solve a simple linear system in Maxima using solve like so: /*Standard form*/ eq1 : x1 + 3*x2 + s1 = 6; eq2 : 3*x1 + 2*x2 + s2 = 6; base1 : solve([eq1,eq2],[s1,s2]); This however returns an empty list and I don't know why. Any ideas? I'm pretty sure the system has a solution, so that shouldn't be the issue. EDIT: I attempted to insert the equations explicitly into solve in place of eq1 and eq2 , and now it works. Now the question is, why do I need to explicitly insert the

Function to translate linear equations into matrix form in R?

五迷三道 提交于 2019-12-23 10:55:06
问题 I was wondering whether there exist any packages or other pre-built solutions for R that are capable of translating sets of linear equations into matrix form (e.g. for solution via the Gauss Seidel algorithm), similar to the equationsToMatrix(eqns,vars) function in Matlab? An example from Matlab: [A, b] = equationsToMatrix([x - y == 0, x + 2*y == 3, [x, y]) A = [ 1, -1] [ 1, 2] b = 0 3 Suggestions for building blocks would be very helpful, too. 回答1: 1) This is not exactly what you are asking

Function to translate linear equations into matrix form in R?

我是研究僧i 提交于 2019-12-23 10:52:56
问题 I was wondering whether there exist any packages or other pre-built solutions for R that are capable of translating sets of linear equations into matrix form (e.g. for solution via the Gauss Seidel algorithm), similar to the equationsToMatrix(eqns,vars) function in Matlab? An example from Matlab: [A, b] = equationsToMatrix([x - y == 0, x + 2*y == 3, [x, y]) A = [ 1, -1] [ 1, 2] b = 0 3 Suggestions for building blocks would be very helpful, too. 回答1: 1) This is not exactly what you are asking

PETSc solving linear system with ksp guide

非 Y 不嫁゛ 提交于 2019-12-21 02:34:18
问题 I am starting use PETSc library to solve linear system of equations in parallel. I have installed all packages, build and run successfully the examples in petsc/src/ksp/ksp/examples/tutorials/ folder, for example ex.c But I couldn't understand how to fill matrices A,X an B by reading them for example from file. Here I provide the code within ex2.c file: /* Program usage: mpiexec -n <procs> ex2 [-help] [all PETSc options] */ static char help[] = "Solves a linear system in parallel with KSP.\n\