Skip to main content
broken link fixed
Source Link
Glorfindel
  • 22.8k
  • 13
  • 97
  • 124

The symbol / is the matrix right division operator in MATLAB, which calls the mrdivide function. From the documentation, matrix right division is related to matrix left division in the following way:

B/A = (A'\B')'

If A is a square matrix, B/A is roughly equal to B*inv(A) (although it's computed in a different, more robust way). Otherwise, x = B/A is the solution in the least squares sense to the under- or over-determined system of equations x*A = B. More detail about the algorithms used for solving the system of equations is given here. Typically packages like LAPACKLAPACK or BLASBLAS are used under the hood.

The NumPy packageNumPy package for Python contains a routine lstsqlstsq for computing the least-squares solution to a system of equations. This routine will likely give you comparable results to using the mrdivide function in MATLAB, but it is unlikely to be exact. Any differences in the underlying algorithms used by each function will likely result in answers that differ slightly from one another (i.e. one may return a value of 1.0, whereas the other may return a value of 0.999). The relative size of this error could end up being larger, depending heavily on the specific system of equations you are solving.

To use lstsq, you may have to adjust your problem slightly. It appears that you want to solve an equation of the form cB = a, where B is 25-by-18, a is 1-by-18, and c is 1-by-25. Applying a transposetranspose to both sides gives you the equation BTcT = aT, which is a more standard form (i.e. Ax = b). The arguments to lstsq should be (in this order) BT (an 18-by-25 array) and aT (an 18-element array). lstsq should return a 25-element array (cT).

Note: while NumPy doesn't make any distinction between a 1-by-N or N-by-1 array, MATLAB certainly does, and will yell at you if you don't use the proper one.

The symbol / is the matrix right division operator in MATLAB, which calls the mrdivide function. From the documentation, matrix right division is related to matrix left division in the following way:

B/A = (A'\B')'

If A is a square matrix, B/A is roughly equal to B*inv(A) (although it's computed in a different, more robust way). Otherwise, x = B/A is the solution in the least squares sense to the under- or over-determined system of equations x*A = B. More detail about the algorithms used for solving the system of equations is given here. Typically packages like LAPACK or BLAS are used under the hood.

The NumPy package for Python contains a routine lstsq for computing the least-squares solution to a system of equations. This routine will likely give you comparable results to using the mrdivide function in MATLAB, but it is unlikely to be exact. Any differences in the underlying algorithms used by each function will likely result in answers that differ slightly from one another (i.e. one may return a value of 1.0, whereas the other may return a value of 0.999). The relative size of this error could end up being larger, depending heavily on the specific system of equations you are solving.

To use lstsq, you may have to adjust your problem slightly. It appears that you want to solve an equation of the form cB = a, where B is 25-by-18, a is 1-by-18, and c is 1-by-25. Applying a transpose to both sides gives you the equation BTcT = aT, which is a more standard form (i.e. Ax = b). The arguments to lstsq should be (in this order) BT (an 18-by-25 array) and aT (an 18-element array). lstsq should return a 25-element array (cT).

Note: while NumPy doesn't make any distinction between a 1-by-N or N-by-1 array, MATLAB certainly does, and will yell at you if you don't use the proper one.

The symbol / is the matrix right division operator in MATLAB, which calls the mrdivide function. From the documentation, matrix right division is related to matrix left division in the following way:

B/A = (A'\B')'

If A is a square matrix, B/A is roughly equal to B*inv(A) (although it's computed in a different, more robust way). Otherwise, x = B/A is the solution in the least squares sense to the under- or over-determined system of equations x*A = B. More detail about the algorithms used for solving the system of equations is given here. Typically packages like LAPACK or BLAS are used under the hood.

The NumPy package for Python contains a routine lstsq for computing the least-squares solution to a system of equations. This routine will likely give you comparable results to using the mrdivide function in MATLAB, but it is unlikely to be exact. Any differences in the underlying algorithms used by each function will likely result in answers that differ slightly from one another (i.e. one may return a value of 1.0, whereas the other may return a value of 0.999). The relative size of this error could end up being larger, depending heavily on the specific system of equations you are solving.

To use lstsq, you may have to adjust your problem slightly. It appears that you want to solve an equation of the form cB = a, where B is 25-by-18, a is 1-by-18, and c is 1-by-25. Applying a transpose to both sides gives you the equation BTcT = aT, which is a more standard form (i.e. Ax = b). The arguments to lstsq should be (in this order) BT (an 18-by-25 array) and aT (an 18-element array). lstsq should return a 25-element array (cT).

Note: while NumPy doesn't make any distinction between a 1-by-N or N-by-1 array, MATLAB certainly does, and will yell at you if you don't use the proper one.

deleted 148 characters in body
Source Link
gnovice
  • 126k
  • 16
  • 259
  • 364

The symbol "/"/ is the matrix right division operator in MATLAB, which calls the MRDIVIDEmrdivide function. From the documentation, matrix right division is related to matrix left divisionmatrix left division in the following way:

B/A = (A'\B')'

If AA is a square matrix, B/AB/A is roughly the same asequal to B*inv(A)B*inv(A) (although it's computed in a different, more robust way). Otherwise, X = B/Ax = B/A is the solution in the least squares sense to the under- or overdeterminedover-determined system of equations XA = Bx*A = B.

  More detail about the algorithms used for solving the system of equations is given in the link to the MRDIVIDE documentation abovehere. Most useTypically packages like LAPACK or BLAS. It's all rather complicated, and you should check to see if Python already has an MRDIVIDE-like function before you try to do it yourself are used under the hood.

EDIT:

The NumPy package for Python contains a routine lstsqlstsq for computing the least-squares solution to a system of equations, as mentioned in a comment by David Cournapeau. This routine will likely give you comparable results to using the MRDIVIDEmrdivide function in MATLAB, but it is unlikely to be exact. Any differences in the underlying algorithms used by each function will likely result in answers that differ slightly from one another (i.e. one may return a value of 1.0, whereas the other may return a value of 0.999). The relative size of this error could end up being larger, depending heavily on the specific system of equations you are solving.

To use lstsqlstsq, you may have to adjust your problem slightly. It appears that you want to solve an equation of the form cB = a, where B is 25-by-18, a is 1-by-18, and c is 1-by-25. Applying a transpose to both sides gives you the equation BTcT = aT, which is a more standard form (i.e. Ax = b). The arguments to lstsqlstsq should be (in this order) BT (an 18-by-25 array) and aT (an 18-element array). lstsqlstsq should return a 25-element array (cT).

DisclaimerNote: I don't know if Python makeswhile NumPy doesn't make any distinction between a 1-by-N or N-by-1 array, so transposes may not be necessary for 1-dimensional arrays. MATLAB certainly considers them as differentdoes, and will yell at you for itif you don't use the proper one. =)

The symbol "/" is the matrix right division operator in MATLAB, which calls the MRDIVIDE function. From the documentation, matrix right division is related to matrix left division in the following way:

B/A = (A'\B')'

If A is a square matrix, B/A is roughly the same as B*inv(A) (although it's computed in a different way). Otherwise, X = B/A is the solution in the least squares sense to the under- or overdetermined system of equations XA = B.

  More detail about the algorithms used for solving the system of equations is given in the link to the MRDIVIDE documentation above. Most use LAPACK or BLAS. It's all rather complicated, and you should check to see if Python already has an MRDIVIDE-like function before you try to do it yourself.

EDIT:

The NumPy package for Python contains a routine lstsq for computing the least-squares solution to a system of equations, as mentioned in a comment by David Cournapeau. This routine will likely give you comparable results to using the MRDIVIDE function in MATLAB, but it is unlikely to be exact. Any differences in the underlying algorithms used by each function will likely result in answers that differ slightly from one another (i.e. one may return a value of 1.0, whereas the other may return a value of 0.999). The relative size of this error could end up being larger, depending heavily on the specific system of equations you are solving.

To use lstsq, you may have to adjust your problem slightly. It appears that you want to solve an equation of the form cB = a, where B is 25-by-18, a is 1-by-18, and c is 1-by-25. Applying a transpose to both sides gives you the equation BTcT = aT, which is a more standard form (i.e. Ax = b). The arguments to lstsq should be (in this order) BT (an 18-by-25 array) and aT (an 18-element array). lstsq should return a 25-element array (cT).

Disclaimer: I don't know if Python makes any distinction between a 1-by-N or N-by-1 array, so transposes may not be necessary for 1-dimensional arrays. MATLAB certainly considers them as different, and will yell at you for it. =)

The symbol / is the matrix right division operator in MATLAB, which calls the mrdivide function. From the documentation, matrix right division is related to matrix left division in the following way:

B/A = (A'\B')'

If A is a square matrix, B/A is roughly equal to B*inv(A) (although it's computed in a different, more robust way). Otherwise, x = B/A is the solution in the least squares sense to the under- or over-determined system of equations x*A = B. More detail about the algorithms used for solving the system of equations is given here. Typically packages like LAPACK or BLAS are used under the hood.

The NumPy package for Python contains a routine lstsq for computing the least-squares solution to a system of equations. This routine will likely give you comparable results to using the mrdivide function in MATLAB, but it is unlikely to be exact. Any differences in the underlying algorithms used by each function will likely result in answers that differ slightly from one another (i.e. one may return a value of 1.0, whereas the other may return a value of 0.999). The relative size of this error could end up being larger, depending heavily on the specific system of equations you are solving.

To use lstsq, you may have to adjust your problem slightly. It appears that you want to solve an equation of the form cB = a, where B is 25-by-18, a is 1-by-18, and c is 1-by-25. Applying a transpose to both sides gives you the equation BTcT = aT, which is a more standard form (i.e. Ax = b). The arguments to lstsq should be (in this order) BT (an 18-by-25 array) and aT (an 18-element array). lstsq should return a 25-element array (cT).

Note: while NumPy doesn't make any distinction between a 1-by-N or N-by-1 array, MATLAB certainly does, and will yell at you if you don't use the proper one.

added a numpy alternative
Source Link
gnovice
  • 126k
  • 16
  • 259
  • 364

The symbol "/" is the matrix right division operator in MATLAB, which calls the MRDIVIDE function. From the documentation, matrix right division is related to matrix left division in the following way:

B/A = (A'\B')'

If A is a square matrix, B/A is roughly the same as B*inv(A) (although it's computed in a different way). Otherwise, X = B/A is the solution in the least squares sense to the under- or overdetermined system of equations XA = B.

More detail about the algorithms used for solving the system of equations is given in the link to the MRDIVIDE documentation above. Most use LAPACK or BLAS. It's all rather complicated, and you should check to see if Python already has an MRDIVIDE-like function before you try to do it yourself.

EDIT:

The NumPy package for Python contains a routine lstsq for computing the least-squares solution to a system of equations, as mentioned in a comment by David Cournapeau. This routine will likely give you comparable results to using the MRDIVIDE function in MATLAB, but it is unlikely to be exact. Any differences in the underlying algorithms used by each function will likely result in answers that differ slightly from one another (i.e. one may return a value of 1.0, whereas the other may return a value of 0.999). The relative size of this error could end up being larger, depending heavily on the specific system of equations you are solving.

To use lstsq, you may have to adjust your problem slightly. It appears that you want to solve an equation of the form cB = a, where B is 25-by-18, a is 1-by-18, and c is 1-by-25. Applying a transpose to both sides gives you the equation BTcT = aT, which is a more standard form (i.e. Ax = b). The arguments to lstsq should be (in this order) BT (an 18-by-25 array) and aT (an 18-element array). lstsq should return a 25-element array (cT).

Disclaimer: I don't know if Python makes any distinction between a 1-by-N or N-by-1 array, so transposes may not be necessary for 1-dimensional arrays. MATLAB certainly considers them as different, and will yell at you for it. =)

The symbol "/" is the matrix right division operator in MATLAB, which calls the MRDIVIDE function. From the documentation, matrix right division is related to matrix left division in the following way:

B/A = (A'\B')'

If A is a square matrix, B/A is roughly the same as B*inv(A) (although it's computed in a different way). Otherwise, X = B/A is the solution in the least squares sense to the under- or overdetermined system of equations XA = B.

More detail about the algorithms used for solving the system of equations is given in the link to the MRDIVIDE documentation above. Most use LAPACK or BLAS. It's all rather complicated, and you should check to see if Python already has an MRDIVIDE-like function before you try to do it yourself.

The symbol "/" is the matrix right division operator in MATLAB, which calls the MRDIVIDE function. From the documentation, matrix right division is related to matrix left division in the following way:

B/A = (A'\B')'

If A is a square matrix, B/A is roughly the same as B*inv(A) (although it's computed in a different way). Otherwise, X = B/A is the solution in the least squares sense to the under- or overdetermined system of equations XA = B.

More detail about the algorithms used for solving the system of equations is given in the link to the MRDIVIDE documentation above. Most use LAPACK or BLAS. It's all rather complicated, and you should check to see if Python already has an MRDIVIDE-like function before you try to do it yourself.

EDIT:

The NumPy package for Python contains a routine lstsq for computing the least-squares solution to a system of equations, as mentioned in a comment by David Cournapeau. This routine will likely give you comparable results to using the MRDIVIDE function in MATLAB, but it is unlikely to be exact. Any differences in the underlying algorithms used by each function will likely result in answers that differ slightly from one another (i.e. one may return a value of 1.0, whereas the other may return a value of 0.999). The relative size of this error could end up being larger, depending heavily on the specific system of equations you are solving.

To use lstsq, you may have to adjust your problem slightly. It appears that you want to solve an equation of the form cB = a, where B is 25-by-18, a is 1-by-18, and c is 1-by-25. Applying a transpose to both sides gives you the equation BTcT = aT, which is a more standard form (i.e. Ax = b). The arguments to lstsq should be (in this order) BT (an 18-by-25 array) and aT (an 18-element array). lstsq should return a 25-element array (cT).

Disclaimer: I don't know if Python makes any distinction between a 1-by-N or N-by-1 array, so transposes may not be necessary for 1-dimensional arrays. MATLAB certainly considers them as different, and will yell at you for it. =)

added links
Source Link
gnovice
  • 126k
  • 16
  • 259
  • 364
Loading
Source Link
gnovice
  • 126k
  • 16
  • 259
  • 364
Loading