题目

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

numpy 解一道简单数学题的更多相关文章

  1. [JZOJ5773]【NOIP2008模拟】简单数学题

    Description       话说, 小X是个数学大佬,他喜欢做数学题.有一天,小X想考一考小Y.他问了小Y一道数学题.题目如下:      对于一个正整数N,存在一个正整数T(0<T&l ...

  2. JZOJ 5773. 【NOIP2008模拟】简单数学题

    5773. [NOIP2008模拟]简单数学题 (File IO): input:math.in output:math.out Time Limits: 1000 ms  Memory Limits ...

  3. 通过一道简单的例题了解Linux内核PWN

    写在前面 这篇文章目的在于简单介绍内核PWN题,揭开内核的神秘面纱.背后的知识点包含Linux驱动和内核源码,学习路线非常陡峭.也就是说,会一道Linux内核PWN需要非常多的铺垫知识,如果要学习可以 ...

  4. 又一道简单题&&Ladygod(两道思维水题)

    Ladygod Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit S ...

  5. numpy和pandas简单使用

    numpy和pandas简单使用 import numpy as np import pandas as pd 一维数据分析 numpy中使用array, pandas中使用series numpy一 ...

  6. HDU 6467 简单数学题 【递推公式 && O(1)优化乘法】(广东工业大学第十四届程序设计竞赛)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6467 简单数学题 Time Limit: 4000/2000 MS (Java/Others)    M ...

  7. HDU 6467.简单数学题-数学题 (“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛)

    简单数学题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  8. Discrete Function(简单数学题)

    Discrete Function There is a discrete function. It is specified for integer arguments from 1 to N (2 ...

  9. CSU 1785: 又一道简单题

    1785: 又一道简单题 Submit Page   Summary   Time Limit: 5 Sec     Memory Limit: 128 Mb     Submitted: 602   ...

随机推荐

  1. Travis CI实现持续部署

    安装Ruby 2.0以上版本并安装travis的命令行工具 可以看出我的已经是安装好的(Ubuntu 16.04.3 LTS 系统) ruby -v ruby --) [x86_64-linux-gn ...

  2. MySQL迁移方案(后续再补充)

    出处:黑洞中的奇点 的博客 http://www.cnblogs.com/kelvin19840813/ 您的支持是对博主最大的鼓励,感谢您的认真阅读.本文版权归作者所有,欢迎转载,但请保留该声明. ...

  3. Java实现矩阵计算器【代码】

    其实这个程序最开始是大二下学期Java的一次平时作业,当时只要求产生几个随机矩阵并对这些矩阵进行计算. 所以当时没去实现现在这么丰富而且实用的功能.不过当时倒是挺想去做的,无奈有些不知道怎么去实现. ...

  4. Exception: Unexpected End Of File(crontab)

    Exception: Unexpected End Of File [solphire@hadoop02 tools]$ crontab -l 1 * * * * source /etc/profil ...

  5. vue2.0 微信oauth认证的正确调用位置

    运行在微信端的项目,很重要的环节是oauth认证:那在vue项目中,在何时何地调用oauth认证最合适呢? 经过观察,在项目启动过程中,会执行main.js文件:所以我将认证放在main.js中操作: ...

  6. XCode8中的sizeClass设置

    xcode8出来很久了,xcode9都要出来了,项目中由于一直没遇到用到适配屏幕的情况,所以一直也就忽略了这个知识点.今天忽然想起来,就抱着试一试的态度打开了xcode,我去~就我现在了解而言,屏幕大 ...

  7. django之admin流程

    admin 类复习: class Base(object): def __init__(self,val): self.val = val def func(self): self.test() pr ...

  8. SAP成都研究院35岁以上的开发人员都去哪儿了?

    2006年成立的SAP成都研究院,位于天府软件园B区.如今,因为研究院发展的不断壮大, 已经搬迁到天府软件园E区了,因此,发生在图片building各种充满悲欢离合的故事,已经成为一部分小伙伴脑海中难 ...

  9. Repair MySQL 5.6 GTID replication by injecting empty transactions

    Since SQL_SLAVE_SKIP_COUNTER doesn’t work with GTID we need to find a way to ignore that transaction ...

  10. Android的Environment.getExternalStorageState的使用

    1.sd状态 sd状态 现象描述  /mnt/sdcard目录是否存在 canRead返回 canWrite返回 MEDIA_MOUNTED  SD卡正常挂载 true true true MEDIA ...