Язык программирования R/Математика: различия между версиями

Содержимое удалено Содержимое добавлено
Matrix inversion
Solving a linear equation
Строка 379:
</pre>
 
=== Решение системы линейных уравнений ===
===Solving a linear equation===
Из линейной алгебры известно, что система:
 
<math>\begin{cases}
a_{11}x_1 + a_{12}x_2 + \ldots + a_{1n}x_n = b_1 \\
a_{21}x_1 + a_{22}x_2 + \ldots + a_{2n}x_n = b_2 \\
\cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \cdots \\
a_{m1}x_1 + a_{m2}x_2 + \ldots + a_{mn}x_n = b_m
\end{cases}</math>
 
эквивалентна:
 
<math>A \cdot X = B,</math>
 
где:
 
<math>A = \begin{pmatrix}
a_{11} & a_{12} & \cdots & a_{1n} \\
a_{21} & a_{22} & \cdots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & \cdots & a_{mn}
\end{pmatrix} ;\quad
X = \begin{pmatrix}
x_{1} \\ x_{2} \\ \vdots \\ x_{n}
\end{pmatrix} ;\quad
B = \begin{pmatrix}
b_{1} \\ b_{2} \\ \vdots \\ b_{m}
\end{pmatrix}.</math>
 
Следовательно:
 
<math>X = A^{-1} \cdot B</math>
 
Этот алгоритм в коде '''R''' будет выглядеть следующим образом:
 
<pre width = 80>
> ma=matrix(nrow=2,ncol=2,c(1,-.8,1,.2))
> ma
[,1] [,2]
[1,] 1.0 1.0
[2,] -0.8 0.2
>
> lb=matrix(c(1.0+25.0/18,25.0/18.0))
> lb
[,1]
[1,] 2.388889
[2,] 1.388889
>
> kx=solve(ma,lb)
> kx
[,1]
[1,] -0.9111111
[2,] 3.3000000
>
> ma%*%kx #checking theПроверяем answerответ
[,1]
[1,] 2.388889
[2,] 1.388889
>
</pre>
 
 
 
=== Eigenvalue, eigenvector and eigenspace ===