给定九个数字,a, b, c, d, e, f, g, h, i,作为与方阵对应的输入:
$$\mathbf{M} =\begin{p矩阵}a& b& c& d& e& f\ g& h& i\\end{p矩阵}$$
找到矩阵的逆,\\mathbf{M}^{-1}\\$并输出其组成。
矩阵3乘3的逆服从下列方程:
{MM}^{-1}= \mathbf{M}^{-1}\mathbf{M} = \mathbf{I} = \begin{pmatrix}1&0&0\0&1&0\0&0&1\end{pmatrix}$$
并可计算为:
$$\mathbf{M}^{-1} =\frac{1}{\det(\mathbf{M})}\mathbf{C}^T$
其中\\mathbf{C}是辅助因子的矩阵:
$$\mathbf{C}=\begin{pmatrix}ei-fh&fg-di&dh-eg\ch-bi&ai-cg&bg-ah\bf-ce&cd-af&ae-bd\end{pmatrix}$$
而\mathbf{C}^T是\\mathbf{C}的转置:
\begin{pmatrix}ei-fh&ch-bi&bf-ce\fg-di&ai-cg&cd-af\dh-eg&bg-ah&ae-bd\end{pmatrix}$$ {C}^T=$$\mathbf
并且\\det(\mathbf{M})\\$是\\mathbf{M}\\$\\mathbf\\$\\的行列式:
$$\det(\mathbf{M}) =a(ei-fh)-b(di-fg)+c(dh-例如)$$
例如,假设输入是0, -3, -2, 1, -4, -2, -3, 4, 1。这与矩阵对应:
\begin{pmatrix}0&-3&-2\1&-4&-2\-3&4&1\end{pmatrix}$$ $$\mathbf{M} =
首先,让我们使用上面的公式来计算所谓的行列式:
$$\det(\mathbf{M}) =0(-4\ties1-(-2)\times 4)-(-3)(1\times1-(-2)\mes-3)+(-2)(1\times4-(-4)\mes-3)=$1$
接下来,让我们计算辅助因子的矩阵:
-(1\times1-(-2)\times-3)&1\times4-(-4)\times-3\-(-3\times1-(-2)\times4)&0\times1-(-2)\times-3&-(0\times4-(-3)\times-3)\-3\times-2-(-2)\times-4&-(0\times- {C}=\begin{p矩阵}-4\\ties1-(-2)\times4 4&$$\mathbf2-(-2)\times1)&0\times-4-(-3)\times1\end{pmatrix}$$
$$= \begin{pmatrix}4&5&-8\-5&-6&9\-2&-2&3\end{pmatrix}$$
然后,我们需要转置\\mathbf{C}(翻转行和列)以获得\$mathbf{C}^T\$:
\begin{pmatrix}4&-5&2\5&-6&-2\-8&9&3\end{pmatrix}$$ {C}^T=$$\mathbf
最后,我们可以找到如下逆:
{M}^{-1}=\ \frac{1}{1}\begin{pmatrix}4&-5&2\5&-6&-2\-8&9&3\end{pmatrix}=\begin{pmatrix}4&-5&2\5&-6&-2\-8&9&3\end{pmatrix}$$ {1}{$$\mathbf(mathbf{M})}\mathbf{C}^T=$$\mathbf
所以输出将是4, -5, -2, 5, -6, -2, -8, 9, 3。
Input > Output
1, 0, 0, 0, 1, 0, 0, 0, 1 > 1, 0, 0, 0, 1, 0, 0, 0, 1
0, -3, -2, 1, -4, -2, -3, 4, 1 > 4, -5, -2, 5, -6, -2, -8, 9, 3
1, 2, 3, 3, 1, 2, 2, 1, 3 > -1/6, 1/2, -1/6, 5/6, 1/2, -7/6, -1/6, -1/2, 5/6
7, 9, 4, 2, 7, 9, 3, 4, 5 > -1/94, -29/94, 53/94, 17/94, 23/94, -55/94, -13/94, -1/94, 31/94以字节为单位的最短代码获胜。
发布于 2018-07-18 16:21:04
发布于 2018-07-18 17:12:59
由于@Mr.Xcoder保存了2个字节,因为@ETHproductions保存了1个字节
将输入作为9个不同的值。
(a,b,c,d,e,f,g,h,i)=>[x=e*i-h*f,c*h-b*i,b*f-c*e,y=f*g-d*i,a*i-c*g,d*c-a*f,z=d*h-g*e,g*b-a*h,a*e-d*b].map(v=>v/=a*x+b*y+c*z)https://codegolf.stackexchange.com/questions/168828
复制相似问题