没有合适的资源?快使用搜索试试~ 我知道了~
首页Python编程入门:计算与问题解决指南
Python编程入门:计算与问题解决指南
需积分: 9 4 下载量 34 浏览量
更新于2024-07-20
收藏 13.04MB PDF 举报
"《使用Python进行计算与编程入门》是一本面向没有编程经验的学生,介绍如何通过Python和相关库如PyLab进行计算机问题求解的教材。它基于麻省理工学院的一门课程,该课程在MIT的开放式在线课程平台edX上非常受欢迎。本书不仅适合传统课堂教学,也适用于大规模开放在线课程的学习者。 内容覆盖广泛,从基础的Python语言学习和编程概念出发,包括穷举搜索、二分查找等计算方法。书中强调严谨思维,对高中代数水平以上的数学知识有一定的要求,但并不排斥读者对数学概念的理解。除了传统的计算复杂性分析和简单算法,本书还深入探讨了数据可视化、模拟随机性、数据分析技术、统计方法,以及可能误导的统计技巧等内容。 特别值得一提的是,书中还包括了两个进阶主题:优化问题和动态规划。这使得本书成为进一步学习计算机科学课程的桥梁,或者对于其他学科学生来说,提供了扎实的计算问题解决基础。此外,书中的版权信息表明,未经许可,任何形式的电子或机械复制都必须得到出版社的书面许可,且强调了批量购买的商业折扣信息以及印刷和装订信息,表明了其专业性和规范性。 《使用Python进行计算与编程入门》是一本既实用又理论结合实际的教材,旨在帮助读者掌握利用Python进行计算和解决问题的技能,并引导他们进入更高级的计算机科学领域。"
资源详情
资源推荐
ACKNOWLEDGMENTS
This book grew out of a set of lecture notes that I prepared while teaching an
undergraduate course at MIT. The course, and therefore this book, benefited
from suggestions from faculty colleagues (especially Eric Grimson, Srinivas
Devadas, and Fredo Durand), teaching assistants, and the students who took
the course.
The process of transforming my lecture notes into a book proved far more
onerous than I had expected. Fortunately, this misguided optimism lasted long
enough to keep me from giving up. The encouragement of colleagues and family
also helped keep me going.
Eric Grimson, Chris Terman, and David Guttag provided vital help. Eric, who is
MIT’s Chancellor, managed to find the time to read almost the entire book with
great care. He found numerous errors (including an embarrassing, to me,
number of technical errors) and pointed out places where necessary
explanations were missing. Chris also read parts of the manuscript and
discovered errors. He also helped me battle Microsoft Word, which we
eventually persuaded to do most of what we wanted. David overcame his
aversion to computer science, and proofread multiple chapters.
Preliminary versions of this book were used in the MIT course 6.00 and the MITx
course 6.00x. A number of students in these courses pointed out errors. One
6.00x student, J.C. Cabrejas, was particularly helpful. He found a large number
of typos, and more than a few technical errors.
Like all successful professors, I owe a great deal to my graduate students. The
photo on the back cover of this book depicts me supporting some of my current
students. In the lab, however, it is they who support me. In addition to doing
great research (and letting me take some of the credit for it), Guha
Balakrishnan, Joel Brooks, Ganeshapillai Gartheeban, Jen Gong, Yun Liu,
Anima Singh, Jenna Wiens, and Amy Zhao all provided useful comments on this
manuscript.
I owe a special debt of gratitude to Julie Sussman, P.P.A. Until I started working
with Julie, I had no idea how much difference an editor could make. I had
worked with capable copy editors on previous books, and thought that was what
I needed for this book. I was wrong. I needed a collaborator who could read the
book with the eyes of a student, and tell me what needed to be done, what
should be done, and what could be done if I had the time and energy to do it.
Julie buried me in “suggestions” that were too good to ignore. Her combined
command of both the English language and programming is quite remarkable.
Finally, thanks to my wife, Olga, for pushing me to finish and for pitching in at
critical times.
1 GETTING STARTED
A computer does two things, and two things only: it performs calculations and it
remembers the results of those calculations. But it does those two things
extremely well. The typical computer that sits on a desk or in a briefcase
performs a billion or so calculations a second. It’s hard to image how truly fast
that is. Think about holding a ball a meter above the floor, and letting it go. By
the time it reaches the floor, your computer could have executed over a billion
instructions. As for memory, a typical computer might have hundreds of
gigabytes of storage. How big is that? If a byte (the number of bits, typically
eight, required to represent one character) weighed one ounce (which it doesn’t),
100 gigabytes would weigh more than 3,000,000 tons. For comparison, that’s
roughly the weight of all the coal produced in a year in the U.S.
For most of human history, computation was limited by the speed of calculation
of the human brain and the ability to record computational results with the
human hand. This meant that only the smallest problems could be attacked
computationally. Even with the speed of modern computers, there are still
problems that are beyond modern computational models (e.g., understanding
climate change), but more and more problems are proving amenable to
computational solution. It is our hope that by the time you finish this book, you
will feel comfortable bringing computational thinking to bear on solving many of
the problems you encounter during your studies, work, and even everyday life.
What do we mean by computational thinking?
All knowledge can be thought of as either declarative or imperative. Declarative
knowledge is composed of statements of fact. For example, “the square root of x
is a number y such that y
*
y = x.” This is a statement of fact. Unfortunately it
doesn’t tell us how to find a square root.
Imperative knowledge is “how to” knowledge, or recipes for deducing
information. Heron of Alexandria was the first to document a way to compute
the square root of a number.
2
His method can be summarized as:
• Start with a guess, g.
• If g
*
g is close enough to x, stop and say that g is the answer.
• Otherwise create a new guess by averaging g and x/g, i.e., (g + x/g)/2.
• Using this new guess, which we again call g, repeat the process until g
*
g
is close enough to x.
2
Many believe that Heron was not the inventor of this method, and indeed there is some
evidence that it was well known to the ancient Babylonians.
2 Chapter 1. Getting Started
Consider, for example, finding the square root of 25.
1. Set g to some arbitrary value, e.g., 3.
2. We decide that 3
*
3 = 9 is not close enough to 25.
3. Set g to (3 + 25/3)/2 = 5.67.
3
4. We decide that 5.67
*
5.67 = 32.15 is still not close enough to 25.
5. Set g to (5.67 + 25/5.67)/2 = 5.04
6. We decide that 5.04
*
5.04 = 25.4 is close enough, so we stop and declare 5.04
to be an adequate approximation to the square root of 25.
Note that the description of the method is a sequence of simple steps, together
with a flow of control that specifies when each step is to be executed. Such a
description is called an algorithm.
4
This algorithm is an example of a guess-
and-check algorithm. It is based on the fact that it is easy to check whether or
not a guess is a good one.
A bit more formally, an algorithm is a finite list of instructions that describe a
computation that when executed on a provided set of inputs will proceed
through a set of well-defined states and eventually produce an output.
An algorithm is a bit like a recipe from a cookbook:
1. Put custard mixture over heat.
2. Stir.
3. Dip spoon in custard.
4. Remove spoon and run finger across back of spoon.
5. If clear path is left, remove custard from heat and let cool.
6. Otherwise repeat.
It includes some tests for deciding when the process is complete, as well as
instructions about the order in which to execute instructions, sometimes
jumping to some instruction based on a test.
So how does one capture this idea of a recipe in a mechanical process? One way
would be to design a machine specifically intended to compute square roots.
Odd as this may sound, the earliest computing machines were, in fact, fixed-
program computers, meaning they were designed to do very specific things, and
were mostly tools to solve a specific mathematical problem, e.g., to compute the
trajectory of an artillery shell. One of the first computers (built in 1941 by
Atanasoff and Berry) solved systems of linear equations, but could do nothing
else. Alan Turing’s bombe machine, developed during World War II, was
designed strictly for the purpose of breaking German Enigma codes. Some very
simple computers still use this approach. For example, a four-function
calculator is a fixed-program computer. It can do basic arithmetic, but it cannot
3
For simplicity, we are rounding results.
4
The word “algorithm” is derived from the name of the Persian mathematician
Muhammad ibn Musa al-Khwarizmi.
Chapter 1. Getting Started 3
be used as a word processor or to run video games. To change the program of
such a machine, one has to replace the circuitry.
The first truly modern computer was the Manchester Mark 1.
5
It was
distinguished from its predecessors by the fact that it was a stored-program
computer. Such a computer stores (and manipulates) a sequence of
instructions, and has a set of elements that will execute any instruction in that
sequence. By creating an instruction-set architecture and detailing the
computation as a sequence of instructions (i.e., a program), we make a highly
flexible machine. By treating those instructions in the same way as data, a
stored-program machine can easily change the program, and can do so under
program control. Indeed, the heart of the computer then becomes a program
(called an interpreter) that can execute any legal set of instructions, and thus
can be used to compute anything that one can describe using some basic set of
instructions.
Both the program and the data it manipulates reside in memory. Typically there
is a program counter that points to a particular location in memory, and
computation starts by executing the instruction at that point. Most often, the
interpreter simply goes to the next instruction in the sequence, but not always.
In some cases, it performs a test, and on the basis of that test, execution may
jump to some other point in the sequence of instructions. This is called flow of
control, and is essential to allowing us to write programs that perform complex
tasks.
Returning to the recipe metaphor, given a fixed set of ingredients a good chef
can make an unbounded number of tasty dishes by combining them in different
ways. Similarly, given a small fixed set of primitive elements a good programmer
can produce an unbounded number of useful programs. This is what makes
programming such an amazing endeavor.
To create recipes, or sequences of instructions, we need a programming
language in which to describe these things, a way to give the computer its
marching orders.
In 1936, the British mathematician Alan Turing described a hypothetical
computing device that has come to be called a Universal Turing Machine. The
machine had an unbounded memory in the form of tape on which one could
write zeros and ones, and some very simple primitive instructions for moving,
reading, and writing to the tape. The Church-Turing thesis states that if a
function is computable, a Turing Machine can be programmed to compute it.
The “if” in the Church-Turing thesis is important. Not all problems have
computational solutions. For example, Turing showed that it is impossible to
write a program that given an arbitrary program, call it P, prints true if and only
if P will run forever. This is known as the halting problem.
5
This computer was built at the University of Manchester, and ran its first program in
1949. It implemented ideas previously described by John von Neumann and was
anticipated by the theoretical concept of the Universal Turing Machine described by Alan
Turing in 1936.
剩余314页未读,继续阅读
厄厄尔2
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- AirKiss技术详解:无线传递信息与智能家居连接
- Hibernate主键生成策略详解
- 操作系统实验:位示图法管理磁盘空闲空间
- JSON详解:数据交换的主流格式
- Win7安装Ubuntu双系统详细指南
- FPGA内部结构与工作原理探索
- 信用评分模型解析:WOE、IV与ROC
- 使用LVS+Keepalived构建高可用负载均衡集群
- 微信小程序驱动餐饮与服装业创新转型:便捷管理与低成本优势
- 机器学习入门指南:从基础到进阶
- 解决Win7 IIS配置错误500.22与0x80070032
- SQL-DFS:优化HDFS小文件存储的解决方案
- Hadoop、Hbase、Spark环境部署与主机配置详解
- Kisso:加密会话Cookie实现的单点登录SSO
- OpenCV读取与拼接多幅图像教程
- QT实战:轻松生成与解析JSON数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功