Mathematica 9.0简明教程24页
- 格式:doc
- 大小:1.20 MB
- 文档页数:25
Mathemat i ca 简易教程习题及解答2.7练习题1、定义函数/(龙)=* +缶+COS3 ,求当X = 1,3.1, 5时,/(①)的值,再求/(^2)0ln[5]:= f [-x_] : = -x A 2 + 1 / (-x + 1) + Cos [-x]f [{1, 3.1, Pi / 2, x A 2}] // TraditionalForm0 ut[6]//T ra ditionalFc rm=+cos(l), 8.85477, 求当^ = -100,1.5,2,3,100时,丁(⑦)的值(要 求具有40位有效数值)。
ln[11]:= f :=E A J ^/;-K <0£ [乞] :=Log [^] / ; 0 < -x Ef [乞] :=Sqrt [-x] / ; -x > EN[f [{- -100, 1・5, 2, 3, 100}] , 40]Out[1<= {10 000.8 52217 9 6213 66738330918375038 4 9332 43,2 ・72074,3・ 91713 64 967 8 619094 63357 65103832571143567,8 ・2 60007503399554 54272 8 4272 052 687 38 697 606,10 000.8722198 6238 66939 35092 037 52 39 518 32 63}3、造一个九九乘法表,只要求以表格形式显示乘积结果。
Out[21]//TableFcrm=1 2 3 4 5 6 74 6 8 10 12 14 169 12 15 18 21 24 2716 20 24 28 32 3625 30 35 40 4536 42 48 5449 56 6364 7281 + COSl .V^ | :ln[21]:= Table [i ♦ j , {i, 1, 9}, (jz ±, 9}] / / TableForm X < 00 < T < e x > e1、求极限。
mathematica简明使用教程Mathematica是一种强大的数学软件,广泛应用于科学研究、工程计算和数据分析等领域。
本文将简要介绍Mathematica的使用方法,帮助读者快速上手。
一、安装和启动Mathematica我们需要下载并安装Mathematica软件。
在安装完成后,可以通过桌面图标或开始菜单中的快捷方式来启动Mathematica。
二、界面介绍Mathematica的界面分为菜单栏、工具栏、输入区域和输出区域四部分。
菜单栏提供了各种功能选项,工具栏包含了常用的工具按钮,输入区域用于输入代码或表达式,而输出区域则显示执行结果。
三、基本操作1. 输入和输出在输入区域输入代码或表达式后,按下Shift+Enter键即可执行,并在输出区域显示结果。
Mathematica会自动对输入进行求解或计算,并返回相应的输出结果。
2. 变量定义可以使用等号“=”来定义变量。
例如,输入“a = 3”,然后执行,就会将3赋值给变量a。
定义的变量可以在后续的计算中使用。
3. 函数调用Mathematica内置了许多常用的数学函数,可以直接调用使用。
例如,输入“Sin[π/2]”,然后执行,就会返回正弦函数在π/2处的值。
4. 注释和注解在代码中添加注释可以提高代码的可读性。
在Mathematica中,可以使用“(*注释内容*)”的格式来添加注释。
四、数学运算Mathematica支持各种数学运算,包括基本的加减乘除,以及更复杂的求导、积分、矩阵运算等。
下面简要介绍几个常用的数学运算:1. 求导可以使用D函数来求导。
例如,输入“D[Sin[x], x]”,然后执行,就会返回正弦函数的导数。
2. 积分可以使用Integrate函数来进行积分运算。
例如,输入“Integrate[x^2, x]”,然后执行,就会返回x的平方的不定积分。
3. 矩阵运算Mathematica提供了丰富的矩阵运算函数,可以进行矩阵的加减乘除、转置、求逆等操作。
Mathematica使用教程【Mathematica 简介】Mathematica 软件是由沃尔夫勒姆研究公司(Wolfram Research Inc.)研发的。
Mathematica 版发布于1988年6月23日。
发布之后,在科学、技术、媒体等领域引起了一片轰动,被认为是一个革命性的进步。
几个月后,Mathematica 就在世界各地拥有了成千上万的用户。
今天,Mathematica 已经在世界各地拥有了数以百万计的忠实用户。
Mathematica 已经被工业和教育领域被广泛地采用。
实际上,Mathematica 负责将高级的数学和计算引入了传统上非技术的领域,极大的增加了科技软件的市场。
一个包含应用、咨询、书籍、和课程软件的行业支持着国际化的 Mathematica 用户群,这个行业还在不断地膨胀。
随着沃尔夫勒姆研究公司不断地扩大和 Mathematica 的使用被不断地扩展到不同的领域,将会看到 Mathematica 在全世界范围内对未来产品、重要研究发现、和教学的巨大影响。
数学软件是现在科研工作者的必备的工具,个人比较喜欢用Mathematica,因为它是最接近数学语言的。
Mathematica 在15日发布,其最显著的变化是允许自由形式的英文输入,而不再需要严格按照Mathematica语法,这类似于Wolfram|Alpha搜索引擎。
Mathematica 8允许用户按照自己习惯的思考过程输入方程式或问题,最令人激动的部分是软件不是逐行执行命令,而是能理解上下文背景。
1. Enter your queries in plain English using new free-form linguistic input2. Access more than 10 trillion sets of curated, up-to-date, and ready-to-use data3. Import all your data using a wider array of import/export formats4. Use the broadest statistics and data visualization capabilities on the market5. Choose from a full suite of engineering tools, such as wavelets and control systems6. Use more powerful image processing and analysis capabilities7. Create interactive tools for rapid exploration of your ideas8. Develop faster and more powerful applicationsWolfram Research 的CEO 和创立者斯蒂芬·沃尔夫勒姆表示:“传统上,让计算机执行任务必须使用计算机语言或者使用点击式界面:前者要求用户掌握它的语法;而后者则限制了可访问函数的范围。
Mathematica使⽤教程第⼆章 Mathematica 简介Mathematica 是⼀个符号计算与数值计算的通⽤数学软件包,是由美国的物理学家Stephen Wolfram 所领导的⼀个⼩组开发成功并推向市场的。
Mathematica 由最初的1.0、1.2、2.0、2.2、2.4、3.0版,到现在的4.0版,⽬前国内常⽤的版本是Windows 下的3.0及4.0版。
与Mathcad 和MATLAB 相⽐,Mathematica 才称得上是⼀个真正的数学符号计算软件包,因为只有它的内核是以符号计算为基础的,⽐如你可以定义⼀些数学规则,让它为你进⾏符号推导演算⼯作。
在Mathematica 中,你可以像Mathcad 那样进⾏草稿式的数学计算,你也可以像MATLAB ⼀样进⾏命令式的数学计算。
本章以4.0版为基础,介绍Mathematica 的使⽤⽅法。
2.1 Mathematica 的集成环境及基本操作当Mathematica 运⾏时,会出现如图所⽰的窗⼝。
右边的⼩窗⼝,我们称为数学⼯具⾯板,它包含多种数学符号,更多的符号可从命令菜单File/Palettes 中得到,利⽤它,可以像Mathcad ⼀样输⼊数学算式,⽐如上⾯计算的积分,完全可以通过数学⼯具⾯板,在Mathematica 中写成20[2]x Sin x dx π的形式,但这种输⼊⽅法有两个问题:⾸先,Mathematica 的输⼊操作不如Mathcad ⽅便,其次,由于Mathematica 的函数及符号太多,导致这种输⼊⽅法效率太低。
因此,我们对这种直观的命令输⼊⽅法将不做过多的介绍。
有兴趣的读者可以查阅相关的帮助主题。
笔者认为,使⽤Mathematica 计算数学问题最有效的⽅法是,直接通过键盘输⼊每个函数所代表的英⽂字符串。
左边的⼤窗⼝,Mathematica 称之为Notebook ,Mathematica 可以将在Notebook 中输⼊的命令存⼊⼀个扩展名为“.nb ”的⽂件中,⾸次进⼊时默认的⽂件名为Untitled-1.nb 。
A Tutorial Introduction to MathematicaAims and Objectives•To provide a tutorial guide to Mathematica.•To give practical experience in using the package.•To promote self-help using the online help facilities.•To provide a concise reference source for experienced users.On completion of this chapter the reader should be able to•use Mathematica as a tool;•produce simple Mathematica notebooks;•access some Mathematica commands and notebooks over the World Wide Web.It is assumed that the reader is familiar with either the Windows or UNIX platform.This book was prepared using Mathematica(Version6.0)but most pro-grams should work under earlier and later versions of the package.Note that the online version of the Mathematica commands for this book will be written using the most up-to-date version of the package.The command lines and programs listed in this chapter have been chosen to allow the reader to become familiar with Mathematica within a few hours.They20.A Tutorial Introduction to Mathematicaprovide a concise summary of the type of commands that will be used throughout the text.New users should be able to start on their own problems after completing the chapter,and experienced users shouldfind this chapter an excellent source of reference.Of course,there are many Mathematica textbooks on the market for those who require further applications or more detail.If you experience any problems there are several options for you to take. There is an excellent index within Mathematica,and Mathematica commands, notebooks,programs,and output can also be viewed in color over the Web at Mathematica’s Information Center:/infocenter/Books/AppliedMathematics/The notebookfiles can be found at the links Calculus Analysis and Dynamical Systems.Download the zipped notebookfiles and Extract the relevantfiles from the archive onto your computer.0.1A Quick Tour of MathematicaTo start Mathematica,simply double-click on the Mathematica icon.In the UNIX environment,one types mathematica as a shell command.The author has used the Windows platform in the preparation of this material.When Mathematica starts up,a blank notebook appears on the computer screen entitled Untitled-1and some palettes with buttons may appear alongside.Some examples of palettes are given in Figure0.1.The buttons on the palettes serve essentially as additional keys on the user keyboard.Input to the Mathematica notebook can either be performed by typing in text commands or pointing and clicking on the symbols provided by various palettes and subpalettes.As many of the Mathematica programs in subsequent chapters of this book are necessarily text based,the author has decided to present the material using commands in their text format.However,the use of palettes can save some time in typing,and the reader may wish to experiment with the“clicking on palettes’’approach.Mathematica even allows users to create their own palettes;again readers mightfind this useful.Mathematica notebooks can be used to generate full publication-quality doc-uments.In fact,all of the Mathematica help pages have been created with interac-tive notebooks.The Help menu also includes an online version of the Mathematica book[1].The author recommends a brief tour of some of the help pages to give the reader an idea of how the notebooks can be used.For example,click on the Help toolbar at the top of the Mathematica graphical user interface and scroll down to Help browser....Simply type in Solve and ENTER.An interactive Mathemat-ica notebook will be opened showing the syntax,some related commands,and examples of the Solve command.The interactive notebooks from each chapter of this book can be downloaded from Mathematica’s Information Center:/infocenter/Books/AppliedMathematics/0.1.A Quick Tour of Mathematica3(a)(b)(c)(d)Figure0.1:Some Mathematica palettes:(a)Basic input palette.(b)Technical symbols,shapes,and icons.(c)Relational operators.(d)Relational arrows.The author has provided the reader with a tutorial introduction to Mathematica in Sections0.2,0.3,and0.4.Each tutorial should take no more than one hour to complete.The author highly recommends that new users go through these tutorials line by line;however,readers already familiar with the package will probably use Chapter0as reference material only.Tutorial One provides a basic introduction to the Mathematica package. Thefirst command line shows the reader how to input comments,which are extremely useful when writing long or complicated programs.The reader will type in(*This is a comment*)and then type SHIFT-ENTER or SHIFT-RETURN (hold down the SHIFT key and press ENTER).Mathematica will label thefirst input with In[1]:=(*This is a comment*).Note that no output is given for a comment.The second input line is simple arithmetic.The reader types 2+3-36/2+2ˆ3,and types SHIFT-ENTER to compute the result.Mathematica labels the second input with In[2]:=2+3-36/2+2ˆ3,and labels the corre-sponding output Out[2]=-5.As the reader continues to input new command40.A Tutorial Introduction to Mathematicalines,the input and output numbers change accordingly.This allows users to easily label input and output that may be useful later in the notebook.Note that all of the built-in Mathematica functions begin with capital letters and that the arguments are always enclosed in square brackets.Tutorial Two contains graphic commands and commands used to solve simple differential equations.Tutorial Three pro-vides a simple introduction to the Manipulate command and programming with Mathematica.The tutorials are intended to give the reader a concise and efficient intro-duction to the Mathematica package.Many more commands are listed in other chapters of the book,where the output has been included.Of course,there are many Mathematica textbooks on the market for those who require further appli-cations or more detail.A list of textbooks is given in the reference section of this chapter.0.2Tutorial One:The Basics(One Hour)There is no need to copy the comments,they are there to help you.Click on the Mathematica icon and copy the commands.Hold down the SHIFT key and press ENTER at the end of a line to see the answer or use a semicolon to suppress the output.You can interrupt a calculation at any time by typing ALT-COMMA or COMMAND-COMMA.A working Mathematica notebook of Tutorial One can be downloaded from the Mathematica Information Center,as indicated at the start of the chapter.Mathematica Command Lines CommentsIn[1]:=(*This is a comment*)(*Helps when writingprograms.*)In[2]:=2+3-36/2+2ˆ3(*Simple arithmetic.*)In[3]:=23*7(*Use space or*tomultiply.*)In[4]:=2/3+4/5(*Fraction arithmetic.*)In[5]:=2/3+4/5//N(*Approximate decimal.*)In[6]:=Sqrt[16](*Square root.*)In[7]:=Sin[Pi](*Trigonometric function.*) In[8]:=z1=1+2I;z2=3-4*I;z3=z1-z2/z1(*Complex arithmetic.*)In[9]:=ComplexExpand[Exp[z1]](*Express in form x+iy.*)In[10]:=Factor[xˆ3-yˆ3](*Factorize.*)In[11]:=Expand[%](*Expand the last resultgenerated.*)In[12]:=f=mu x(1-x)/.{mu->4,x->0.2}(*Evaluate f when mu=4andx=0.2.*)In[13]:=Clear[mu,x](*Clear values.*)0.2.Tutorial One:The Basics(One Hour)5In[14]:=Simplify[(xˆ3-yˆ3)/(x-y)](*Simplify an expression.*) In[15]:=Dt[xˆ2-3x+6,x](*Total differentiation.*)In[16]:=D[xˆ3yˆ5,{x,2},{y,3}](*Partial differentiation.*) In[17]:=Integrate[Sin[x]Cos[x],x](*Indefinite integration.*) In[18]:=Integrate[Exp[-xˆ2],{x,0,Infinity}](*Definite integration.*)In[19]:=Sum[1/nˆ2,{n,1,Infinity}](*An infinite sum.*)In[20]:=Solve[xˆ2-5x+6==0,x](*Solving equations.Rootsare in a list.*)In[21]:=Solve[xˆ2-5x+8==0,x](*A quadratic with complexroots.*)In[22]:=Abs[x]/.Out[21](*Find the modulus of theroots(see Out[21]).*)In[23]:=Solve[{xˆ2+yˆ2==1,x+3y==0}](*Solving simultaneousequations.*)In[24]:=Series[Exp[x],{x,0,5}](*Taylor series expansion.*) In[25]:=Limit[x/Sin[x],x->0](*Limits.*)In[26]:=f=Function[x,4x(1-x)](*Define a function.*)In[27]:=f[0.2](*Evaluate f(0.2).*)In[28]:=fofof=Nest[f,x,3](*Calculates f(f(f(x))).*)In[29]:=fnest=NestList[f,x,4](*Generates a list ofcomposite functions.*)In[30]:=fofofof=fnest[[4]](*Extract the4th elementof the list.*)In[31]:=u=Table[2i-1,{i,5}](*List the first5oddnatural numbers.*)In[32]:=%ˆ2(*Square the elements ofthe last result generated.*) In[33]:=a={2,3,4};b={5,6,7};(*Two vectors.*)In[34]:=3a(*Scalar multiplication.*)In[35]:=a.b(*Dot product.*)In[36]:=Cross[a,b](*Cross product.*)In[37]:=Norm[a](*Norm of a vector.*)In[38]:=A={{1,2},{3,4}};B={{5,6},{7,8}};(*Two matrices.*)In[39]:=A.B-B.A(*Matrix arithmetic.*)In[40]:=MatrixPower[A,3](*Powers of a matrix.*)In[41]:=Inverse[A](*The inverse of a matrix.*) In[42]:=Det[B](*The determinant of amatrix.*)60.A Tutorial Introduction to MathematicaIn[43]:=Tr[B](*The trace of a matrix.*) In[44]:=M={{1,2,3},{4,5,6},{7,8,9}}(*A matrix.*)In[45]:=Eigenvalues[M](*The eigenvalues of amatrix.*)In[46]:=Eigenvectors[M](*The eigenvectors of amatrix.*)In[47]:=LaplaceTransform[tˆ3,t,s](*Laplace transform.*)In[48]:=InverseLaplaceTransform[6/sˆ4,s,t](*Inverse Laplacetransform.*)In[49]:=FourierTransform[tˆ4Exp[-tˆ2],t,w](*Fourier transform.*)In[50]:=InverseFourierTransform[%,w,t](*Inverse Fouriertransform.*)In[51]:=Quit[](*Terminates Mathematicakernel session.*)0.3Tutorial Two:Plots and Differential Equations(One Hour)Mathematica has excellent graphical capabilities and many solutions of nonlinear systems are best portrayed graphically.The graphs produced from the input text commands listed below may be found in the Tutorial Two Notebook which can be downloaded from the Mathematica Information Center.Plots in other chapters of the book are referred to in many of the Mathematica programs at the end of each chapter.(*Plotting graphs.*)(*Set up the domain and plot a simple function.*)In[1]:=Plot[Sin[x],{x,-Pi,Pi}](*Plot two curves on one graph.*)In[2]:=Plot[{Cos[x],Exp[-.1x]Cos[x]},{x,0,60}](*Plotting with labels.*)In[3]:=Plot[Exp[-.1t]Sin[t],{t,0,60},AxesLabel->{"t","Current"},PlotRange->{-1,1}](*Contour plot with shading.*)In[4]:=ContourPlot[yˆ2/2-xˆ2/2+xˆ4/4,{x,-2,2},{y,-2,2}](*Contour plot with no shading.*)In[5]:=ContourPlot[yˆ2/2-xˆ2/2+xˆ4/4,{x,-2,2},{y,-2,2},0.3.Tutorial Two:Plots and Differential Equations(One Hour)7ContourShading->False](*Contour plot with20contours.*)In[6]:=ContourPlot[yˆ2/2-xˆ2/2+xˆ4/4,{x,-2,2},{y,-2,2}, Contours->20](*Surface plot.*)In[7]:=Plot3D[yˆ2/2-xˆ2/2+xˆ4/4,{x,-2,2},{y,-2,2}](*A parametric plot.*)In[8]:=ParametricPlot[{tˆ3-4t,tˆ2},{t,-3,3}](*3-D parametric curve.*)In[9]:=ParametricPlot3D[{Sin[t],Cos[t],t/3},{t,-10,10}](*Load the package and plot an implicit curve.*)In[10]:=<<Graphics‘ImplicitPlot‘In[11]:=ImplicitPlot[2xˆ2+3yˆ2==12,{x,-3,3},{y,-3,3}](*Solve a simple separable differential equation.*)In[12]:=DSolve[x’(t)==-x[t]/t,x[t],t](*Solve an initial value problem(IVP).*)In[13]:=DSolve[{x’(t)==-t/x[t],x[0]==1},x[t],t](*Solve a second-order ordinary differential equation (ODE).*)In[14]:=DSolve[{x’’[t]+5x’[t]+6x[t]==10Sin[t],x[0]==0, x’[0]==0},x[t],t](*Solve a system of two ODEs.*)In[15]:=DSolve[{x’[t]==3x[t]+4y[t],y’[t]==-4x[t]+3y[t]}, {x[t],y[t]},t](*Solve a system of three ODEs.*)In[16]:=DSolve[{x’[t]==x[t],y’[t]==y[t],z’[t]==-z[t]}, {x[t],y[t],z[t]},t](*Solve an IVP using numerical methods and plot a solution curve.*)In[17]:=u=NDSolve[{x’[t]==x[t](.1-.01x[t]),x[0]==50}, x,{t,0,100}]In[18]:=Plot[Evaluate[x[t]/.u],{t,0,100},PlotRange->All](*Plot a phase plane portrait.*)In[19]:=v=NDSolve[{x’[t]==.1x[t]+y[t],y’[t]==-x[t]+.1y[t], x[0]==.01,y[0]==0},{x[t],y[t]},{t,0,50}]80.A Tutorial Introduction to MathematicaIn[20]:=ParamericPlot[{x[t],y[t]}/.v,{t,0,50},PlotRange->All,PlotPoints->1000](*Plot a three-dimensional phase portrait.*)In[21]:=w=NDSolve[{x’[t]==z[t]-x[t],y’[t]==-y[t],z’[t] ==z[t]-17x[t]+16,x[0]==.8,y[0]==.8,z[0]==.8},{x[t],y[t],z[t]},{t,0,20}]In[22]:=ParametricPlot3D[Evaluate[{x[t],y[t],z[t]}/.w], {t,0,20},PlotPoints->1000,PlotRange->All](*A stiff van der Pol system of ODEs.*)In[23]:=Needs["DifferentialEquations‘InterpolatingFunctionAnatomy‘"];In[24]:=vanderpol=NDSolve[{Derivative[1][x][t]==y[t],Derivative[1][y][t]==1000*(1-x[t]ˆ2)*y[t]-x[t],x[0]==2,y[0]==0},{x,y},{t,5000}];In[25]:=T=First[InterpolatingFunctionCoordinates[First[x/.vanderpol]]];In[26]:=ListPlot[Transpose[{x[T],y[T]}/.First[vanderpol]], PlotRange->All]0.4The Manipulate Command and SimpleMathematica ProgramsSections0.1,0.2,and0.3illustrate the interactive nature of Mathematica.More involved tasks will require more code.Note that Mathematica is very different from procedural languages such as C,Pascal,or Fortran.An afternoon spent browsing through the pages listed at the Mathematica Information Center will convince readers of this fact.The Manipulate command is new in Version6.0and is very useful in the field of dynamical systems.Manipulate[expr,{u,u min,u max}]generates a version of expr with controls added to allow interactive manipulation of the value of u.The Manipulate CommandOn execution of the Manipulate command a parameter slider appears in the note-book.Solutions change as the slider is moved left and right.(*Example1:Solving simultaneous equations as the parameter a varies.See Exercise6in Chapter 3.*)In[1]:=Manipulate[Solve[{x(1-y-a x)==0,y(-1+x-a y)==0}], {a,0,1}](*Showing the solution lying wholly in the first quadrant.*) In[2]:=Manipulate[Plot[{1-a x,(x-1)/a},{x,0,2}],{a,0.01,1}]0.4.The Manipulate Command and Simple Mathematica Programs 9(*Example 2:Evaluating functions of functions to the fifth iteration.*)In[3]:=f=Function[x,4x (1-x)];In[4]:=Manipulate[Expand[Nest[f,x,d]],{d,1,5,1}](*Stepsof 1.*)(*Example 3:Solving a differential equation as twoparameters vary.In this case,the damping and restoring terms when modeling a simple pendulum.*)In[5]:=Manipulate[DSolve[{x’’[t]+b x’[t]+c x[t]==0,x[0]==1,x’[0]==0},x[t],t],{b,0,2},{c,0,5}](*The solution curves.*)In[6]:=Manipulate[soln=NDSolve[{x’’[t]+b x’[t]+c x[t]==0,x[0]==1,x’[0]==0},x[t],{t,0,100}];Plot[Evaluate[x[t]/.soln],{t,0,100},PlotRange->All],{b,0,5},{c,0,5}]Many Manipulate demonstrations are available from the Wolfram Demon-strations Project:/Simple Mathematica ProgramsEach Mathematica program is displayed between horizontal lines and kept short to aid in understanding;the output is also included.Modules and local variables.Aglobal variable t is unaffected by the local variable t used in a module.In[1]:=Norm3d[a_,b_,c_]=Module[{t},t=Sqrt[aˆ2+bˆ2+cˆ2]]Out [1]= a 2+b 2+c 2In[2]:=Norm3d[3,4,5]Out [2]=5√2The Do command.The first ten terms of the Fibonacci sequence.In[3]:=F[1]=1;F[2]=1;Nmax=10;In[4]:=Do[F[i]=F[i-1]+F[i-2],{i,3,Nmax}]In[5]:=Table[F[i],{i,1,Nmax}]Out [5]={1,1,2,3,5,8,13,21,34,55}100.A Tutorial Introduction to MathematicaIf,then,else construct.In[6]:=Num=1000;If[Num>0,Print["Num is positive"],If[Num==0, Print["Num is zero"],Print["Num is negative"]]]Out[6]=Num is positiveConditional statements with more than two alternatives.In[7]:=r[x_]=Switch[Mod[x,3],0,a,1,b,2,c]Out[7]=Switch[Mod[x,3],0,a,1,b,2,c]In[8]:=r[7]Out[8]=bWhich.Defining the tent function.In[9]:=T[x_]=Which[0<=x<1/2,mu x,1/2<=x<=1,mu(1-x)]Out[9]=Which[0≤x<1/2,mu x,1/2≤x≤1,mu(1−x)]In[10]:=T[4/5]Out[10]=mu5For pute f(x),f(f(x)),and f(f(f(x))).In[11]:=For[i=1;t=x,i<4,i++,t=mu t(1-t);Print[Factor[t]]] Out[11]=−mu(−1+x)x−mu2(−1+x)x(1−mu x+mu x2)−mu3(−1+x)x(1−mu x+mu x2)(1−mu2x+mu2x2+mu3x2−2mu3x3+mu3x4)Plotting solution curves.Solutions to the pendulum problem.See Figure0.2. In[12]:=ode1[x0_,y0_]:=NDSolve[{x’[t]==y[t],y’[t]==-25x[t], x[0]==x0,y[0]==y0},{x[t],y[t]},{t,0,6}];In[13]:=sol1[1]=ode1[1,0];In[14]:=ode2[x0_,y0_]:=NDSolve[{x’[t]==y[t],y’[t]==-2y[t]-25x[t],x[0]==x0,y[0]==y0},{x[t],y[t]},{t,0,6}];In[15]:=sol2[1]=ode2[1,0];In[16]:=p1=Plot[Evaluate[Table[{x[t]}/.sol1[i],{i,1}]], {t,0,6},PlotRange->All,PlotPoints->100,PlotStyle->Dashing[{.02}]];0.5.Hints for Programming 11123456t10.50.51xFigure 0.2:Harmonic and damped motion of a pendulum.In[17]:=p2=Plot[Evaluate[Table[{x[t]}/.sol2[i],{i,1}]],{t,0,6},PlotRange->All,PlotPoints->100];In[18]:=Show[{p1,p2},PlotRange->All,AxesLabel->{"t","x"},Axes->True,TextStyle->{FontSize->15}]0.5Hints for ProgrammingThe Mathematica language contains very powerful commands,which means that some complex programs may contain only a few lines of code.Of course,the only way to learn programming is to sit down and try it yourself.This section has been included to point out common errors and give advice on how to troubleshoot.Remember to check the help and index pages in Mathematica and the Web if the following does not help you with your particular problem.Common typing errors.The author strongly advises new users to type Tutorials One,Two,and Three into their own notebooks.This should reduce typing errors.•Type SHIFT-ENTER at the end of every command line.•If a command line is ended with a semicolon,the output will not be displayed.•Make sure brackets,parentheses,etc.,match up in correct pairs.•Remember that all of the built-in Mathematica functions begin with capital letters and that the arguments are always enclosed in square brackets.•Remember Mathematica is case sensitive.•Check the syntax;type ?Solve to list syntax for the Solve command,for example.120.A Tutorial Introduction to MathematicaProgramming tips.The reader should use the Mathematica programs listed in Section 0.4to practice simple programming techniques.•It is best to clear values at the start of a large program.•Use comments throughout a program.You will find them extremely useful in the future.•Use Modules or Blocks to localize variables.This is especially useful for very large programs.•If a program involves a large number of iterations,for example,50,000,then run it for three iterations first and list all output.•If the computer is not responding hold ALT-COMMA or COMMAND-COMMA and try reducing the size of the problem.•Read the error message printed by Mathematica and click on More…if necessary.•Find a similar Mathematica program in a book or on the Web,and edit it to meet your needs.•Check which version of Mathematica you are using.The syntax of some commands may have altered.0.6Mathematica Exercises1.Evaluate the following:(a)4+5−6;(b)312;(c)sin (0.1π);(d)(2−(3−4(3+7(1−(2(3−5))))));(e)25−34×23.2.Given thatA =⎛⎝12−10103−12⎞⎠,B =⎛⎝123112012⎞⎠,C =⎛⎝21101−1422⎞⎠,determine the following:(a)A +4BC ;(b)the inverse of each matrix if it exists;0.6.Mathematica Exercises 13(c)A 3;(d)the determinant of C ;(e)the eigenvalues and eigenvectors of B .3.Given that z 1=1+i ,z 2=−2+i ,and z 3=−i ,evaluate the following:(a)z 1+z 2−z 3;(b)z 1z 2z 3;(c)e z 1;(d)ln (z 1);(e)sin (z 3).4.Evaluate the following limits if they exist:(a)lim x →0sin x x ;(b)lim x →∞x 3+3x 2−52x 3−7x;(c)lim x →πcos x +1x −π;(d)lim x →0+1x;(e)lim x →02sinh x −2sin xcosh x −1.5.Find the derivatives of the following functions:(a)y =3x 3+2x 2−5;(b)y =√1+x 4;(c)y =e x sin x cos x ;(d)y =tanh x ;(e)y =x ln x .6.Evaluate the following definite integrals:(a) 1x =03x 3+2x 2−5dx ;(b) ∞x =11x 2dx ;(c) ∞−∞e −x 2dx ;(d) 101√xdx ;(e)2πsin (1/t)t 2dt .7.Graph the following:140.A Tutorial Introduction to Mathematica(a)y=3x3+2x2−5;(b)y=e−x2,for−5≤x≤5;(c)x2−2xy−y2=1;(d)z=4x2e y−2x4−e4y for−3≤x≤3and−1≤y≤1;(e)x=t2−3t,y=t3−9t for−4≤t≤4.8.Solve the following differential equations:(a)dydx =x2y,given that y(1)=1;(b)dydx =−yx,given that y(2)=3;(c)dydx =x2y3,given that y(0)=1;(d)d2xdt2+5dxdt+6x=0,given that x(0)=1and˙x(0)=0;(e)d2xdt2+5dxdt+6x=sin(t),given that x(0)=1and˙x(0)=0.9.Carry out100iterations on the recurrence relationx n+1=4x n(1−x n),given that(a)x0=0.2and(b)x0=0.2001.List thefinal10iterates in each case.10.Type?While to read the help page on the While e a whileloop to program Euclid’s algorithm forfinding the greatest common divisor of two e your program tofind the greatest common divisor of 12,348and14,238.Recommended Textbooks[1]S.Wolfram,The Mathematica Book,6th ed.(electronic),Wolfram Media,Champaign,IL,2007;included with Mathematica®Version6.0.[2]D.McMahon and D.M.Topa,A Beginner’s Guide to Mathematica,Chapmanand Hall,London,CA,2006.[3]G.Baumann,Mathematica for Theoretical Physics:Classical Mechanicsand Nonlinear Dynamics,Springer-Verlag,New York,2005.[4]G.Baumann,Mathematica for Theoretical Physics:Electrodynamics,Quan-tum Mechanics,General Relativity,and Fractals,Springer-Verlag,New York,2005.[5]M.Trott,The Mathematica Guidebook for Numerics,Springer-Verlag,NewYork,2005.Recommended Textbooks15 [6]M.Trott,The Mathematica Guidebook for Symbolics,Springer-Verlag,NewYork,2005.[7]M.Trott,The Mathematica Guidebook:Graphics,Springer-Verlag,NewYork,2004.[8]M.Trott,The Mathematica Guidebook:Programming,Springer-Verlag,New York,2004.[9]E.Don,Schaum’s Outline of Mathematica,McGraw–Hill,New York,2000.。
最新版的Mathematica 9.0三个种子中的Mathematica 9的安装文件都是来自Wolfram官网,填入算号器算出来的Activation Key和Password之后就是正式版了。
请注意:这个算号器(for_windows和for_Linux这2个种子中那个)是针对Mathematica 8的,且是个Windows程序(必须在Windows中算号),但是其算出来的Activation Key和Password在三大平台中的Mathematica 9中也能正确注册。
在for_mac的种子中还有一个算号器(Mathematica 7-8-9 keygen.exe.zip)其实是个Mathematica 7的算号器,我使用了之后无用,请忽略。
其他两个种子中带的那个算号器(Mathematica_8_kg.exe)是可以用的,如果算出来的号不能用,请多算几次!目前网上还没有能一次性算出正确的号的算号器!算号及激活方法(以Windows平台为例):1、安装并运行对应平台的Mathematica 9,启动后会提示激活产品2、点“Other ways to activate”,并点“Manual Activation”3、右键“MathID"后面的数字,并选择”Copy“复制下来备用4、运行Mathematica_8_kg.exe(如果你不下载Windows和Linux版本,请单独下载附件中的算号器,因为for mac种子里面的那个算号器不能用),在第一行粘贴刚才复制的MathID,然后下面的”Computer Name“等等随便填,最后点”Save mathpass“,并点击成功生成提示框的”确定“按钮5、复制算出来的”Activation Key“和”Password“,粘贴到Mathematica 9产品激活窗口中对应的框中,并点击”activate“按钮完成注册6、如果成功注册,则会进入Mathematica 9的界面(屏幕上方的标题栏和菜单栏以及屏幕中间的Welcome Screen)7、如果出现以下窗口,则说明算出来的号无效,需要重新在算号器中点”Save mathpass“来再算一次,(我算了5次才算了一对能用的号。
Mathematica 9.0简明教程2015年10月10日目录0.Mathematica启动与帮助 (2)1. Mathematica基本使用 (3)2. Mathematica的基本语法特征 (3)3. Mathematica 中的数据类型和数学常数 (4)4. Mathematica数的运算符 (4)5. Mathematica 中的精确数与近似数 (4)6. Mathematica中的表 (5)建表命令: (5)分量命令: (6)运算命令 (6)7. Mathematica中的变量 (7)(1) Mathematica的变量命名 (7)(2) Mathematica中的变量取值与清除 (7)(3) Mathematica中有关变量的注意事项 (8)8. Mathematica中的函数 (9)(1).的Mathematica内部函数 (9)(2).Mathematica中的自定义函数 (10)(3).Mathematica中的函数求值 (11)9. Mathematica中的表达式 (11)(1).Mathematica中的算术表达式 (12)(2).Mathematica中的关系表达式 (12)(3).Mathematica中的逻辑表达式 (12)(4).Mathematica中的复合表达式 (13)10.Mathematica 中的一些符号和语句 (13)(1).Mathematica中的专用符 (13)(2).Mathematica中的屏幕输出语句 (14)11. 绘图 (15)(一).Mathematica绘图命令有如下一些常用形式: (15)(二).绘图命令中的选择项参数的形式为: (18)Mathematica自1988年由美国的Wolfram Research公司首次推出,是一个功能强大的常用数学软件, 不但可以解决数学中的数值计算问题, 还可以解决符号演算问题, 并且能够方便地绘出各种函数图形。
0.Mathematica启动与帮助假设在Windows环境下已安装好中文Mathematica9.0,在“开始”菜单的“程序”中单击,就启动了Mathematica9.0,默认为是新建“笔记本”。
这与[文件]-[新建]菜单是一样的。
笔记本,幻灯片,项目,后缀都是.nb,可以理解为不同场合设计的模板。
任何时候都可以通过按F1键或点击帮助菜单项“参考资料中心”,调出帮助菜单,如图所示,函数浏览器和虚拟全书可理解为两个搜索引擎,帮助查找所需内容。
该文档全面整合的文件中心容纳几千个详细举例、动画、辅导课程和其它资料。
这些都被翻译成中文,帮助您使用Mathematica。
1. Mathematica基本使用(1)在工作区(软件打开初始时,左侧的窗口,上方有untitled-1*)输入命令,按Shift+Enter组合键执行命令;如输入“1+1”,按Shift+Enter执行后,窗口显示In[1]:= 1 + 1Out[1]= 2其中“In[1]:=,Out[1]=”为系统自动添加(不必管),In[1]括号内数字1表示第1次输入。
如果不想显示此次输入的结果,只要在所输入命令的后面再加上一个分号便可。
(2)可以打开“助手面板”,方便命令输入,如级数,积分,数学符号等。
(3)在Mathematica系统中定义了许多功能强大的函数,我们称之为内建函数(built-in function), 直接调用这些函数可以取到事半功倍的效果。
这些函数分为两类,一类是数学意义上的函数,如:绝对值函数Abs[x],正弦函数Sin[x],余弦函数Cos[x],以e为底的对数函数Log[x],以a为底的对数函数Log[a,x]等;第二类是命令意义上的函数,如作函数图形的函数Plot[f[x],{x,xmin,xmax}],解方程函数Solve[eqn,x],求导函数D[f[x],x]等。
在Mathematica中,函数名和自变量之间的分隔符是用方括号“[ ]”,而不是一般数学书上用的圆括号“()”,初学者很容易犯这类错误。
2. Mathematica的基本语法特征(1)Mathematica中区分大、小写,如Name、name、NAME等是不同的变量名或函数名。
(2)系统所提供的功能大部分以系统函数的形式给出,内部函数一般写全称,而且一定是以大写英文字母开头,如Sin[2]等。
(3)乘法即可以用*,又可以用空格表示,如2 3=2*3=6 ,x y,2 Sin[x]等;乘幂可以用“^”表示,如x^0.5,Tan[x]^y。
(4)自定义的变量可以取几乎任意的名称,长度不限,但不可以数字开头。
(5)当赋予变量任何一个值,除非明显地改变该值或使用Clear[变量名]或“变量名=.”取消该值为止,否则它将始终保持原值不变。
(6)一定要注意四种括号的用法:()圆括号表示运算项的结合顺序,如(x+(y^x+1/(2x)));[]方括号表示函数,如Log[x], BesselJ[x,1];{}大括号表示一个“表”(一组数字、任意表达式、函数等的集合),如{2x,Sin[12 Pi],{1+A,y*x}};[[]]双方括号表示“表”或“表达式”的下标,如a[[2,3]]、{1,2,3}[[1]]=1。
(7)Mathematica的语句书写十分方便,一个语句可以分为多行写,同一行可以写多个语句(但要以分号间隔)。
当语句以分号结束时,语句计算后不做输出(输出语句除外),否则将输出计算的结果。
3. Mathematica 中的数据类型和数学常数Mathematica提供的简单数据类型有整数、有理数、实数和复数4种类型,这些数据在Mathematica中有如下的要求:(1)整数描述为Integer,是可以具有任意长度的精确数。
书写方法同于我们通常的表示,输入时,构成整数的各数字之间不能有空格、逗号和其它符号,整数的正负号写在该数的首位,正号可以不输入。
如:2367189、-932是正确的整数。
(2)有理数描述为Rationa l,用化简过的分数表示,但其中分子和分母都应该是整数,有理数是精确数,输入时分号用“ / ”代替,即使用“分子/分母”的形式。
如:23/45、- 41/345 是正确的有理数。
(3)实数描述为Real,是除了整数和有理数之外的所有实数。
与一般高级语言不同的是这里数学中的无理数是可以有任意精确度的近似数, 如圆周率π, 在Mathematica中它可以根据需要取任意位有效数字。
(4)复数描述为Complex,用是否含有虚数单位I来区分,它的实部和虚部可以是整数、有理数和实数。
如:3+4.3I、18.5I都是正确的复数。
为了方便数学处理和计算更准确,Mathematica定义了一些数学常数,它们用英文字符串表示,常用的有:Pi 表示圆周率π=3.14159…E 表示自然数e =2.71828…Degree 表示几何的角度1︒或π /180 ,30Degree表示30︒.I 表示虚数单位-1开平方IInfinity 表示数学中的无穷大∞(正无穷)注意:数学常数是精确数,可以直接用于输入的公式中,作为精确数参与计算和公式推导。
这些常数可以从符号面板选择输入。
4. Mathematica数的运算符数的运算有:加、减、乘、除和乘方,它们在Mathematica中的符号为:加(+)、减(-)、乘(*)、除(/)和乘方(^)。
不同类型的数参与运算,其结果的类型为:●如果运算数有复数,则计算结果为复数类型;●如果运算数没有复数,但有实数,则计算结果为实数类型●如果运算数没有复数和实数,但有分数,则计算结果为有理数类型●如果运算数只有整数,则计算结果或是整数类型(如果计算结果是整数);或是有理数类型(如果计算结果不是整数)。
5. Mathematica 中的精确数与近似数(1)Mathematica的近似数是带有小数点的数;精确数是整数、有理数、数学常数以及函数在自变量取整数、有理数、数学常数时的函数值。
如: 62243、2/3、E、Sin[4]都是精确数。
如果参与运算或求值的数带有小数点,则运算结果通常为带有6位有效数字的近似数,如:In[3]: = 1.2345678020/30Out[3]=0.0411523 结果为近似数In[4]: = 2+Sin[1.0]Out[4]= 2.84147 结果为近似数In[5]: = 2+Sin[1]Out[5]= 2 + Sin[1] 结果为精确数(2)如果需要精确数的数值结果(除了整数之外),可以用Mathematica提供的N函数将其转化,N函数可以得到该精确数的任意精度的近似结果:例如:In[6]: = 2*E+Sin[ Pi/5 ] // NOut[6]= 6.02345 (输入2*E+Sin[ Pi/5 ]试试)In[7]:= N[ 2*E+Sin[Pi/5] , 30 ]Out[7]= 6.02434890921056359988928089734Input=N[Pi,20]output=3.141592653589793238462643383286. Mathematica中的表表可以用来表示数学中的集合、向量、矩阵和数据库中的记录。
在Mathematica中,任何用一对花括号括起来的一组元素都代一个表,其中的元素用逗号分隔且各元素可以具有不同的类型,特别其中的元素还可以是一个表。
表的形式:{ 元素1,元素2,元素3,……,元素n },如:{1,3,5}、{3,x,{1,y},4}都是表建表命令:(1)命令形式1: Table[f(i),{i ,imin,imax,h}],其中h>0功能:产生一个表{ f(imin) ,f(imin +h),f(imin +2h),…,f(imin +nh)}例如:In[8]: = Table[ i^2 , { i , 1, 19 , 2} ]Out[8]= {1, 9, 25, 49, 81, 121, 169, 225, 289, 361}(2)命令形式2: Table[ 通项公式f(i),{i ,imin,imax}],相当于h=1功能:产生一个表{ f(imin) ,f(imin +1),f(imin +2),…,f(imin +n)}命令:In[9]: = Table[i^2, {i, 2 , 10}]Out[9]={ 4, 9, 16, 25, 36, 49, 64, 81, 100}(3)命令形式3: Table[ 通项公式f,{循环次数n}], f为常数功能:产生n个f的一个表{ f ,f,f,……,f }例如:建立产生8个2一个表{2,2,2,2,2,2,2,2}命令:In[10]: = Table[2, {8}]Out[10]= {2,2,2,2,2,2,2,2}(4)命令形式4: Table[ 通项公式f(i , j),{{i ,imin,imax},{j ,jmin,jmax}] 功能:产生一个二维表{ {f(imin, jmin) ,f(imin, jmin +1),f(imin, jmin +2),……,f(imin, jmin +m)}, {f(imin+1, jmin) ,f(imin+1, jmin +1), f(imin+1, jmin +2), ……, f(imin+1 , jmin +m)}, ……{f(imin+n, jmin) ,f(imin+n, jmin +1),f(imin+n, jmin +2),……,f(imin +n, jmin +m)}例如:In[11]: = Table[i-j, {i, 1 , 6}, {j, 1 , 2}]Out[11]= {{0, -1}, {1, 0}, {2, 1}, {3, 2}, {4, 3}, {5, 4}}分量命令:表的分量表示:有时为了需要,希望取出表中的某一或某些元素参与后面的运算和处理。