R语言,循环,控制结构 From: http://www.r-bloggers.com/control-structures-loops-in-r/?utm_source=tuicoolutm_medium=referral As part of Data Science tutorial Series in my previous post I posted on basic data types in R . I have kept the tutorial very simple so that beginners of R programming may takeoff immediately. Please find the online R editor at the end of the post so that you can execute the code on the page itself. In this section we learn about control structures loops used in R. Control strcutures in R contains conditionals, loop statements like any other programming languages. Loops are very important and forms backbone to any programming languages.Before we get into the control structures in R, just type as below in Rstudio : ?control If else statement: #See the code syntax below for if else statement if(x1){ print(x is greater than 1) }else{ print(x is less than 1) } #See the code below for nested if else statement x=10 x=10 if(x1 x7){ print(x is between 1 and 7)}else if(x8 x 15){ print(x is between 8 and 15) } x is between 8 and 15 For loops: As we know for loops are used for iterating items #Below code shows for loop implementation x = c(1,2,3,4,5) for(i in 1:5){ print(x ) } 1 2 3 4 5 While loop : #Below code shows while loop in R x = 2.987 while(x = 4.987) { x = x + 0.987 print(c(x,x-2,x-1)) } 3.974 1.974 2.974 4.961 2.961 3.961 5.948 3.948 4.948 Repeat Loop: The repeat loop is an infinite loop and used in association with a break statement. #Below code shows repeat loop: a = 1 repeat { print(a) a = a+1 if(a 4) break } 1 2 3 4 Break statement: A break statement is used in a loop to stop the iterations and flow the control outside of the loop. #Below code shows break statement: x = 1:10 for (i in x){ if (i == 2){ break } print(i) } 1 Next statement: Next statement enables to skip the current iteration of a loop without terminating it. #Below code shows next statement x = 1: 4 for (i in x) { if (i == 2){ next} print(i) } 1 3 4 Creating a function in R: function() is a built-in R function whose job is to create functions. In the below example function() takes one parameter x, executes a for loop logic. The function object thus created using function() is assigned to a variable (‘words.names’). Now this created function will be called using the variable ‘word.names’ #Below code shows us, how a function is created in R: Syntax: function_name = function(parameters,..){ code} words = c(R, datascience, machinelearning,algorithms,AI) words.names = function(x) { for(name in x){ print(name) } } #Calling the function words.names(words) R datascience machinelearning algorithms AI Hands on exercise of what we have learnt so far We create a data frame DF, run for loop, ifelse in a function and call the function #create 3 vectors name,age,salary name = c(David,John,Mathew) age = c(30,40,50) salary = c(30000,120000,55000) #create a data frame DF by combining the 3 vectors using cbind() function DF = data.frame(cbind(name,Age,salary)) #display DF DF name Age salary 1 David 30 30000 2 John 40 120000 3 Mathew 50 55000 #dimensions of DF dim(DF) 3 3 #write a function which displays the salaried person name findHighSalary = function(df){ Maxsal = 0 empname = for(i in 1:nrow(DF)){ tmpsal = as.numeric(DF ) if(tmpsal Maxsal){ Maxsal = tmpsal empname = DF } } return(as.character(empname)) } #calling the function findHighSalary(DF) Mathew R语言,控制结构,循环
众所周知Matlab的强大运算能力让各种工程软件望而却步,而VC程序的友好界面又让人爱不释手,如果能够让两者的优势结合起来的话,势必能让程序员欢欣鼓舞。还好MathWorks已经为我们想到了,基本上现在市面上主流的Matlab版本都可以支持VC和Matlab的混合编程。但是目前网上资料基本上都是基于Matlab 6.0和VC 6.0的,和新版本的实现方法有所不同,因此笔者通过不断的尝试和研究,终于调试通了基于VS2008和Matlab R2010b的混合编程。 为了更加直观的说明如何实现混合编程,笔者写了一个简单的程序作为测试。先在Matlab里面写一个M文件,代码如下: function b = MyFunc(a) b = a.*a; 将M文件保存为MyFunc.m,保存在F:/test文件夹中。然后在Matlab主窗口中将当前文件夹改为F:/test: cd F:/test; 为了能够让VC调用Matlab程序,我们可以采用将Matlab程序包装成动态链接文件DLL的形式,然后让VC调用动态链接文件,因此在Matlab中,我们需要设置一下Matlab的编译库,在Matlab主窗口中键入如下代码: mbuild –setup 然后出现 Please choose your compiler for building standalone MATLAB applications: Would you like mbuild to locate installed compilers /n? 键入y后回车,出现 Select a compiler: Lcc-win32 C 2.4.1 in D:\PROGRA~1\MATLAB\R2010b\sys\lcc Microsoft Visual C++ 2008 SP1 in D:\Program Files\Microsoft Visual Studio 9.0 None Compiler: 由于我们是需要用VC来调用Matlab函数,因此我们选择2,回车,出现 Please verify your choices: Compiler: Microsoft Visual C++ 2008 SP1 Location: D:\Program Files\Microsoft Visual Studio 9.0 Are these correct /n? 确定,键入y后回车,出现 **************************************************************************** Warning: Applications/components generated using Microsoft Visual Studio 2008 require that the Microsoft Visual Studio 2008 run-time libraries be available on the computer used for deployment. To redistribute your applications/components, be sure that the deployment machine has these run-time libraries. **************************************************************************** Trying to update options file: C:\Users\张智宇\AppData\Roaming\MathWorks\MATLAB\R2010b\compopts.bat From template:D:\PROGRA~1\MATLAB\R2010b\bin\win32\mbuildopts\msvc90compp.bat Done . . . 如果出现以上说明,则证明Matlab编译器设置成功了。接下来是生成M文件的DLL文件。 在Matlab主窗口中键入如下代码 mmc –W cpplib:MyDLL –T link:lib MyFunc.m –C 其中cpplib:后面的是需要生成文件的文件名,是自己取的,link:lib后面的MyFunc.m是转换为DLL的M文件的文件名。-W/-T/-C是参数,具体含义可以通过mcc –help命令查看,注意参数的大小写。 Matlab编译后会在Test文件夹下生成9个文件,分别是: mccEcxludedFiles.log MyDLL.cpp MyDLL.ctf MyDLL.dll MyDLL.exp MyDLL.exports MyDLL.h MyDLL.lib readme.txt 其中MyDLL.dll,MyDLL.lib,MyDLL.ctf,MyDLL.h是我们需要的文件,至此,Matlab方面就已经设置妥当了。 打开VC2008,新建一个工程,然后将上述四个文件复制到工程目录下。选择“工具-选项-项目和解决方案-VC++目录”,在“显示以下内容目录”里选择“包含文件”将“D:\Program Files\MATLAB\R2010b\extern\include”添加进去,然后选择“库文件”将“D:\Program Files\MATLAB\R2010b\extern\lib\win32\microsoft”添加进去,其中D:\Program Files是Matlab的安装目录,可根据实际情况进行修改。 然后选择“项目-属性-配置属性-链接器-输入”,在右边“附加依赖项”一栏填入“myDLL.lib mclmcrrt.lib”,其中MyDLL.lib就是刚刚用Matlab生成的lib文件。 在编写代码时首先得包含头文件“MyDLL.h”,然后开始编写需要的代码,我为了说明问题编写了一个测试代码如下所示: { MyDLLInitialize();//初始化DLL动态连接文件 double _x = {1,2,3,4,5};//输入数组 double _y ;//输出数组 mxArray* x = mxCreateDoubleMatrix(1, 5, mxREAL);//创建1*5矩阵 memcpy(mxGetPr(x), (void*)_x, sizeof(_x));//拷贝输入数据 mxArray *input = {x};//将矩阵x的指针作为输入参数传递进去 mxArray *output ;//定义输出参数指针 mlxMyFunc(1,output,1,input);//调用m函数 mxArray *y;//定义输出结果指针 y = output ;//将输出参数传递给输出结果 memcpy(_y, mxGetPr(y), sizeof(_y));//拷贝输出数据 MyDLLTerminate();//结束DLL库 //显示数组中的数据 CString str; str.Format("%f %f %f %f %f",_y ,_y ,_y ,_y ,_y ); MessageBox(str); } 其中MyDLLInitialize(),mlxMyFunc(),MyDLLTerminate()等函数可以在MyDLL.h中找到函数原型,mlxMyFunc函数原型为: mlxMyFunc(int nlhs, mxArray *plhs ) nlhs代表输出参数个数,plhs 中存放的是输入参数的指针。上例中由于输入输出参数只有一个,因此在plhs 中存放的就是M文件中b的指针,prhs 中存放的就是M文件中a的指针。 编译运行之后就可以在弹出的消息框中得到所要的结果。将项目文件夹下生成的可执行文件复制出来,将MyDLL.dll文件、MyDLL.ctf文件和.exe文件放在同一目录下便可脱离VC++独立运行。如果需要在其他未装Matlab的机器上运行,则还需要将“D:\Program Files\MATLAB\R2010b\toolbox\compiler\deploy\win32”中的MCRInstaller.exe复制出来,在未安装Matlab的电脑上运行此程序,才可使得刚刚生成的可执行文件顺利运行。 以上程序在Windows 7家庭普通版+ Visual Studio 2008专业版SP1 + Matlab R2010b下编译运行通过。
1、FINITE ELEMENT MESH GENERATION B.H.V. Topping, J. Muylle, P. Iványi, R. Putanowicz and B. Cheng http://www.saxe-coburg.co.uk/pubs/descrip/mgn.htm source code: http://www.bhvt.org.uk/mgn/ 本教学程序的教学主页: http://perso.uhp-nancy.fr/guenego/cd-mesh/mesh/general/index.html 另一个关于该程序的很好资源页面 http://www.maxwell.sze.hu/~kuczmann/HPC/tutorials/tutorial1/ Professor Barry H.V. Topping 教授主页 http://www.bhvt.org.uk/ 2、Finite Element Mesh Generation http://www.isr.umd.edu/~austin/aladdin.d/fe-mesh.html 3、 Aladdin FEM toolkit http://www.isr.umd.edu/~austin/aladdin.html 4、Mesh Generation Grid Generation on the Web http://www.robertschneiders.de/meshgeneration/meshgeneration.html 5.Finite element mesh generation http://nmag.soton.ac.uk/nmag/0.2/manual/html/finite_element_mesh_generation.html 6、土木系统编程 http://www.isr.umd.edu/~austin
久闻R语言的大名,但由于专业原因,直到去年暑假一个偶然的机会与一位统计专业的人士聊天,才知道R语言的强大威力!(当然这里没有贬低SPSS, SAS, Stata的意 思)。 R语言是用于统计分析、绘图的语言和操作环境。R是属于GNU系统的一个自由、免费、源代码开放的软件,它是一个用于统计计算和统计制图的优秀工具。它是统计领域广泛使用的诞生于 1980年左右的 S 语言的一个分支。 R是S语言的一种实现。S语言是由 ATT贝尔实验室开发的一种用来进行数据探索、统计分析、作图的解释型语言。最初S语言的实现版本主要是S-PLUS。S-PLUS是一个商业软件,它基于S语言,并由MathSoft 公司的统计科学部进一步完善。后来Auckland大学的Robert Gentleman 和 Ross Ihaka 及其他志愿人员开发了一个R系统。R的使用与S-PLUS有很多类似之处,两个软件有一定的兼容性。S-PLUS的使用手册,只要经过不多的修改就能成为 R的使用手册。换句话说:R,是S-PLUS的一个“克隆”,但R语言是免费的。 R是一套完整的数据处理、计算和制图软件系统。其功能包括:数据存储和处理系统;数组运算工具(其向量、矩阵运算方面功能尤其强大);完整连贯的统计分析工具;优秀的统计制图功能;简便而强大的编程语言:可操纵数据的输入和输入,可实现分支、循环,用户可自定义功能 。与其说R是一种统计软件,还不如说R是一种数学计算的环境,因为R并不是仅仅提供若干统计程序、使用者只需指定数据库和若干参数便可进行一个统计分析。R的思想是:它可以提供一些集成的统计工具,但更大量的是它提供各种数学计算、统计计算的函数,从而使使用者能灵活机动的进行数据分析,甚至创造出符合需要的新的统计计算方法。 R内建多种统计学及数字分析功能。 R语言的功能也可以透过安装套件(Packages,用户撰写的功能)增强。增加的功能有特殊的统计技术、绘图功能,以及编程介面和数据输出/输入功能。这些软件包是由R语言、 LaTeX、Java及最常用C语言和Fortran撰写。下载的执行档版本会连同一批核心功能的软件包,而根据 CRAN纪录有过千种不同的软件包。其中有几款较为常用,例如用于经济计量、财经分析、人文科学研究以及人工智能。因为S的血缘,R比其他统计学或数学专用的编程语言有更强的物件导向(面向对象程序设计)功能。此外虽然R语言主要用于统计分析或者开发统计相关的软体,但也有人用作矩阵计算。其分析速度可比美GNU Octave甚至商业软件MATLAB。 该语言的语法表面上类似 C,但在语义上是函数设计语言的(functional programming language)的变种并且和Lisp 以及 APL有很强的兼容性。特别的是,它允许在“语言上计算”(computing on the language)。这使得它可以把表达式作为函数的输入参数,而这种做法对统计模拟和绘图非常有用。 R是一个免费的自由软件,它有UNIX、LINUX、MacOS和WINDOWS版本,都是可以免费下载和使用的。R的主要网站是 http://www.r-project.org 。在那儿可以下载到R的安装程序和源代码、各种外挂程序和文档(点击进入:Windows (95 and later),再点击:base,下载SetupR.exe,约18兆,此便是R FOR WINDOWS的安装程序。双击SetupR.exe,按照提示一步步安装即可)。在R的安装程序中只包含了8个基础模块,其他外在模块可以通过CRAN(Comprehensive R Archive Network(R综合典藏网)的简称)获得( http://cran.r-project.org )。 统计编程R语言的更详细的介绍见: 中文官网: http://www.rproject.cn/ 英文官网: http://www.r-project.org/ http://cran.r-project.org/other-docs.html http://cran.r-project.org/mirrors.html 在这里我也给出一些学习R语言的材料共各位需要了解R语言的博友参考。(均来自网上,无版权,请勿商用!) 1. R for Beginners (中文版).pdf 2. R导论.pdf 3. R语言简介.pdf 4. 153 分钟学会R.pdf 5. 统计编程的框架与R语言统计分析基础.pdf 6. R语言初步_统计绘图与编程.ppt 7. R语言与统计分析.ppt 最近Springer出了一本用R语言解微分方程的书:Solving Differential Equations in R (Series: Use R!Soetaert, Karline, Cash, Jeff, Mazzia, Francesca,pp248, Springer,2012),希望热心的博友能提供一个电子版。谢谢!以下是这本书的前言摘录:Numerous examples help the reader to quickly solve a variety of differential equations in the open source software R. Shows how R can be used as a problem solving environment, using examples from the biological, chemical, physical, mathematical sciences. 我想找的书由热心的博友 bleu1860 提供: 8. Solving Differential Equations in R.pdf R语言资料汇集 R语言 中文网- R语言 论坛-最大的 R语言 中文社区 R语言 学习笔记 R语言 入门教程 R语言 _数据分析_中国统计网 下载R程序, http://www.r-project.org/ 。当然,如果你一定是找不到这个网站中R语言的程序位置,那么请看这里: http://ftp.ctex.org/mirrors/CRAN/ ,在这里,请点击install R for the first time,这样你就可以把这个软件下载下来了。接下来就跟我们平时使用软件一样,安装,安装时请注意一点: 安装路径不要有中文字符 ,以避免一些不必要的麻烦。接下来,我推荐大家一个额外的步骤,事实上你进行了上述步骤就可以真正开始你的R语言的使用了,但是我推荐大家再安装另外一个软件,叫做Rstudio。下载地址为: http://www.rstudio.com/ide/download/ 如果Rstudio提示你不能找到R的位置,你可以自行寻找,这里不再赘述。 R语言教材小结(2014.9) 以下内容转自: 常用统计学相关软件及网络资源 1、统计编程、应用软件 (1)、C语言 C语言计算速度快,但是编程难度大 入门教材: C语言趣味程序百例精解 (2)、Matlab 偏重于矩阵计算 相关教材:(见人大经济论坛) (a)、Applied Econometrics using MATLAB (b)、Computational Statistics Handbook with MATLAB (c)、Applied Statistics Using SPSS, STATISTICA, MATLAB and R (d)、An Introduction to Statistics in Matlab(可作为入门教材之一) 使用Matlab求解最大、小值时的有用工具: (a)、fmincon matlab自带函数,主用用于求解带约束条件时,给定函数的最小值,见相应的matlab help文档。 遗传算法(速度慢) (b)、fminunc Matlab自带函数,求解无约束条件下,某给定函数的最小值。 (c)、遗传算法工具箱 http://www.geatbx.com/ea_matlab.html 主要优点:对目标函数几乎没有要求,主要用于目标函数形式比较复杂情况下的优化问题 主要缺点:计算速度慢。 (3)、R语言 http://www.r-project.org/ R是用于统计分析、绘图的语言和操作环境。R是属于GNU系统的一个自由、免费、源代码开放的软件,它是一个用于统计计算和统计制图的优秀工具。R的语言风格和matlab及其类似,数据处理时,均采用向量化处理。R是开源软件,因此在 国外的高等院校中较为普及,是统计学、生物学及经济学等相关专业硕士至博士级的学生的必须课程。 但R的主要缺点是,R的内存管理能力较差,运行时会占用较多的内存资源,因此编程过程中,注意及时释放内存。此外,计算速度慢,特别当需要多次循环迭代时,速度极慢。解决的方法是,将需要循环迭代的部分用C或者Fortran语言编写,然后采用相关的接口程序加以调用。 R自带的编辑器较为简单,现在一般都使用开源软件Tinn-R来进行编辑。Tinn-R具有一定的语法检测和高亮显示功能。其下载地址: http://www.sciviews.org/Tinn-R/ 相关教材: (a)、R语言简介(最初级的入门教材,为R软件自带说明书) (b)、Time series analysis and its applications with R examples(结合时间序列分析) (c)、Introductory Statistics with R (d)、Programming with R(侧重于介绍R语言内在的逻辑和思想,较为高级,需要有一定的编程开发基础) (e)、Statistics with R(例子为主,较为全面) (4)、S及S-Plus S-Plus为商业软件。不过由于凡是能在S-Plus环境运行的程序,基本上都可以在R环境运行。 相关教材: (a)、Modelling Financial Time Series with S-PLUS (b)、Applied Smoothing Techniques for Data Analysis The Kernel Approach with S-Plus Illustrations (c)、Modern Applied Statistics with S (R 、S-Plus 等语言方面的经典教程 ) (d)、S Programming (R、S-Plus等语言方面的经典教程,内容更深刻,比Modern Applied Statistics with S难度大) (5)、SPSS、SAS SPSS是社会统计学的应用软件,再开发能力差。但简单易用。在国内较为普及,因此网络上可查找的资源较多 SAS是功能最强大的统计软件,具有优越的大型数据操作能力,为国外统计学专业的必备课程。但入门较难。 相关教程: (a)、The Little SAS Book. 2、文字编辑软件 (1)、CTex http://www.ctex.org/HomePage 中文版的latex。它已经集成了文字编辑和pdf编译为一起,是一款优化的数学论文编辑软件。用其编辑出来的数学公式大方美观。支持中文输入和编辑中文论文。 (2)、MikTex http://www.miktex.org/ 开源软件,功能类似于Ctex,但不支持中文编辑。自带的编辑器功能简单,一般结合软件TeXnicCenter和SummtraPDF(均为开源软件)软件使用。 (3)、TeXnicCenter http://www.texniccenter.org/ 开源软件,功能类似于WinEdt编辑器。某些功能甚至超过了WinEdt。 (4)、SummtraPDF http://blog.kowalczyk.info/software/sumatrapdf/free-pdf-reader.html PDF阅览器,占硬盘空间极小,编译时无需关闭,因此使用特别方便。此外,使用SummtraPDF还可以阅览djvu格式( http://djvu.org/ )的文件,因此功能特别强大。在国外使用非常广泛。 相关教程及论坛地址: (a)、 http://en.wikibooks.org/wiki/LaTeX (b)、 http://bbs.ctex.org/ (5)、UltraEdit和UltraComp 商业软件。具有强大的数据编辑和文字比较功能。可以与上述编程问论文编辑软件结合使用,可极大的提高效率。 3、网络资源 (1)、人大经济论坛 http://bbs.pinggu.org/ 可以下载数学相当可观的统计、经济、统计软件类外文电子书籍 (2)、统计之都 http://cos.name/ (3)、小木虫论坛 http://emuch.net/bbs/ 讨论科研、出国等方面的主要论坛之一 (4)、R语言中文论坛 http://www.biostatistic.net/forum-42-1.html
http://msdn.microsoft.com/zh-cn/library/ms173145.aspx 运算符(C# 编程指南) Visual Studio 2010 其他版本 Visual Studio 11 Visual Studio 2008 Visual Studio 2005 SPAN id=mt1 class=sentence data-guid="6e8389ad814e836de3eddc7ec47b9317" data-source='In C#, an operator is a program element that is applied to one or more operands in an expression or statement.' jQuery1710533584943800696="1"在 C# 中,运算符是应用于表达式或语句中一个或多个操作数的程序元素。 SPAN id=mt2 class=sentence data-guid="f60d0d8d3a05e5f251e2e5953f8b70bd" data-source='Operators that take one operand, such as the increment operator ( ++ ) or new , are referred to as unary operators.' jQuery1710533584943800696="2"接受一个操作数的运算符称为“一元”运算符,例如增量运算符 ( ++ ) 或 new 。 SPAN id=mt3 class=sentence data-guid="c8620114fdcc6bb5d8553b429ee95d87" data-source='Operators that take two operands, such as arithmetic operators ( + , - , * , / ), are referred to as binary operators.' jQuery1710533584943800696="3"接受两个操作数的运算符称为“二元”运算符,例如算术运算符 + 、 - 、 * 、 / 。 SPAN id=mt4 class=sentence data-guid="9d0b6da6ec79090b84241165b706f4fb" data-source='One operator, the conditional operator ( ?: ), takes three operands and is the sole ternary operator in C#.' jQuery1710533584943800696="4"条件运算符 ?: 接受三个操作数,是 C# 中唯一的三元运算符。 下面的 C# 语句包含一个一元运算符和一个操作数。 SPAN id=mt6 class=sentence data-guid="aad93e5e8ed1832e3e49adadde9895ee" data-source='The increment operator, ++ , modifies the value of the operand y .' jQuery1710533584943800696="6"增量运算符 ++ 修改操作数 y 的值。 注释:该网站还有很多资源!
多夫弗罗曼( Dov Fromana ) 的可擦除 紫外光只读存储器的设计为微机系统的快速发展提供了重要的设计工具 ,被称为 一个可擦写的只读程序或可编程只读存储器 。 英特尔公司掩码只读存储器 ( 1965 里程碑)模式建立在工厂,因此也需要几个星期来设计生产每个迭代。用户可编程只读存储器( PROM )的设备允许设计者在实验室中更改。 1970 年 5 月在公司推出辐射金属保险丝链接连接到 512 位的双极 TTL 电 PROM ( 64x8 )每个位。一位烧用户数据的 I / O ,频谱动态,以及其他一次性可编程熔丝编程单位 . 哈里斯(继任辐射) ,单片存储器,摩托罗拉和西格尼蒂克发展 1k 到 16K 位的镍铬保险丝的可编程只读存储器 。 AMD ,英特尔, IT 产业通过使用备用保险丝材料和肖特基技术 (1969 年里程碑 ) 进入市场。 1967 年斯佩里兰德和贝尔实验室的研究人员独立地描述可变内存存储器可以存储 MOS 栅介质中的电荷。 1971 年英特尔多弗弗罗曼用浮栅(悬空)存储在可擦写只读存储器(存储器) 1702 中。 2048 位内存设备可以改变并重复使用多次。模式是由暴露紫外线光通过包中石英窗口拭除。同时比双极设备执行要慢得多,可重用的可编程只读存储器大量被引用在微处理器 ( 1971 年里程碑) 和微控制器 ( 1974 年里程碑) 的原型 ROM 代码中。英特尔又继续出了几代 EPROM 高达数百万位密度, 1978 乔治 · 皮莱格斯设计的英特尔 2816 ,一个电可擦除 PROM ,消除了长时间的紫外线照射周期。 1981 年在 Seeq 与英特尔其他员工基础上 Perlegos 开发了一种改进的版本,可以对其进行编程和擦除原位。闪存,当今最广泛用于非易失性内存 (NVM) 的形式,是由富士男 Masuoka 的东芝开发于 1984 年和 1988 年由英特尔商业化。 当代文献 : D.Kahng 、 D 和施, S.M." 浮栅和内存设备中的应用 " 贝尔系统技术杂志,火山 46 ,第 4 (1967) pp.1288–1295 。 Wegener, H.A.R., Lincoln, A.J., Pao, H.C., O'Connell, M.R., Oleksiak, R.E. Lawrence, H." 可变阈值晶体管,新的电变、 非破坏性的只读存储设备, " 电子设备会议上,国际 1967 年、 火山 13 ( 1967 ) 体育 70 D." 内存行为在浮栅雪崩注入 MOS (FAMOS) 结构中, " 弗罗曼 -Bentchkowsky 卷第 18 (1971) 体育 332 应用物理快报。 弗罗曼 -Bentchkowsky D." 完全解码 2048 年位电可编程序 FAMOS 只读存储器, " 杂志的固态电路、、 火山 6 ,问题 5 ,第 301-306 页 (1971 年 10 月 ) 详细信息 : 奥加唐斯坦 " 电子魔术,一块 " 状态的艺术: 摄影历史的集成电路。(新的避难所科技纽约: Ticknor 和字段, 1983 年 ) 体育 32 。 布朗、 威廉 D. 和啤酒,乔 E. (编辑) 非易失性半导体存储技术 : 理解和使用自持设备综合指南。(威利 IEEE 出版社, 1997 年 10 月 15 日)。 " Fujio Masuoka : 感谢记忆。 创新, " 声音 ; 商业周刊 (2006 4 月 3 日 ) 。 译者:哈尔滨工业大学(威海)电子封装 090840220 刘卫超 校对者:090840228 谢战胜 英文原文: http://www.computerhistory.org/semiconductor/timeline/1971-EPROM.html 1971 - Reusable Programmable ROM Introduces Iterative Design Flexibility Dov Froman’s ultra-violet light erasable ROM design offers an important design tool for the rapid development of microprocessor-based systems, called an erasable, programmable read-only-memory or EPROM A masked ROM ( 1965 Milestone ) pattern is created in the factory and thus takes several weeks to produce each design iteration. User-programmable ROM (PROM) devices allow the designer to make changes in the lab. Radiation Inc. introduced a 512-bit bipolar TTL PROM (64x8) with metal fuse links connected to each bit in May 1970. A user "burned" the one-time-programmable fuses on programming units from Data I/O, Spectrum Dynamics, and others. Harris (successor to Radiation), Monolithic Memories, Motorola, and Signetics developed 1K through 16K-bit nickel-chromium fuse PROMs. AMD, Intel, and TI entered the market using alternative fuse materials and Schottky technology. ( 1969 Milestone ) Researchers at Bell Labs and Sperry Rand independently described alterable memory cells that stored charge in the MOS gate dielectric in 1967. At Intel in 1971 Dov Frohman used a floating (unconnected) gate for storage in the 1702 Erasable PROM (EPROM). The 2048-bits of memory could be changed and reused multiple times. The pattern was erased by exposure to ultra-violet light through a quartz window in the package. While much slower performing than bipolar devices, re-usable EPROMs found numerous applications in prototyping ROM codes for microprocessors ( 1971 Milestone ) and microcontrollers ( 1974 Milestone ). Intel went on to produce generations of EPROMs up to multi-million bits in density. In 1978 George Perlegos designed the Intel 2816, an Electrically Erasable PROM that eliminated the lengthy UV exposure cycle. On founding Seeq with other Intel employees in 1981, Perlegos developed an improved version that could be programmed and erased in-situ, in the system. Flash, today's most widely used non-volatile memory (NVM) form, was developed in 1984 by Fujio Masuoka of Toshiba and commercialized by Intel in 1988. 版权 copyright by www.computerhistory.org Contemporary Documents D. Kahng, D, and Sze, S. M. "A floating-gate and its application to memory devices," The Bell System Technical Journal, Vol. 46, No. 4 (1967) pp.1288–1295. Wegener, H.A.R., Lincoln, A.J., Pao, H.C., O'Connell, M.R., Oleksiak, R.E. Lawrence, H. "The variable threshold transistor, a new electrically-alterable, non-destructive read-only storage device," Electron Devices Meeting, 1967 International, Vol. 13 (1967) p. 70 Frohman-Bentchkowsky, D. "Memory behavior in a floating-gate avalanche-injection MOS (FAMOS) structure," Applied Physics Letters, Vol. 18 (1971) p. 332. Frohman-Bentchkowsky, D. "A fully decoded 2048-bit electrically programmable FAMOS read-only memory," IEEE Journal of Solid-State Circuits, , Vol. 6, Issue 5, (Oct 1971) pp. 301-306. Oral History transcripts online at the Computer History Museum Frohman-Bentchkowsky, Dov (Intel) an oral history (2009-05-02) Intel FLASH Non-Volatile Memory oral history panel - Kynett, Lai, McCormick, Pashley (2007-11-20) Harari, Eli. (Intel, Waferscale, SanDisk) Transcript in process More Information Augarten, Stan. "A Piece of Electronic Magic," State Of The Art: A Photographic History of the Integrated Circuit. (New Haven New York: Ticknor and Fields, 1983) p. 32. Brown, William D. and Brewer, Joe E. (Editors) Nonvolatile Semiconductor Memory Technology: A Comprehensive Guide to Understanding and Using NVSM Devices. (Wiley-IEEE Press, October 15, 1997). "Fujio Masuoka: Thanks for the Memory. Voices of Innovation," Business Week (April 3, 2006). EPROM的发明者多夫弗罗曼面具设计图纸 石英窗口紫外光EPROM 1971英特尔编程存储器
下面的这些经典的引言来自英文,也许有些我翻译的是不很好,所以,我提供了中英对照,如果有问题,请大家指正。 过早的优化是万恶之源。Premature optimization is the root of all evil! - Donald Knuth 在水里行走和以一个需求规格进行软件开发,有一点是相同的,那就是如果水或需求都被冻住不了,那么行走和软件开发都会变得容易。Walking on water and developing software from a specification are easy if both are frozen - Edward V Berard Hofstadter 定理:“一件事情总是会花费比你预期更多的时间,就算是你已经考虑过本条 Hofstadter 定理”。It always takes longer than you expect, even when you take into account Hofstadter’s Law. - Hofstadter’s Law 有些遇到问题的人总是会说“我知道,我会使用正则表达式”,那么,你现在有两个问题了。(意思是:你本想用正则表达式来解决你已有问题,但实际上你又引入了“正则表达式”的一个新问题)Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems - Jamie Zawinski 调试程序的难度是写代码的两倍。因此,只要你的代码写的尽可能的清楚,那么你在调试代码时就不需要那么地有技巧。Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. - Brian Kernighan 用代码行来衡量开发进度,无异于用重量来衡量制造飞机的进度。Measuring programming progress by lines of code is like measuring aircraft building progress by weight. - Bill Gates PHP被一些不合格的业余人员造就成了一个小恶魔;而Perl则是被一些熟练的但不正当的专业人员造就成了一个超级大恶魔。PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil, perpetrated by skilled but perverted professionals. - Jon Ribbens 在两个场合我被问到:“请你告诉我,如果你给机器输入了错误的数字,那么,是否还能得到正确的答案?”我并不能正确领会这类想法。(意思是:程序需要有纠错的能力吗?)On two occasions I have been asked, ‘Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?’ I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.” - Charles Babbage 在编程的时候,我们一定要想像一下,以后维护我们自己的代码的那个人会成为一个强烈的精神病人,并且,他还知道我们住在哪里?Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Rick Osborne 现代的编程是“程序员努力建一个更大更傻的程序”和“世界正在尝试创造更多更傻的人”之间的一种竞赛,目前为止,后者是赢家。 Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook 我才不关于我的代码是否能在你的机器上工作!我们不会给你提供机器。I don’t care if it works on your machine! We are not shipping your machine! - Ovidiu Platon 我总是希望我的电脑能够像电话一样容易使用;我的这个希望正在变成现实,因为我现在已经不知道怎么去使用我的电话了。I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone. - Bjarne Stroustrup 计算机是一种在人类历史上所有发明中,可以让你比以前更快地犯更多的错误的发明,同样,其也包括了“手枪”和“龙舌兰酒”这两种发明的缺陷。A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. - Mitch Ratcliffe 如果调试程序是一种标准的可以铲除BUG的流程,那么,编程就是把他们放进来的流程。If debugging is the process of removing software bugs, then programming must be the process of putting them in. - E. W. Dijkstra 教一群被BASIC先入为主的学生,什么是好的编程风格简直是一件不可能的事。对于一些有潜力的程序员,他们所受到的智力上的伤害远远超过了重建他们的信心。It is practically impossible to teach good programming style to students that have had prior exposure to BASIC. As potential programmers, they are mentally mutilated beyond hope of regeneration. - E. W. Dijkstra 理论上来说,理论和实际是一样的。但实际上来说,他们则不是。In theory, theory and practice are the same. In practice, they’re not. - Unknown 只有两个事情是无穷尽的:宇宙和人类的愚蠢。当然,我现在还不能确定宇宙是无穷尽的。Two things are infinite: the universe and human stupidity; and I’m not sure about the universe. - Albert Einstein Perl这种语言就好像是被RSA加密算法加密过的一样。Perl - The only language that looks the same before and after RSA encryption. - Keith Bostic 我爱“最终期限”,我喜欢“嗖嗖嗖”的声音就像他们在飞一样。I love deadlines. I like the whooshing sound they make as they fly by. - Douglas Adams 说Java好的是因为它跨平台就像好像说肛交好是因为其可以适用于一切性别。Saying that Java is good because it works on all platforms is like saying anal sex is good because it works on all genders - Unknown XML就像是一种强暴——如果它不能解决你的问题,那只能说明你没有用好它。XML is like violence - if it doesn’t solve your problems, you are not using enough of it. - Unknown 爱因期坦说,自然界中的一切一定会有一个简单的解释,因为上帝并不是反复无常和独裁的。当然,不会有什么信仰能程序员像爱因期坦那样感到舒服。 Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer. - Fred Brooks
转载自: http://vastars.info/parallelcomputing/openmp.html 距离上次写 并行计算概述 很有段日子了,后续的可能至少有三篇文章需要写。今天花了点时间针对Openmp共享内存的并行编程写了点东西。这里只能提供一点概念和感觉(甚至有可能会误导),需要系统学习Openmp并行计算的朋友可以到文章末尾下载推荐的教材。个人觉得把那书翻翻就足够用啦~ 什么是OpenMP? “ OpenMP (Open Multi-Processing) is an application programming interface (API) that supports multi-platform shared memory multiprocessing programming in C, C++ and Fortran on many architectures, including Unix and Microsoft Windows platforms. It consists of a set of compiler directives, library routines, and environment variables that influence run-time behavior. ” 简单来说,OpenMP是一个可以应用于多种平台的共享内存式并行计算的接口。 Openmp的工作模式: Openmp的工作模式为串行-并行-串行…。一开始的主线程是串行,当在需要并行的时候(这时候程序中应该有相应的Openmp指令语句),多个线程开始一起工作。若当前的并行块结束(仍旧由相应的Opemp指令语句来控制)时,又重新回到单一的主线程。如此可往复继续。在一个四核心cpu上运行Openmp程序(并行块的线程数默认是核心数目,这里即为4个线程),程序处于主线程时cpu利用率为100%,但是当程序进入并行块时所有的核心都会参与进来,cpu利用率会达到400%。如果程序的主要运算部分都处于并行区域,则绝大部分时间cpu都处于400%的工作状态,这样便大大提高cpu的利用率。 Openmp程序的结构: 正如上面所说,编写Openmp程序只需要在已有的串行程序上稍加修改即可:在并行开始和结束的地方加上Openmp语句引导并行的开始和结束。这些引导语句本身处于注释语句的地位,必须在编译时加上Openmp并行参数才能使其生效。如果不加编译参数,编译出来的程序仍旧是串行程序。 Openmp是最容易实现的并行方式。 Openmp程序的编写: 下面以fortran语言为例说明Openmp程序的编写(对c语言和fortran语言,都可以参考本文最后给出的openmp教程)。一般的格式为 !$omp parallel CLAUSE !$omp DIRECTION !$omp end DIRECTION !$omp end parallel 其中 DIRECTION 是Openmp指令,有sections,do等,指定并行行为。中间的 即是需要并线的程序块。除了上面的称为 DIRECTION 的指令语句外,Openmp还需要称为 CLAUSE 的从句对并行进行限制和说明。比如,需要对私有变量进行声明时就需要用到private从句(这是经常要遇到的,后面会以例子说明)。在fortran的串行编译下,以“!”打头的都处于屏蔽状态是不起作用的。加了openmp编译参数后才会生效。 我在程序编写中用到最多的是do指令,偶尔用一下sections。do指令通常用来并行化do循环。本来用一个线程来执行的长的do循环被分割成几个部分让多个线程同时执行,这样就节省了时间。sections指令通常用来将前后没有依赖关系的程序块(也即原本不分先后,你换下顺序也无所谓)并行化。因为无关联,所以可以同时执行。 可以说,若程序主要用来做计算,掌握了do和sections这两个指令足矣! 简单的程序例子: 1.Sections 指令的应用: !$OMP PARALLEL SHARED(A,B,C), PRIVATE(I) !//Paralell块开始 !$OMP SECTIONS !//Sections开始 !$OMP SECTION !//第一个section DO I = 1, N/2 C(I) = A(I) + B(I) END DO !$OMP SECTION !//第二个section DO I = 1+N/2, N C(I) = A(I) + B(I) END DO !$OMP END SECTIONS NOWAIT !//Sections结束 !$OMP END PARALLEL !//Paralell块结束 这个并行语句将本来从1到N的循环手动分为两个部分并行执行。上面的shared,private就是从句(clause),声明A,B,C为公有的,而循环指标I是私有的。因为两个section同时执行,都会对I进行改变,所以两个section的循环指标必须彼此独立,不能是同一个变量。PRIVATE会自动将这个会引发冲突的变量按需生成多个拷贝以供使用。最后的!$OMP END SECTIONS NOWAIT语句告诉两个线程可各自自行结束,无需相互等待。 2.Do 指令的应用: 上面用Section实现的功能完全可以用Do来实现: !$OMP PARALLEL SHARED(A,B,C), PRIVATE(I) !//Paralell块开始 !$OMP DO !//Do的并行开始 DO I = 1, N C(I) = A(I) + B(I) END DO !$OMP END DO !//Do的并行结束 !$OMP END PARALLEL !//Paralell块结束 Do循环本来是从1到N,现在有多少个线程就分为多少个部分执行,比上面的section更方便智能。不用担心循环次数N不能被线程数整除~。一般情况下,各个线程均分循环次数,但是在某些循环指标下运算可能比较快,所以各个线程的运算时间可能不尽相同。这时候如果需要让各个线程都结束了才能再往下(没有NOWAIT),快的线程就必须等待慢的线程。为了解决这个问题需要加上schedule从句,首行变为如下: !$OMP PARALLEL SHARED(A,B,C), PRIVATE(I), SCHEDULE(DYNAMIC) 这个SCHEDULE(DYNAMIC)从句告诉程序动态调整并线方式,那些任务轻松运算快的线程会自动去帮任务重运算慢的线程,力争所有线程同时完成任务。 关于Do的积累计算,如累加,需要加上REDUCTION从句: C=0.d0 !$OMP PARALLEL SHARED(A,C), PRIVATE(I), REDUCTION(+:C) !$OMP DO DO I = 1, N C =C+ A(I) END DO !$OMP END DO !$OMP END PARALLEL 这里将累加分为几个部分由多个线程进行运算,由于各个线程都在0.d0的基础上开始计算它该算的部分,所以最后必须将各部分计算的结果再次求和。 REDUCTION(+:C) 从句就实现了这个效果。类似的叠乘等等用类似写法,只需把“:”前的运算符改为乘法“*”即可。 一些注意问题: 1.尤其要注意的问题就是变量的私有和公有问题。其实只要把握好一个原则,即如果这个变量有可能会被不同的线程同时进行写操作(这不是你希望看到的),则这个变量就应该声明为私有。一般来说,并行体中临时用到的一些中间变量应该是私有的。 2.据我的经验,Fortran中如果不特别声明,变量都是默认公有的。这一点可以用DEFAULT(PRIVATE/SHARED)从句强行改变。循环指标默认是私有的,无需自己另外声明。放在common域中的变量都是全局的,若要将这些全局变量私有化,可使用threadprivate指令(参见文章: OpenMP并行编程:threadprivate指令 )。 3.并行引导语句可以简化,但要注意前后配对。比如上面那个累加的例子可以这样写: C=0.d0 !$OMP PARALLEL DO SHARED(A,C), PRIVATE(I), REDUCTION(+:C) DO I = 1, N C =C+ A(I) END DO !$OMP END PARALLEL DO 也即可以将从句加在指令之后。 4.Fortran+Openmp的编译问题: 一般来说,加上-openmp编译参数即可。如: ifort -openmp -o exe.out main.f gfortran用-fopenmp编译参数,g77和ifort一样用-openmp参数。 如果用Makefile,将编译参数放在合适的地方。 5.对于多重do循环,如果中间变量太多,对私有公有弄不清楚或者虽然清楚但是闲麻烦,可以保留最外层循环,将里面的循环在别处写成一个子函数或子程序 ,然后在此处调用。这样从结构上看就是对一重循环进行并行化,条理清楚不容易出错。当然,传递给子函数或子程序的参数一般是要声明私有的。 6.将串行程序改为Openmp并行程序后,在加与不加-openmp编译参数的情况下分别编译并运算,比较并行与串行的结果,确保并行块没有改错。 7.可以在并行开始前指定由多少个线程来并行。在单cpu单核心的机器上也可以(虽然没有实际意义,但可以用来调试并行程序): CALL OMP_SET_NUM_THREADS(scalar_integer_expression) 其中scalar_integer_expression是个整形变量,指定并行的线程数目。 8.Openmp对私有变量的大小有限制。所以当遇到这样的情况,一般就是由这个限制造成的:不加openmp并行时程序没有问题,加了openmp并行时出现断错误(segmentation fault),但是当把某个(一些)私有数组的维数变小时,段错误消失而且和串行时结果一致。 解决办法(linux下,windows下另外search)如下: 在linux终端执行 ulimit -s unlimited ;export KMP_STACKSIZE= 2048000
高温假虽然还没有结束,但工作要正式开始了。做事没有计划性,虎头蛇尾是我的一大弊病,为了严格监督自己的进度,同时也考虑到与各老师同学交流,在此开辟工作笔记系列。 今天的任务是理清模型思路,收集各计算公式,对计算的每一个步骤理解精准。 以下为论文 Interfacial Forces, Average Pore Size, and Pore Size Distribution of Ultrafiltraction Membrane, Kam Chan, Takeshi Matsuura and S. Sourirajan, Ind. Eng. Chem. Prod. Res. Dev. 1982.21附录中提到。 介绍部分我认为重要的:孔流模型用在ployethylene glycol(聚乙二醇PEG)
贝塞尔 函数 ( Bessel function, 又称柱函数 ) 是一类在各工程领域中有着广泛应用的特殊函数。贝塞尔函数是贝塞尔方程 ( 一个二阶常微分方程 ) 的解。 一般有三类贝塞尔函数 1 、第一类贝塞尔函数 (Bessel function of the first kind) J v (x) 2 、第二类贝塞尔函数 (Bessel function of the second kind), 又称诺依曼函数( Neumann function ) :Y v (x)( 或 N v (x)) 3 、第三类贝塞尔函数( Bessel function of the third kind ),又称汉克尔函数( Hankel function ) : H 1 v (x) 和 H 2 v (x) 。 当贝塞尔方程为变形贝塞尔方程 ( 虚宗量贝塞尔方程 ) 时,方程的解一般有两类 1、 变形第一类贝塞尔函数( modified Bessel function of the first kind ) I v (x) 2、 变形第二类贝塞尔函数( modified Bessel function of the second kind ) K v (x) 另外应用比较多的函数还有球贝塞尔函数 (Spherical Bessel functions) 、艾里函数 (Airy functions )等等。由于贝塞尔函数的广泛应用,很多软件都提供了现成的函数供用户使用。 Mathematics :提供了比较多的 Bessel 函数。如: Bessel 函数 BesselJ BesselY BesselI BesselK 球体 Bessel 函数 SphericalBesselJ SphericalBesselY Hankel 函数 HankelH1 HankelH2 SphericalHankelH1 SphericalHankelH2 Airy 函数 AiryAi AiryAiPrime AiryBi AiryBiPrime Kelvin 函数 KelvinBer KelvinBei KelvinKer KelvinKei Struve 函数 StruveH StruveL AngerJ WeberE 零函数 BesselJZero BesselYZero AiryAiZero AiryBiZero Matlab :提供了五个函数 besselj 、 bessely 、 besselh 、 besseli 和 besselk 分别对应第一类 Bessel 函数、第二类 Bessel 函数、第三类 Bessel 函数、第一类变形 Bessel 函数和第二类变形 Bessel 函数。语法 besselj(nu,z) : nu 为函数的阶次,可以不为整数但必须为实数。 z 为函数的变量,可以为复数。还有 besselj(nu,z,1) 语法,可查询帮助。其他函数除了 besselh 有些不同外,基本类似。至于球函数、 Airy 函数等可通过这个函数来构造实现。 Excel :提供了四个函数,即: BESSELJ 、 BESSELY 、 BESSELI 、 BESSELK 。 语法: BESSELJ (x,n) ;其中, x 为参数值, n 为函数的阶数。如果 n 非整数,则截尾取整。即 Excel 中只能计算整数阶次的 Bessel 函数。其他函数类似。 关于贝塞尔函数的专业书籍有: 中文 刘颖,《圆柱函数》国防工业出版社, 1983 。 奚定平,《贝塞尔函数》高等教育出版社和施普林格出版社, 1998. 英文 George Neville Watson 《 A Treatise on the Theory of Bessel Functions 》 Cambridge University Press , 1995(1944 , 1922) 最经典的一本书。 BG Korenev 《 Bessel Functions and Their Applications 》 CRC 2002. Milton Abramowitz, and Irene A. Stegun 《 Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables 》 Dover Publications 1964. I.S. Gradshteyn, I.M. Ryzhik, A Jeffrey, D Zwillinger 《 Table of integrals, series and products 》 (Seventh Edition) Academic Press 2007.
线性微分方程的求解方法很多,直接积分可以得到很高的精度。但是尝试一下用数值逼近的方法也是很有意思的。 下面以用Chebyshev多项式展开求解方程(x= 的一段) dy/dx=y y(0)=1 为例说明这个方法。 n阶Chebyshev定义为T(n,x)=cos(n arccos(x))。假设函数y(x)可以近似为 y(x)=\sum^{n}_{i=1} a_i T(i,x) 那么,取需要求解的区间内的n-1个点,加上初始条件,方程可以表示为n元线性方程组,用线性代数的方法可以求解展开系数a_i。 下面是实现这个方法的一段代码 function trychebyshev2(n,t0,t1)% use first n Chebyshev polinomial to approximate % t0:lower boundary; t1: upper boundary A=zeros(n,n); h=t0:(t1-t0)/n:t1; t=h(2:end); for j=1:n-1 for i=1:n A(j,i)=chebT(i,t(j))-chebQ(i,t(j)); % the differential equation is y'=y, y(0)=1 end end for i=1:n A(n,i)=chebT(i,0); end B=zeros(n,1); B(n)=1; x=linsolve(A,B); z=0:0.05:1; f1=0; for i=1:n f1=f1+x(i)*chebT(i,z); end f2=exp(z); plot(z,f1,'r',z,f2,'b'); function y=chebT(n,x) y=cos(n.*acos(x)); function y=chebQ(n,x) y=sin(n.*acos(x)).*n./sqrt(1-x.^2); 用5阶Chebyshev多项式时误差可以达到百分之几。 用10阶Chebyshev多项式近误差就小得多了。 不过,可以看到,在近似区间之外,近似函数和真实函数就完全不同了。
笔记(十一)IDL三维可视化的一种方法 用TV命令画等值面 pro three fitsname='../gaussfit.fits' a=mrdfits(fitsname) head=headfits(fitsname);read the header of the fits file to a vector nx = fxpar(head,'NAXIS1'); number of elements in the first dimension ny = fxpar(head,'NAXIS2'); nv = fxpar(head,'NAXIS3'); ;a=read_binary('/home/qianl/Software/idl_6.2/examples/data/head.dat',$ ; data_dims= ,data_type=1) b=lindgen(nx,ny,nv) bnz0=b/nx/ny bny0=(b-bnz0*nx*ny)/nx bnx0=b-bnz0*nx*ny-bny0*nx bx=bnx0*1.0d0 by=bny0*1.0d0 bv=bnz0*1.0d0 ;a=exp(-((bx-30.0)/10.0)^2-((by-30.0)/10.0)^2-((bv-30.0)/10.0)^2) shade_volume,a,max(a)/2.0,v,p,/low scale3,xrange= ,yrange= ,zrange= set_plot,'PS' filename='3d_TV.ps' ; set the file name of the output ps file device,file=filename,/COLOR, BITS=8 tv,polyshade(v,p,/t3d) device,/CLOSE end
笔记(十)二维高斯分布和高斯聚类的程序 生成两个二维高斯分布随机数样本的组合样本,用混合高斯模型聚类,算出每个点属于每个高斯成分的概率,代码如下,结果如图所示。 %testcluster.m: z1= ; z2= ; z= ; x=gmm(z,2); hold on scatter3(z(:,1),z(:,2),x(:,1),'.'); scatter3(z(:,1),z(:,2),x(:,2),'.'); %axis( ) %view( ); view(-162,-13); hold off print -dpng gmm.png %gmm.m function varargout = gmm(X, K_or_centroids) % ============================================================ % Expectation-Maximization iteration implementation of % Gaussian Mixture Model. % % PX = GMM(X, K_OR_CENTROIDS) % = GMM(X, K_OR_CENTROIDS) % % - X: N-by-D data matrix. % - K_OR_CENTROIDS: either K indicating the number of % components or a K-by-D matrix indicating the % choosing of the initial K centroids. % % - PX: N-by-K matrix indicating the probability of each % component generating each point. % - MODEL: a structure containing the parameters for a GMM: % MODEL.Miu: a N-by-K matrix. % MODEL.Sigma: a D-by-D-by-K matrix. % MODEL.Pi: a 1-by-K vector. % ============================================================ threshold = 1e-15; = size(X); if isscalar(K_or_centroids) % judge if K_or_centroids is a scalar K = K_or_centroids; % K is the number of Gaussian components % randomly pick centroids rndp = randperm(N); % randomly permute the index array 1:N centroids = X(rndp(1:K), :); % centers of the Gaussian components else K = size(K_or_centroids, 1); % size of the first dimension (number of rows) centroids = K_or_centroids; end % initial values = init_params(); Lprev = -inf; while true Px = calc_prob(); % new value for pGamma pGamma = Px .* repmat(pPi, N, 1); % (N by K) matrix pGamma = pGamma ./ repmat(sum(pGamma, 2), 1, K); % (N by K) matrix % new value for parameters of each Component Nk = sum(pGamma, 1); % add to a single row (1 by K) pMiu = diag(1./Nk) * pGamma' * X; % (K by D) pPi = Nk/N; for kk = 1:K Xshift = X-repmat(pMiu(kk, :), N, 1); % (N by D) pSigma(:, :, kk) = (Xshift'* ... (diag(pGamma(:, kk)) * Xshift))/ Nk(kk); % (D by D) end % check for convergence L = sum(log(Px*pPi')); if L-Lprev threshold break; end Lprev = L; end if nargout == 1 varargout = {Px}; else model = = init_params() pMiu = centroids; % set the centers of Gaussian components pPi = zeros(1, K); pSigma = zeros(D, D, K); % hard assign x to each centroids distmat = repmat(sum(X.*X, 2), 1, K) + ... repmat(sum(pMiu.*pMiu, 2)', N, 1) - ...% (N by K) matrix 2*X*pMiu'; % pMiu' (D by K) % add the columns to a single column % and creat a large % matrix (N by K) by % tiling % X*pMiu' (N by K) % distmat is an (N by K) % to specify the % distance of every data % point to the K centers = min(distmat, [], 2); % return minimum of every row % labels is the column % numbers for k=1:K Xk = X(labels == k, :); pPi(k) = size(Xk, 1)/N; pSigma(:, :, k) = cov(Xk); % if Xk is a vector, cov(Xk)is % the variance,just set the % K initial (D by D matrix) to the same value end end function Px = calc_prob() Px = zeros(N, K); for k = 1:K Xshift = X-repmat(pMiu(k, :), N, 1); % N by D matrix inv_pSigma = inv(pSigma(:, :, k)); % invert the matrix (D by D) tmp = sum((Xshift*inv_pSigma) .* Xshift, 2); % N element vector coef = (2*pi)^(-D/2) * sqrt(det(inv_pSigma)); Px(:, k) = coef * exp(-0.5*tmp); % the probability end end end
笔记(七)关于命令行直接运行IDL脚本 假设有一个IDL脚本test.pro,内容为 pro test print,1+1 end 现在想直接在shell里运行而不先启动IDL,怎么办?我的土办法是另写一个文件test,内容为 #!/usr/local/idl test 再变为可执行文件。然后,把test.pro里的pro test和end两行注释掉。这样就可以直接敲test了。IDL自动启动,运行test.pro。 如果想执行完直接退出IDL,那么在test.pro中再加一行 exit 就可以了。
笔记(五)模拟中性氢质量函数 在这里附上模拟某个极限流量时观测到的河外星系中性氢的质量函数的代码。 z=0.1; %redshift rmax=zD(z);% maximum distance corresponding to maximum redshift thetastar=8.6e-3;% normalization of the mass function V=200.0; % line width in km/s f=0.7; % factor accounting for the line shape Slim=3.0e-5; % flux limit, in Jy dx=3.906; % length of side of a volume element, in Mpc dy=3.906; dz=3.906; volume=dx*dy*dz; % volume element, in Mpc^3 local=26.0; % local latitude dec1=local+30.0; % range of relevant declination dec2=local-30.0; %a=load('densmap_250_G10.0.dat'); x=a(:,1); % coordinate y=a(:,2); z=a(:,3); b=a(:,4); % % %max(b); % % %maxb=23.5072;% the maximum of the density contrast % % b=b./maxb; % = meshgrid(-250:1:250, -250:1:250, -250:1:250); % % v = x .* exp(-x.^2 - y.^2 - z.^2); % slice(x,y,z,a, ,2, ) n=length(b); MHI= ; NHI=zeros(1,5); M=6:10; M=M+0.5; for i=1:n if mod(i,1000)==0 i end V=sgc2ec(x(i),y(i),z(i)); ra=V(1); dec=V(2); r=sqrt(x(i).^2+y(i).^2+z(i).^2); if decdec1decdec2rrmax % if in the right dec and redshift range ngal=volume*(b(i)+1.0)*thetastar; if ngal~=0 mgal=floor(ngal); xgal=mgal+((ngal-mgal)rand());% if the number is not integer % the decimal part is treated as % probability if xgal0 temp=GenRanNum2(xgal); % generate a sample with the distribution of the mass function for i=1:xgal S=temp(i)./(2.356e5.*r.^2.*V.*f); if SSlim % if can be detected MHI= ; % add to the whole sample Dist= ; j=ceil(log10(temp(i))-6); NHI(j)=NHI(j)+1; end end end end end end save simulation_NHI.txt NHI -ascii %plot(M,NHI,'*'); bar(M,NHI); % histogram title(strcat('redshift:',num2str(z),' Slim:',num2str(Slim))); xlabel('\fontname{times New Toman}\fontsize{16}log(M_{HI}/M_{sun})'); ylabel('\fontname{times New Toman}\fontsize{16}N'); print -depsc2 simulation.eps
红移距离转换也是常用的一个操作。现把代码放在下面 function y=zD(z) % z-distance relation, distance in units of Mpc h=0.72; DH=3000./h; % in Mpc OmegaM=0.274; OmegaLam=0.726; %fun=strcat('',num2str(OmegaM),'*(1+x)^3+',num2str(OmegaLam),'') DC=DH.*comdis(OmegaM,OmegaLam,z); DM=DC; % for zero curvature y=DM.*(1+z); %================================================= function y=comdis(OmegaM,OmegaLam,z0) function f=E(z) f=1.0./sqrt(OmegaM.*(1+z).^3+OmegaLam); end y=quadl(@E,0,z0); end
语录:101条伟大的计算机编程名言 HACKER 2009-05-23 18:50 阅读 17 评论 1 字号: 大 大 中 中 小 小 人们总是害怕改变。电被发明出来的时候他们害怕电,是不是?他们害怕煤,害怕蒸汽机车。无知无所不在,并导致恐惧。但随着时间推移,人们终究会接受最新的科技。 正如比尔盖茨曾经警告过一样,计算机已经真正成为我们的最新科技,几乎遍布我们日常生活的每一方面。所以,我们这个时代的某些最伟大的头脑开始思索起计算机和软件对于人类的重要性来了。以下就是101条有关计算机的伟大名言,并且,既然我们这个网站是一个软件开发网站,我们尤其关注编程方面的。 计算机 1、计算机没什么用。他们只会告诉你答案。 (巴勃罗毕加索,画家) 2、计算机就跟比基尼一样,省去了人们许多的胡思乱想。 (萨姆尤因,作家) 3、他们拥有计算机,他们也还可能拥有其他的大规模杀伤性武器。 (珍内特雷诺,美国前女司法部长) 4、跟计算机工作酷就酷在这里,它们不会生气,能记住所有东西,还有,它们不会喝光你的啤酒。 (保罗利里,吉他手) 5、如果汽车能赶上计算机的发展周期的话,一辆今天的劳斯莱斯仅值100美元,每加仑要跑100万英里,每年还得爆炸一次,把里面的人杀个精光。 (RobertX.Cringely,技术作家) 计算机智能 6、计算机总是越来越智能的。科学家告诉我们说不久它们就能跟我们对话了。(这里的它们,我指的是计算机。我怀疑科学家永远都不能跟我们对话。) (DaveBarry,幽默作家) 7、我最近注意到,在共同文化中,那种对计算机变得智能化并最终掌控世界的妄想恐惧症几乎彻底消失了。据我所知,这跟MS-DOS的发布基本是同步的。 (LarryDeLuca) 8、计算机会不会思考这个问题就像问潜水艇会不会游泳一样。 (EdsgerW.Dijkstra,图灵奖获得者) 9、活了一百年却只能记住30M字节是荒谬的。你知道,这比一张压缩盘还要少。人类境况正在变得日趋退化。 (MarvinMinsky,人工智能研究的奠基人) 信任 10、这座城市的中央计算机告诉你的?R2D2,你不该相信一台陌生的计算机! (C3PO,星球大战中的翻译机器人) 11、永远不要相信一台不能扔掉一扇窗户*的计算机 (斯蒂夫沃兹尼亚克,苹果联合创始人) *译者:暗指微软的wINDOWS操作系统 硬件 12、硬件:计算机系统中可被踢的部分。 (JeffPesis) 软件 13、今天大部分的软件都很像上百万块砖堆叠在一起组成的埃及金字塔,缺乏结构完整性,只能靠强力和成千上万的奴隶完成。 (阿伦凯,图灵奖获得者,面向对象创始人) 14、我终于明白向上兼容性是怎么回事了。这是指我们得保留所有原有错误。 (DennievanTassel) 操作系统 15、有两样重要产品出自伯克利:LSD和BSD*。我们不相信这是个巧合。 (JeremyS.Anderson) *译者:LSD是一种药力至强的迷幻剂,BSD-BSD(BerkeleySoftwareDistribution,伯克利软件套件)是Unix的衍生系统 16、2038年1月19日,凌晨3点14分07秒 (UNIX中的世界末日*1970年1月1号之后的2^32秒) *译者:word跟world同音,UNIX用4个字节(WORD)表示时间,所以最多只能计时2^32秒 17、每个操作系统都差不多我们都一样的烂。 (微软的高级副总裁布莱恩瓦伦蒂尼这样描述操作系统的安全状况,2003) 18、微软有出了个新版本,WindowsXP,据大家说是有史以来最稳定的Windows,对我而言,这就好像是在说芦笋是有史以来发音最清脆的蔬菜一样 (DaveBarry) 互联网 19、互联网?那个东西还在吗? (HomerSimpson) 20、网络就像是个母夜叉。我每转到一处都会看见小个的按钮命令我提交*。 (Nytwind) *译者注:Submit:提交,另一层意思是要求屈服 21、想想看吧,已经有一百万只猴子坐在一百万台打字机旁,可Usenet就是比不上莎士比亚。 (BlairHoughton) 软件产业 22、计算机软件产业最为惊人的成就,是其持续不断地放弃硬件产业的惊人成果和稳定性。 (HenryPetroski) 23、真正的创新经常来自于那些贴近市场、但无力拥有市场的的小型初创公司。 (TimmMartin) 24、人们常说,伟大的科学学科就像是站在其它巨人肩膀上的巨人。人们也说过,软件产业正如站在其他侏儒脚上的侏儒。 (AlanCooper,交互设计之父) 25、这无关比特、字节和协议,而关乎利润和损益。 (郭士纳,IBM前CEO) 26、我们是微软。反抗是徒劳的。你会被同化的。 (保险杠贴纸) 软件演示 27、不管演示在彩排的时候有多好,一旦在观众面前展示时,演示不出错的几率与观众人数成反比,与投入的金钱总额成正比。 (MarkGibbs) 软件专利 28、专利大多数都是垃圾。浪费时间去阅读这些专利是愚蠢的。只有专利持有人才会这么干,还得强迫自己才会看。 (LinusTorvalds,LINUX创始人) 复杂性 29、控制复杂性是计算机编程的本质。 (BrianKernigan) 30、复杂性杀死一切。它把程序员的生活给搞砸了,它令产品难以规划、创建和测试,带来了安全挑战,并导致最终用户和管理员沮丧不已。 (RayOzzie) 31、进行软件设计有两种方式。一种是让它尽量简单,让人看不出明显的不足。另一种是弄得尽量复杂,让人看不出明显的缺陷。 (C.A.R.Hoare) 32、好的软件的作用是让复杂的东西看起来简单。 (GradyBooch,UML创始人之一) 易用性 33、不管那些计算机书籍如何宣称,只需记住,你并非傀儡。真正的傀儡是那些无法设计出易于使用的硬件和软件的那些人,尽管他们是技术专家,因为这是普通消费者赖以生活的东西。 (WalterMossberg,科技专栏记者) 34、软件供应商在努力尝试让他们的软件更易于操作迄今为止,他们最好的办法就是翻出所有的老手册,然后在封面盖上易于操作这几个字。 (比尔盖茨) 35、有个老套的故事说有人希望他的计算机能像他的电话机一样好用。他的愿望实现了,因为我已经不知道该如何使用自己的电话了。 (BjarneStroustrup,C++之父) 用户 36、任何一个傻瓜都会用电脑。很多都会。 (TedNelson) 37、只有两个行业把客户称为用户*。 (EdwardTufte,信息设计大师) *译者注:一个是计算机设计,另一个是毒品交易,computerdesignanddrugdealing 程序员 38、程序员在跟宇宙赛跑,他们在努力开发出更大更好的傻瓜程序,而宇宙则努力培养出更大更好的白痴。到目前为止,宇宙领先。 (RichCook) 39、你们当中很多人都知道程序员的美德。当然啦,有三种:那就是懒惰、急躁以及傲慢。 (LarryWall,Perl发明者) 40、程序员的问题是你无法预料他在做什么,直到为时已晚。 (SeymourCray,超级计算机之父) 41、那就是这些自认为痛恨计算机的人的真实面目。他们实际上真正痛恨的是糟糕的程序员。 (拉瑞尼文,科幻作家) 42、很长时间以来我一直困惑不已,为什么一些又贵又先进的东西会一点用都没有。直到我突然想起,计算机不就是一台愚蠢之至却拥有难以置信的做聪明事能力的机器嘛,而程序员不就是聪明绝顶却拥有难以置信的干蠢事的能力的人嘛。一句话,他们简直就是天生绝配。 (比尔布莱森,旅游文学作家) 43、不像学学涂涂画画也能让某人成为专家级画家,计算机科学教育不会让任何人成为一名编程大师。 (埃里克雷蒙,开源运动领袖) 44、一个程序员是经历以下事情后仍能证明自己是严格的专家的人:他可以历经数不清的捶打,可取材于无关紧要的文档,用上面的争议数据作出模糊假设,并以此计算出测微精度的无数片面理解的答案,并由一个不可靠、脑袋充满质疑、公开宣称要让一个倒霉透顶、没有指望、毫无防备,要求第一时间获得信息的部门狼狈不堪、令人生厌的人使用一台准确度有问题的仪器去实施。 (IEEE网格新闻杂志) 45、运气好的黑客能用几个月的时间-生产出一个小规模的开发团体(比如说,7-8人)历尽艰辛一起工作了一年多才能做出来的东西。IBM经常报告说某些程序员的生产力要比其它工人高百倍,甚至更多。 (PeterSeebach,黑客) 46、最好的程序员跟好的程序员相比可不止好那么一点点。这种好不是一个数量级的,取决于标准怎么定:概念创造性、速度、设计的独创性或者解决问题的能力。 (兰德尔E斯特劳斯,科技作家) 47、伟大的车工值得给他几倍于普通车工的薪水,但一个伟大的软件代码作家,其价值则要等同于一个普通的软件写手的价格的1万倍。 (比尔盖茨) 编程 48、就算它工作不正常也别担心。如果一切正常,你早该失业了。 (Mosher的软件工程定律) 49、靠代码行数来衡量开发进程就好比用重量来衡量飞机制造的进度。 (比尔盖茨) 50、写代码的社会地位比盗墓的高,比管理的低。 (杰拉尔德温伯格,软件与系统思想家) 51、首先学习计算机科学及理论。接着形成自己编程的风格。然后把这一切都忘掉,尽管改程序就是了。 (GeorgeCarrette,杰出软件工程师,开源推广者) 52、先解决问题再写代码。 (JohnJohnson) 53、乐观主义是编程行业的职业病;用户反馈则是治疗方法。 (KentBeck) 54、迭代者为人,递归者为神。 (L.PeterDeutsch) 55、布尔值最好的一点是,就算你错了,也顶多错了一位而已。 (无名氏) 56、数组的下标是从0开始好还是从1开始好呢?我的0.5的折衷方案,以我之见,没有经过适当考虑就被否决掉了。 (StanKelly-Bootle) 编程语言 57、只有两种编程语言:一种是天天挨骂的,另一种是没人用的。 (BjarneStroustrup,C++之父) 58、PHP是不合格的业余爱好者创建的,他们犯做了个小恶;Perl是娴熟而堕落的专家创建的,他们犯了阴险狡诈的大恶。 (JonRibbens) 59、COBOL的使用摧残大脑;其教育应被视为刑事犯罪。 (E.W.Dijkstra) 60、把良好的编程风格教给那些之前曾经接触过BASIC的学生几乎是不可能的。作为可能的程序员,他们已精神残废,无重塑的可能了。 (E.W.Dijkstra) 61、我想微软之所以把它叫做.Net,是因为这样它就不会在Unix的目录里显示出来了。 (Oktal) 62、Thereisnoprogramminglanguagenomatterhowstructuredthatwillpreventprogrammersfrommakingbadprograms. (LarryFlon) 63、计算机语言设计犹如在公园里漫步。我是说侏罗纪公园。 (LarryWall) C/C++ 64、搞了50年的编程语言的研究,我们难道就以C++告终啦? (RichardA.OKeefe) 65、写C或者C++就像是在用一把卸掉所有安全防护装置的链锯。 (BobGray) 66、在C++里你想搬起石头砸自己的脚更为困难了,不过一旦你真的做了,整条腿都要报销。 (BjarneStroustrup) 67、C++:友人可造访你的私有成员之地也。 (GavinRussellBaker) 译者:Friends:C++的友元,是一种定义在类外部的普通函数,但它需要在类体内进行说明,为了与该类的成员函数加以区别,在说明时前面加以关键字friend。友元不是成员函数,但是它可以访问类中的私有成员。友元的作用在于提高程序的运行效率,但是,它破坏了类的封装性和隐藏性,使得非成员函数可以访问类的私有成员。 68、罗马帝国灭亡的其中一个主要原因是他们没有0-这样他们就没法给自己的C程序指明成功退出的路径了。 (RobertFirth) Java 69、Java从许多方面来说就是C++。 (MichaelFeldman) 70、说Java好就好在运行于多个操作系统之上,就好像说肛交好就好在不管男女都行。 (Alanna) 71、好吧,Java也许是编程语言的好榜样。但Java应用则是应用程序的坏榜样。 (pixadel) 72、要是Java真的有垃圾回收的话,大部分程序在执行的时候就会把自己干掉了。 (RobertSewell) 开源 73、软件就像性事:免费/自由更好。 (LinusTorvalds) 74、唯一对免费软件感到害怕的人,是自己的产品还要不值钱的人。 (DavidEmery) 代码 75、好代码本身就是最好的文档。 (SteveMcConnell) 76、你自己的代码如果超过6个月不看,再看的时候也一样像是别人写的。 (伊格尔森定律) 77、前面90%的代码要占用开发时间的前90%。剩下的10%的代码要占用开发时间的另一90%。 (TomCargill) 软件开发 78、好的程序员会用脑,但是好的向导救我们于样样都要想到。 (FrancisGlassborow) 79、在软件里面,我们鲜有有意义的需求。就算有,衡量成功的唯一尺度也取决于我们的解决方案是否解决了客户对问题是什么的观念的转变。 (JeffAtwood) 80、想想我们计算机程序的糟糕现状吧,很显然软件开发仍是黑箱艺术,还不能称之为工程学科。 (BillClinton,前美国总统) 81、没有伟大的团队就没有伟大的软件,可大部分的软件团队举止就像是支离破碎的家庭。 (吉姆麦卡锡,微软VC++总监) 调试 82、一旦我们开始编程,就会惊讶地发现让程序正常没想象中那么简单。调试不可避免。那一刻我认记忆犹新,当时我就意识到,从今往后我生活的大部分时间都要花在寻找自己程序的错误上面了。 (莫里斯威尔克斯调试探索,1949) 83、调试难度本来就是写代码的两倍。因此,如果你写代码的时候聪明用尽,根据定义,你就没有能耐去调试它了。 (BrianKernighan) 84、如果调试是除虫的过程,那么编程就一定是把臭虫放进来的过程。 (EdsgerW.Dijkstra) 质量 85、我才不管它能不能在你的机器上运行呢!我们又没装到你的机器上! (VidiuPlaton,罗马尼亚的微软最佳学生合作伙伴MSP) 86、编程就像性一样:一时犯错,终生维护。 (MichaelSinz) 87、有两种写出无错程序的办法;只有第三种有用。 (AlanJ.Perlis) 88、软件质量与指针算法不可兼得。 (BertrandMeyer) 89、如果麦当劳像软件公司那样运作的话,每一百个巨无霸就会有一个令你食物中毒,而他们的回应是,真对不起,这是一张额外附送两个的赠券。 (MarkMinasi) 90、永远要这样写代码,好像最终维护你代码的人是个狂暴的、知道你住在哪里的精神病患者。 (MartinGolding) 91、是人都会犯错,不过要想把事情彻底搞砸还得请电脑出马。 (PaulEhrlich) 92、计算机比人类历史上的任何发明都更快速地导致你犯更多的错误可能除了手枪和龙舌兰酒是例外。 (MitchRadcliffe) 预测 93、能发明的东西都发明出来了。 (查尔斯杜埃尔,美国专利局局长,1899年) 94、我认为全球市场约需5台计算机。 (托马斯沃森,IBM董事长,约1948年) 95、看上去我们已经到达了利用计算机技术可能获得的极限了,尽管下这样的结论得小心,因为不出五年这听起来就会相当愚蠢。 (约翰冯诺伊曼,约1949年) 96、但这又有什么好处呢? (IBM先进计算机系统部的工程师对微芯片的评论,1968年) 97、我们没有理由让每一个人在家都拥有一台电脑。 (肯奥尔森,数据设备公司(DEC)总裁,1977年) 98、640K对每一个人来说都已足够。 (比尔盖茨,1981年) 99、WindowsNT的RAM寻址空间可达2G,这比任何应用程序所需都要多。 (微软,谈及WindowsNT的开发时所言,1992年) 100、我们永远也无法真正成为无纸化社会,直到掌上电脑一族发布擦我1.0*(WipeMe1.0)为止。 (安迪皮尔逊,商界领袖) *译者注:意思是说难道你大便不用纸吗? 101、长此以往,除了按键的手指外,人类的肢体将全部退化。 (弗兰克劳埃德赖特,建筑师) 附:英文版 2009 - 05 - 24 101 Great Computer Programming Quotes 关键字: 精彩转载 People always fear change. People feared electricity when it was invented, didnt they? People feared coal, they feared gas-powered engines. There will always be ignorance, and ignorance leads to fear. But with time, people will come to accept their silicon masters. As Bill Gates once warned, computers have indeed become our silicon masters, pervading nearly every aspect of our modern lives. As a result, some of the greatest minds of our time have pondered the significance of computers and software on the human condition. Following are 101 great quotes about computers, with an emphasis on programming, since after all this is a software development site. Computers Computers are useless. They can only give you answers. (Pablo Picasso) Computers are like bikinis. They save people a lot of guesswork. (Sam Ewing) They have computers, and they may have other weapons of mass destruction. (Janet Reno) Thats whats cool about working with computers. They dont argue, they remember everything, and they dont drink all your beer. (Paul Leary) If the automobile had followed the same development cycle as the computer, a Rolls-Royce would today cost $100, get a million miles per gallon, and explode once a year, killing everyone inside. (Robert X. Cringely) Computer Intelligence Computers are getting smarter all the time. Scientists tell us that soon they will be able to talk to us. (And by they, I mean computers. I doubt scientists will ever be able to talk to us.) (Dave Barry) Ive noticed lately that the paranoid fear of computers becoming intelligent and taking over the world has almost entirely disappeared from the common culture. Near as I can tell, this coincides with the release of MS-DOS. (Larry DeLuca) The question of whether computers can think is like the question of whether submarines can swim. (Edsger W. Dijkstra) Its ridiculous to live 100 years and only be able to remember 30 million bytes. You know, less than a compact disc. The human condition is really becoming more obsolete every minute. (Marvin Minsky) Trust The citys central computer told you? R2D2, you know better than to trust a strange computer! (C3PO) Never trust a computer you cant throw out a window. (Steve Wozniak) Hardware Hardware: The parts of a computer system that can be kicked. (Jeff Pesis) Software Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves. (Alan Kay) Ive finally learned what upward compatible means. It means we get to keep all our old mistakes. (Dennie van Tassel) Operating Systems There are two major products that come out of Berkeley: LSD and UNIX. We dont believe this to be a coincidence. (Jeremy S. Anderson) 19 Jan 2038 at 3:14:07 AM (End of the word according to Unix2^32 seconds after January 1, 1970) Every operating system out there is about equal We all suck. (Microsoft senior vice president Brian Valentine describing the state of the art in OS security, 2003) Microsoft has a new version out, Windows XP, which according to everybody is the most reliable Windows ever. To me, this is like saying that asparagus is the most articulate vegetable ever. (Dave Barry) Internet The Internet? Is that thing still around? (Homer Simpson) The Web is like a dominatrix. Everywhere I turn, I see little buttons ordering me to Submit. (Nytwind) Come to think of it, there are already a million monkeys on a million typewriters, and Usenet is nothing like Shakespeare. (Blair Houghton) Software Industry The most amazing achievement of the computer software industry is its continuing cancellation of the steady and staggering gains made by the computer hardware industry. (Henry Petroski) True innovation often comes from the small startup who is lean enough to launch a market but lacks the heft to own it. (Timm Martin) It has been said that the great scientific disciplines are examples of giants standing on the shoulders of other giants. It has also been said that the software industry is an example of midgets standing on the toes of other midgets. (Alan Cooper) It is not about bits, bytes and protocols, but profits, losses and margins. (Lou Gerstner) We are Microsoft. Resistance Is Futile. You Will Be Assimilated. (Bumper sticker) Software Demos No matter how slick the demo is in rehearsal, when you do it in front of a live audience, the probability of a flawless presentation is inversely proportional to the number of people watching, raised to the power of the amount of money involved. (Mark Gibbs) Software Patents The bulk of all patents are crap. Spending time reading them is stupid. Its up to the patent owner to do so, and to enforce them. (Linus Torvalds) Complexity Controlling complexity is the essence of computer programming. (Brian Kernigan) Complexity kills. It sucks the life out of developers, it makes products difficult to plan, build and test, it introduces security challenges, and it causes end-user and administrator frustration. (Ray Ozzie) There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies. (C.A.R. Hoare) The function of good software is to make the complex appear to be simple. (Grady Booch) Ease of Use Just remember: youre not a dummy, no matter what those computer books claim. The real dummies are the people whothough technically expertcouldnt design hardware and software thats usable by normal consumers if their lives depended upon it. (Walter Mossberg) Software suppliers are trying to make their software packages more user-friendly Their best approach so far has been to take all the old brochures and stamp the words user-friendly on the cover. (Bill Gates) Theres an old story about the person who wished his computer were as easy to use as his telephone. That wish has come true, since I no longer know how to use my telephone. (Bjarne Stroustrup) Users Any fool can use a computer. Many do. (Ted Nelson) There are only two industries that refer to their customers as users. (Edward Tufte) Programmers Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. (Rich Cook) Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris. (Larry Wall) The trouble with programmers is that you can never tell what a programmer is doing until its too late. (Seymour Cray) Thats the thing about people who think they hate computers. What they really hate is lousy programmers. (Larry Niven) For a long time it puzzled me how something so expensive, so leading edge, could be so useless. And then it occurred to me that a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match. (Bill Bryson) Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond) A programmer is a person who passes as an exacting expert on the basis of being able to turn out, after innumerable punching, an infinite series of incomprehensive answers calculated with micrometric precisions from vague assumptions based on debatable figures taken from inconclusive documents and carried out on instruments of problematical accuracy by persons of dubious reliability and questionable mentality for the avowed purpose of annoying and confounding a hopelessly defenseless department that was unfortunate enough to ask for the information in the first place. (IEEE Grid newsmagazine) A hacker on a roll may be able to producein a period of a few monthssomething that a small development group (say, 7-8 people) would have a hard time getting together over a year. IBM used to report that certain programmers might be as much as 100 times as productive as other workers, or more. (Peter Seebach) The best programmers are not marginally better than merely good ones. They are an order-of-magnitude better, measured by whatever standard: conceptual creativity, speed, ingenuity of design, or problem-solving ability. (Randall E. Stross) A great lathe operator commands several times the wage of an average lathe operator, but a great writer of software code is worth 10,000 times the price of an average software writer. (Bill Gates) Programming Dont worry if it doesnt work right. If everything did, youd be out of a job. (Moshers Law of Software Engineering) Measuring programming progress by lines of code is like measuring aircraft building progress by weight. (Bill Gates) Writing code has a place in the human hierarchy worth somewhere above grave robbing and beneath managing. (Gerald Weinberg) First learn computer science and all the theory. Next develop a programming style. Then forget all that and just hack. (George Carrette) First, solve the problem. Then, write the code. (John Johnson) Optimism is an occupational hazard of programming; feedback is the treatment. (Kent Beck) To iterate is human, to recurse divine. (L. Peter Deutsch) The best thing about a boolean is even if you are wrong, you are only off by a bit. (Anonymous) Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration. (Stan Kelly-Bootle) Programming Languages There are only two kinds of programming languages: those people always bitch about and those nobody uses. (Bjarne Stroustrup) PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals. (Jon Ribbens) The use of COBOL cripples the mind; its teaching should therefore be regarded as a criminal offense. (E.W. Dijkstra) It is practically impossible to teach good programming style to students that have had prior exposure to BASIC. As potential programmers, they are mentally mutilated beyond hope of regeneration. (E. W. Dijkstra) I think Microsoft named .Net so it wouldnt show up in a Unix directory listing. (Oktal) There is no programming languageno matter how structuredthat will prevent programmers from making bad programs. (Larry Flon) Computer language design is just like a stroll in the park. Jurassic Park, that is. (Larry Wall) C/C++ Fifty years of programming language research, and we end up with C++? (Richard A. OKeefe) Writing in C or C++ is like running a chain saw with all the safety guards removed. (Bob Gray) In C++ its harder to shoot yourself in the foot, but when you do, you blow off your whole leg. (Bjarne Stroustrup) C++ : Where friends have access to your private members. (Gavin Russell Baker) One of the main causes of the fall of the Roman Empire was thatlacking zerothey had no way to indicate successful termination of their C programs. (Robert Firth) Java Saying that Java is nice because it works on all OSes is like saying that anal sex is nice because it works on all genders. (Alanna) Fine, Java MIGHT be a good example of what a programming language should be like. But Java applications are good examples of what applications SHOULDNT be like. (pixadel) If Java had true garbage collection, most programs would delete themselves upon execution. (Robert Sewell) Open Source Software is like sex: Its better when its free. (Linus Torvalds) The only people who have anything to fear from free software are those whose products are worth even less. (David Emery) Code Good code is its own best documentation. (Steve McConnell) Any code of your own that you havent looked at for six or more months might as well have been written by someone else. (Eaglesons Law) The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. (Tom Cargill) Software Development Good programmers use their brains, but good guidelines save us having to think out every case. (Francis Glassborow) In software, we rarely have meaningful requirements. Even if we do, the only measure of success that matters is whether our solution solves the customers shifting idea of what their problem is. (Jeff Atwood) Considering the current sad state of our computer programs, software development is clearly still a black art, and cannot yet be called an engineering discipline. (Bill Clinton) You cant have great software without a great team, and most software teams behave like dysfunctional families. (Jim McCarthy) Debugging As soon as we started programming, we found to our surprise that it wasnt as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs. (Maurice Wilkes discovers debugging, 1949) Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you areby definitionnot smart enough to debug it. (Brian Kernighan) If debugging is the process of removing bugs, then programming must be the process of putting them in. (Edsger W. Dijkstra) Quality I dont care if it works on your machine! We are not shipping your machine! (Vidiu Platon) Programming is like sex: one mistake and youre providing support for a lifetime. (Michael Sinz) There are two ways to write error-free programs; only the third one works. (Alan J. Perlis) You can either have software quality or you can have pointer arithmetic, but you cannot have both at the same time. (Bertrand Meyer) If McDonalds were run like a software company, one out of every hundred Big Macs would give you food poisoning, and the response would be, Were sorry, heres a coupon for two more. (Mark Minasi) Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. (Martin Golding) To err is human, but to really foul things up you need a computer. (Paul Ehrlich) A computer lets you make more mistakes faster than any invention in human historywith the possible exceptions of handguns and tequila. (Mitch Radcliffe) Predictions Everything that can be invented has been invented. (Charles H. Duell, Commissioner, U.S. Office of Patents, 1899) I think theres a world market for about 5 computers. (Thomas J. Watson, Chairman of the Board, IBM, circa 1948) It would appear that we have reached the limits of what it is possible to achieve with computer technology, although one should be careful with such statements, as they tend to sound pretty silly in 5 years. (John Von Neumann, circa 1949) But what is it good for? (Engineer at the Advanced Computing Systems Division of IBM, commenting on the microchip, 1968) There is no reason for any individual to have a computer in his home. (Ken Olson, President, Digital Equipment Corporation, 1977) 640K ought to be enough for anybody. (Bill Gates, 1981) Windows NT addresses 2 Gigabytes of RAM, which is more than any application will ever need. (Microsoft, on the development of Windows NT, 1992) We will never become a truly paper-less society until the Palm Pilot folks come out with WipeMe 1.0 . (Andy Pierson) If it keeps up, man will atrophy all his limbs but the push-button finger. (Frank Lloyd Wright)
22条经典的编程引言 HACKER 2009-05-24 15:08 阅读 51 评论 6 字号: 大 大 中 中 小 小 下面的这些经典的引言来自英文,也许有些我翻译的是不很好,所以,我提供了中英对照,如果有问题,请大家指正。 过早的优化是万恶之源。Premature optimization is the root of all evil! - Donald Knuth 在水里行走和以一个需求规格进行软件开发,有一点是相同的,那就是如果水或需求都被冻住不了,那么行走和软件开发都会变得容易。Walking on water and developing software from a specification are easy if both are frozen - Edward V Berard Hofstadter 定理:一件事情总是会花费比你预期更多的时间,就算是你已经考虑过本条Hofstadter 定理。It always takes longer than you expect, even when you take into account Hofstadters Law. - Hofstadters Law 有些遇到问题的人总是会说我知道,我会使用正则表达式,那么,你现在有两个问题了。(意思是:你本想用正则表达式来解决你已有问题,但实际上你又引入了正则表达式的一个新问题)Some people, when confronted with a problem, think I know, Ill use regular expressions. Now they have two problems - Jamie Zawinski 调试程序的难度是写代码的两倍。因此,只要你的代码写的尽可能的清楚,那么你在调试代码时就不需要那么地有技巧。Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. - Brian Kernighan 用代码行来衡量开发进度,无异于用重量来衡量制造飞机的进度。Measuring programming progress by lines of code is like measuring aircraft building progress by weight. - Bill Gates PHP被一些不合格的业余人员造就成了一个小恶魔;而Perl则是被一些熟练的但不正当的专业人员造就成了一个超级大恶魔。PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil, perpetrated by skilled but perverted professionals. - Jon Ribbens 在两个场合我被问到:请你告诉我,如果你给机器输入了错误的数字,那么,是否还能得到正确的答案?我并不能正确领会这类想法。(意思是:程序需要有纠错的能力吗?)On two occasions I have been asked, Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out? I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage 在编程的时候,我们一定要想像一下,以后维护我们自己的代码的那个人会成为一个强烈的精神病人,并且,他还知道我们住在哪里?Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Rick Osborne 现代的编程是程序员努力建一个更大更傻的程序和世界正在尝试创造更多更傻的人之间的一种竞赛,目前为止,后者是赢家。Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook 我才不关于我的代码是否能在你的机器上工作!我们不会给你提供机器。I dont care if it works on your machine! We are not shipping your machine! - Ovidiu Platon 我总是希望我的电脑能够像电话一样容易使用;我的这个希望正在变成现实,因为我现在已经不知道怎么去使用我的电话了。I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone. - Bjarne Stroustrup 计算机是一种在人类历史上所有发明中,可以让你比以前更快地犯更多的错误的发明,同样,其也包括了手枪和龙舌兰酒这两种发明的缺陷。A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. - Mitch Ratcliffe 如果调试程序是一种标准的可以铲除BUG的流程,那么,编程就是把他们放进来的流程。If debugging is the process of removing software bugs, then programming must be the process of putting them in. - E. W. Dijkstra 教一群被BASIC先入为主的学生,什么是好的编程风格简直是一件不可能的事。对于一些有潜力的程序员,他们所受到的智力上的伤害远远超过了重建他们的信心。It is practically impossible to teach good programming style to students that have had prior exposure to BASIC. As potential programmers, they are mentally mutilated beyond hope of regeneration. - E. W. Dijkstra 理论上来说,理论和实际是一样的。但实际上来说,他们则不是。In theory, theory and practice are the same. In practice, theyre not. - Unknown 只有两个事情是无穷尽的:宇宙和人类的愚蠢。当然,我现在还不能确定宇宙是无穷尽的。Two things are infinite: the universe and human stupidity; and Im not sure about the universe. - Albert Einstein Perl这种语言就好像是被RSA加密算法加密过的一样。Perl - The only language that looks the same before and after RSA encryption. - Keith Bostic 我爱最终期限,我喜欢嗖嗖嗖的声音就像他们在飞一样。I love deadlines. I like the whooshing sound they make as they fly by. - Douglas Adams 说Java好的是因为它跨平台就像好像说肛交好是因为其可以适用于一切性别。Saying that Java is good because it works on all platforms is like saying **** sex is good because it works on all genders - Unknown XML就像是一种强暴如果它不能解决你的问题,那只能说明你没有用好它。XML is like violence - if it doesnt solve your problems, you are not using enough of it. - Unknown 爱因期坦说,自然界中的一切一定会有一个简单的解释,因为上帝并不是反复无常和独裁的。当然,不会有什么信仰能程序员像爱因期坦那样感到舒服。Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer. - Fred Brooks