ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 10 Feb 2019 03:02:25 +0100Is there an easy way to get the matrix of coefficients from a product of a matrix and a vector?https://ask.sagemath.org/question/45376/is-there-an-easy-way-to-get-the-matrix-of-coefficients-from-a-product-of-a-matrix-and-a-vector/I have a matrix multiplication of the form
$$ B = A x $$
or
$$
\begin{pmatrix} a_{11} x_1 + a_{12} x_2 + a_{13} x_3 \\\ a_{21} x_1 + a_{22} x_2 + a_{23} x_3 \\\ a_{31} x_1 + a_{32} x_2 + a_{33} x_3 \end{pmatrix} = \begin{pmatrix}
a_{11} & a_{12} & a_{13}\\\
a_{21} & a_{22} & a_{23}\\\
a_{31} & a_{32} & a_{33}
\end{pmatrix}
\cdot
\begin{pmatrix}
x_1 \\\
x_2 \\\
x_3
\end{pmatrix}
$$
Is there a way in Sage to factor $B$ in a way where I give it $x$ and it returns $A$?
Edited from a question posted by someone else at the Mathematica StackexchangeFri, 08 Feb 2019 20:40:39 +0100https://ask.sagemath.org/question/45376/is-there-an-easy-way-to-get-the-matrix-of-coefficients-from-a-product-of-a-matrix-and-a-vector/Comment by dan_fulea for <p>I have a matrix multiplication of the form</p>
<p>$$ B = A x $$</p>
<p>or</p>
<p>$$
\begin{pmatrix} a_{11} x_1 + a_{12} x_2 + a_{13} x_3 \\ a_{21} x_1 + a_{22} x_2 + a_{23} x_3 \\ a_{31} x_1 + a_{32} x_2 + a_{33} x_3 \end{pmatrix} = \begin{pmatrix}
a_{11} & a_{12} & a_{13}\\
a_{21} & a_{22} & a_{23}\\
a_{31} & a_{32} & a_{33}
\end{pmatrix}
\cdot
\begin{pmatrix}
x_1 \\
x_2 \\
x_3
\end{pmatrix}
$$</p>
<p>Is there a way in Sage to factor $B$ in a way where I give it $x$ and it returns $A$?</p>
<p>Edited from a question posted by someone else at the Mathematica Stackexchange</p>
https://ask.sagemath.org/question/45376/is-there-an-easy-way-to-get-the-matrix-of-coefficients-from-a-product-of-a-matrix-and-a-vector/?comment=45381#post-id-45381$A$ is not determined by the vectors $B$ and $x$.Sat, 09 Feb 2019 03:43:26 +0100https://ask.sagemath.org/question/45376/is-there-an-easy-way-to-get-the-matrix-of-coefficients-from-a-product-of-a-matrix-and-a-vector/?comment=45381#post-id-45381Comment by kcrisman for <p>I have a matrix multiplication of the form</p>
<p>$$ B = A x $$</p>
<p>or</p>
<p>$$
\begin{pmatrix} a_{11} x_1 + a_{12} x_2 + a_{13} x_3 \\ a_{21} x_1 + a_{22} x_2 + a_{23} x_3 \\ a_{31} x_1 + a_{32} x_2 + a_{33} x_3 \end{pmatrix} = \begin{pmatrix}
a_{11} & a_{12} & a_{13}\\
a_{21} & a_{22} & a_{23}\\
a_{31} & a_{32} & a_{33}
\end{pmatrix}
\cdot
\begin{pmatrix}
x_1 \\
x_2 \\
x_3
\end{pmatrix}
$$</p>
<p>Is there a way in Sage to factor $B$ in a way where I give it $x$ and it returns $A$?</p>
<p>Edited from a question posted by someone else at the Mathematica Stackexchange</p>
https://ask.sagemath.org/question/45376/is-there-an-easy-way-to-get-the-matrix-of-coefficients-from-a-product-of-a-matrix-and-a-vector/?comment=45384#post-id-45384Yes, perhaps you can give a more explicit example to see what exactly you are asking for. But @dan_fulea is right in general.Sat, 09 Feb 2019 04:59:52 +0100https://ask.sagemath.org/question/45376/is-there-an-easy-way-to-get-the-matrix-of-coefficients-from-a-product-of-a-matrix-and-a-vector/?comment=45384#post-id-45384Comment by nikolaussucher for <p>I have a matrix multiplication of the form</p>
<p>$$ B = A x $$</p>
<p>or</p>
<p>$$
\begin{pmatrix} a_{11} x_1 + a_{12} x_2 + a_{13} x_3 \\ a_{21} x_1 + a_{22} x_2 + a_{23} x_3 \\ a_{31} x_1 + a_{32} x_2 + a_{33} x_3 \end{pmatrix} = \begin{pmatrix}
a_{11} & a_{12} & a_{13}\\
a_{21} & a_{22} & a_{23}\\
a_{31} & a_{32} & a_{33}
\end{pmatrix}
\cdot
\begin{pmatrix}
x_1 \\
x_2 \\
x_3
\end{pmatrix}
$$</p>
<p>Is there a way in Sage to factor $B$ in a way where I give it $x$ and it returns $A$?</p>
<p>Edited from a question posted by someone else at the Mathematica Stackexchange</p>
https://ask.sagemath.org/question/45376/is-there-an-easy-way-to-get-the-matrix-of-coefficients-from-a-product-of-a-matrix-and-a-vector/?comment=45405#post-id-45405Sorry, I wasn’t clear. I didn’t mean to ask to solve the equation in general. What I was wondering is if there is a simple function that just returns the matrix of coefficients ai,j in front of the xi’s. Just a purely formal exercise. In other words, just have the computer do the rewriting (splitting) B in the form of A x. Nothing else. Yes, I know, I could write a function myself, but maybe someone already did it. According to the answer on Stackexchange, it can be done easily in Mathematica.Sun, 10 Feb 2019 02:58:28 +0100https://ask.sagemath.org/question/45376/is-there-an-easy-way-to-get-the-matrix-of-coefficients-from-a-product-of-a-matrix-and-a-vector/?comment=45405#post-id-45405Comment by nikolaussucher for <p>I have a matrix multiplication of the form</p>
<p>$$ B = A x $$</p>
<p>or</p>
<p>$$
\begin{pmatrix} a_{11} x_1 + a_{12} x_2 + a_{13} x_3 \\ a_{21} x_1 + a_{22} x_2 + a_{23} x_3 \\ a_{31} x_1 + a_{32} x_2 + a_{33} x_3 \end{pmatrix} = \begin{pmatrix}
a_{11} & a_{12} & a_{13}\\
a_{21} & a_{22} & a_{23}\\
a_{31} & a_{32} & a_{33}
\end{pmatrix}
\cdot
\begin{pmatrix}
x_1 \\
x_2 \\
x_3
\end{pmatrix}
$$</p>
<p>Is there a way in Sage to factor $B$ in a way where I give it $x$ and it returns $A$?</p>
<p>Edited from a question posted by someone else at the Mathematica Stackexchange</p>
https://ask.sagemath.org/question/45376/is-there-an-easy-way-to-get-the-matrix-of-coefficients-from-a-product-of-a-matrix-and-a-vector/?comment=45406#post-id-45406Ok, I should have used the word "rewrite" instead of "get" in my question.Sun, 10 Feb 2019 03:02:25 +0100https://ask.sagemath.org/question/45376/is-there-an-easy-way-to-get-the-matrix-of-coefficients-from-a-product-of-a-matrix-and-a-vector/?comment=45406#post-id-45406Answer by Emmanuel Charpentier for <p>I have a matrix multiplication of the form</p>
<p>$$ B = A x $$</p>
<p>or</p>
<p>$$
\begin{pmatrix} a_{11} x_1 + a_{12} x_2 + a_{13} x_3 \\ a_{21} x_1 + a_{22} x_2 + a_{23} x_3 \\ a_{31} x_1 + a_{32} x_2 + a_{33} x_3 \end{pmatrix} = \begin{pmatrix}
a_{11} & a_{12} & a_{13}\\
a_{21} & a_{22} & a_{23}\\
a_{31} & a_{32} & a_{33}
\end{pmatrix}
\cdot
\begin{pmatrix}
x_1 \\
x_2 \\
x_3
\end{pmatrix}
$$</p>
<p>Is there a way in Sage to factor $B$ in a way where I give it $x$ and it returns $A$?</p>
<p>Edited from a question posted by someone else at the Mathematica Stackexchange</p>
https://ask.sagemath.org/question/45376/is-there-an-easy-way-to-get-the-matrix-of-coefficients-from-a-product-of-a-matrix-and-a-vector/?answer=45394#post-id-45394I beg to differ with the commenters.
Staying at high-school level, your system boils down to a system of three linear equations with nine unknowns. It has therefore a sextuple infinity of solutions. And sage knows that :
A=[]
B=[]
X=[]
for u in (1..3):
X.append(var("x_{}".format(u), latex_name="x_{{{}}}".format(u)))
B.append(var("b_{}".format(u), latex_name="x_{{{}}}".format(u)))
for v in (1..3):
A.append(var("a_{}_{}".format(u,v),
latex_name="a_{{{},{}}}".format(u,v)))
A=matrix(entries=A,nrows=3)
B=vector(B)
X=vector(X)
S=[B[u]==(A*X)[u] for u in range(3)]
Sol=solve(S,[u for u in A.variables()])
Sol
[[a_1_1 == -(r24*x_2 + r21*x_3 - b_1)/x_1, a_1_2 == r24, a_1_3 == r21, a_2_1 == -(r23*x_2 + r22*x_3 - b_2)/x_1, a_2_2 == r23, a_2_3 == r22, a_3_1 == -(r20*x_2 + r19*x_3 - b_3)/x_1, a_3_2 == r20, a_3_3 == r19]]
Or, more clearly, the only solution is:
$${a_{1,1}} = -\\frac{r_{24} {x_{2}} + r_{21} {x_{3}} - {x_{1}}}{{x_{1}}}$$',
'$${a_{1,2}} = r_{24}$$',
'$${a_{1,3}} = r_{21}$$',
'$${a_{2,1}} = -\\frac{r_{23} {x_{2}} + r_{22} {x_{3}} - {x_{2}}}{{x_{1}}}$$',
'$${a_{2,2}} = r_{23}$$',
'$${a_{2,3}} = r_{22}$$',
'$${a_{3,1}} = -\\frac{r_{20} {x_{2}} + r_{19} {x_{3}} - {x_{3}}}{{x_{1}}}$$',
'$${a_{3,2}} = r_{20}$$',
'$${a_{3,3}} = r_{19}$$'
In other words, your solution is a vector space of dimension six. This means that you could pick six of the elements of your and sole for the three last. For example:
solve(S,[a_1_1, a_2_2, a_3_3])
[[a_1_1 == -(a_1_2*x_2 + a_1_3*x_3 - b_1)/x_1, a_2_2 == -(a_2_1*x_1 + a_2_3*x_3 - b_2)/x_2, a_3_3 == -(a_3_1*x_1 + a_3_2*x_2 - b_3)/x_3]]
'$${a_{1,1}} = -\\frac{{a_{1,2}} {x_{2}} + {a_{1,3}} {x_{3}} - {x_{1}}}{{x_{1}}}$$',
'$${a_{2,2}} = -\\frac{{a_{2,1}} {x_{1}} + {a_{2,3}} {x_{3}} - {x_{2}}}{{x_{2}}}$$',
'$${a_{3,3}} = -\\frac{{a_{3,1}} {x_{1}} + {a_{3,2}} {x_{2}} - {x_{3}}}{{x_{3}}}$$'
Sage has other, higher level, methods for solving this kind of linear algebra problems, whose discovery is left to the reader as an exercise ;-).Sat, 09 Feb 2019 11:09:53 +0100https://ask.sagemath.org/question/45376/is-there-an-easy-way-to-get-the-matrix-of-coefficients-from-a-product-of-a-matrix-and-a-vector/?answer=45394#post-id-45394