numpy 解一道简单数学题
2017-04-11 16:41
381 查看
题目
A group took a trip on a bus, at 3 per child and 3.20 per adult for a total of 118.40.They took the train back at 3.50 per child and 3.60 per adult for a total of 135.20.
How many children, and how many adults?
求解过程
设有x1个children,
x2个adults,线性方程组为:
\[
3x_1+3.2x_2 = 118.4
\]
\[
3.5x_1+3.6x_2 = 135.2
\]
矩阵形式表示为:
\[
\begin{bmatrix}
3 & 3.2 \\
3.5 & 3.6
\end{bmatrix}
\begin{bmatrix}
x_1 \\
x_2 \\
\end{bmatrix}
=
\begin{bmatrix}
118.4 \\
135.2
\end{bmatrix}
\]
化为:
\[
\begin{bmatrix}
x_1 \\
x_2
\end{bmatrix}
=
{
\begin{bmatrix}
3 & 3.2 \\
3.5 & 3.6
\end{bmatrix}
}^{-1}
\begin{bmatrix}
118.4 \\
135.2
\end{bmatrix}
\]
接下来就是使用numpy求解了
代码
import numpy as np a = np.matrix('3. 3.2;3.5,3.6') b = np.matrix('118.4;135.2') inverse_a = np.linalg.inv(a) print(inverse_a) result = inverse_a * b print(result)
结果
\[
inverse\_a =
\begin{bmatrix}
-9 & 8 \\
8.75 & -7.5
\end{bmatrix}
\]
\[
result =
\begin{bmatrix}
16 \\
22
\end{bmatrix}
\]
也就是说是16个children,22个adults
相关文章推荐
- 一道简单数学题
- POJ1142Smith Numbers一道简单的数学题
- 简单一道数学题 剿灭100%垃圾邮件
- 有一道十分简单的数学题,但是我就是没想出来,不得以发在首页求助
- noj一道简单的数学题
- qduoj 102 一道非常简单的数学题(构造)
- bjfu1070 一道简单的数学题
- 一道简单的算法问题--数学的魅力
- NBUT 1647 又一道简单题【数学+枚举】
- [杜教筛 反演] LOJ#6229. 这是一道简单的数学题
- 有一道十分简单的数学题,但是我就是没想出来,不得以发在首页求助
- 一道简单数学题
- 一道简单数学题!10人有11个人算错!!
- [杜教筛][莫比乌斯反演] LOJ #6229. 这是一道简单的数学题
- 偶见一道华为笔试题(简单的题更显算法啊--不可忽视的数学)
- 一道简单而又容易出错的题目
- 数学之美 系列五 -- 简单之美:布尔代数和搜索引擎的索引
- 数学之美系列五 -- 简单之美:布尔代数和搜索引擎的索引
- 呵呵,刚刚水了一道题目。简单题就要水!PKU2895,精简到70行代码!
- 一道比较简单的Google面试题