Mathematica求不定积分与函数作图
写文章
分享兴趣、传播快乐、增长见闻、留下美好,大家好,这里是LearningYard学苑,今天小编为大家带来文章:用mathematica求不定积分与mathematica函数作图教程。
Share your interests, spread happiness, increase your knowledge, and stay good. Hello, everyone. This is LearningYard Academy. Today, the editor brings you an article: Using mathematica to find indefinite integrals and mathematica function mapping tutorial
主题一:用mathematica求不定积分
Topic 1: Using mathematica to find indefinite integral
方法一:使用命令:Integrate[f,x] (*其中为积分变量*)
Method 1: Use the command: Integrate[f,x] (*where is the integral variable*)
方法二:直接用工具栏输入不定积分
Method 2: Use the toolbar to input the indefinite integral directly
案例展示Case show:
计算不定积分Calculate indefinite integral
答案Answer:
或者
小贴士:
① Integrate命令在处理积分运算时会做两个假设。第一个假设即Mathematica假设除了积分变量之外其它符号都被作为常数处理。
② 第二个假设是Mathematica求得的积分结果是一个通式(generic form),积分结果可能在某些点不成立,这时Mathematica会告诉你
的标准结果,并且假设这一结果在哪些点不成立,如
// 假设n¹-1.
③ 积分变量不一定是单个的符号变量,也可以是一个函数如sin x
④ 如果无法积分,Mathematica会保留积分的原式,若原式中含有常数系数,Mathematica会把常数系数提到积分之外,保留积不出来的表达式,如
Tips:
① The Integrate command makes two assumptions when processing integral operations. The first assumption is that Mathematica assumes that all symbols except the integral variable are treated as constants.
② The second hypothesis is that the integral result obtained by Mathematica is a generic form, and the integral result may not be valid at some points. At this time, Mathematica will tell you the standard result and assume that the result is not valid at which points.
③ The integral variable is not necessarily a single symbolic variable, but can also be a function such as sin x.
④ If integration is not possible, Mathematica will retain the original integral formula. If the original formula contains constant coefficients, Mathematica will add the constant coefficients outside the integral and retain the expressions that cannot be integrated.
主题二:用Mathematica作函数图
Topic 2: Use Mathematica to make function graphs
- 二维作图原理Principle of two-dimensional drawing
计算机在画函数图形时所用的基本方法类似于描点法。机器首先对所给的区间里的一定数量的点 (通常取区间的均分点)计算函数值,并画出这些点(x,f(x)),然后依x的大小从小到大所对应的点用直线段连接成一条直线(实际上是一条折线),就把它作为函数在观察区内的图形
The basic method used by the computer to draw function graphs is similar to the dot method. The machine first calculates the value of the function for a certain number of points in the given interval (usually the average point of the interval), and draws these points (x, f(x)), and then corresponds to the size of x from small to large Use straight line segments to connect the points into a straight line (actually a polyline), and use it as a function of the graph in the observation area.
- 基本绘图命令PlotBasic drawing commands Plot
Plot命令表达式中的可选项是对画图的细节提出的各种要求和设置,每个选项都有一个确定的名字和选项值以“选项名®选项值”的形式放在Plot命令的最后位置,一次可设置多个选项,以逗号相隔依次排列。
The options in the Plot command expression are various requirements and settings for the details of drawing. Each option has a certain name and option value in the form of 'option name option value' in the last position of the Plot command. Multiple options can be set at one time, arranged in order with commas separated.
可选项 |
说明 |
PlotRange |
指定作图范围。默认值是Automatic。可用{y1,y2}的形式要求绘出坐标在[y1,y2]内的图形。 |
SpectRation |
图形的高度与宽度的比例,默认值是黄金分割值0.618.如果要图形按实际情况显示,则需要设置为Automatic。 |
Axes |
是否画出坐标轴以及设置坐标轴的原点位置。默认值是True.表示画出坐标轴;如果设置Axes®None,表示不画坐标轴;如果设置Axes®{x0,y0}则设置坐标原点为[x0,y0]。 |
AxesLabel |
设置坐标轴上的标记符号,默认值为None.表示不作标记。用AxesLabel[字符串1,字符串2]的形式定义轴的纵坐标和横坐标标记。 |
Ticks |
设置坐标轴上刻度的位置,默认值是Automatic,表示由系统自动定位。用Ticks®None表示不标坐标刻度;Ticks®{xi,yi}规定x轴和y轴的刻度值;Ticks®{t1,t2,……}表示要在一个轴上按t1,t2,……设置刻度。 |
PlotPoints |
设置采样函数的点数,默认值是15。对于函数值变化剧烈的表达式,应设定较大的点数。 |
PlotStyle |
指定曲线的样式,默认值为Automatic,取默认值时,图形为黑实线。可通过可选项改变曲线的样式。 |
DisplayFunction |
用什么机制显示图形。默认值是$ DisplayFunction,可用Identity表示只生成图形,但是现在不显示。 |
案例展示Case show:
将函数
和y=sin x的图像展示在一张纸上Display the image of the function and y=sin x on a piece of paper.
答案Answer:
Out[3]=-Graphics-
小贴士:
如果用Plot函数画两个或多个函数的图形,可以用PlotStyle为每条曲线设定一个不同方式 ,这时必须把描述一条曲线的项放在一个表里作为PlotStyle值的一个子表。
Tips:
If you use the Plot function to draw graphs of two or more functions, you can use PlotStyle to set a different method for each curve. At this time, you must put the item describing a curve in a table as a sub-table of the PlotStyle value.
案例展示Case show:
分别用红、绿、蓝三种颜色画出
的图形Graphics drawn in three colors of red, green and blue.
In[7]:=Plot[{Sin[x],Sin[2x],Sin[3x]},{x,0,2Pi},PlotStyle®{RGBColor[1,0,0],
RGBColor[0,1,0],RGBColor[0,0,1]}]
Out[7]=-Graphics-
- 二维参数图Two-dimensional parameter diagram
在二维平面内,有时无法将隐函数f(x,y)=0化成y=f(x)显函数的形式,所以无法使用Plot命令直接绘图。但是在某些情况下,可以把平面上的曲线f(x,y)=0化成:x=x(t),y=y(t)的形式,其中变量t为方程式的参数(Parameter),而这个方程式则被称为参数方程(Parametric equation)。随着t的变化,我们可以在x,y平面上描绘出曲线的轨迹,所得的曲线称为参数图。Mathematica用ParametricPlot命令绘制二维参数图。它的使用形式有两种:
(1) ParametricPlot[{x(t),y(t)},{t,下限,上限},可选项] 绘制二维参数图;
(2) ParametricPlot[{{x1(t),y1(t)},{x2(t),y2(t)},…},{t,下限,上限}] 同时绘制多个参数图。
ParametricPlot接受与Plot一样的可选项,其作用也一样,但是PlotPoints选项的默认值为25。
In the two-dimensional plane, sometimes it is impossible to convert the implicit function f(x,y)=0 into the form of y=f(x) explicit function, so the Plot command cannot be used to draw directly. However, in some cases, the curve f(x,y)=0 on the plane can be transformed into the form: x=x(t), y=y(t), where the variable t is the parameter of the equation, And this equation is called a parametric equation (Parametric equation). With the change of t, we can draw the trajectory of the curve on the x and y planes, and the resulting curve is called a parametric diagram. Mathematica uses the ParametricPlot command to draw a two-dimensional parameter map. It can be used in two forms:
(1) ParametricPlot[{x(t), y(t)}, {t, lower limit, upper limit}, optional] draw a two-dimensional parameter graph;
(2) ParametricPlot[{{x1(t),y1(t)},{x2(t),y2(t)},…},{t, lower limit, upper limit}] Draw multiple parameter graphs at the same time.
ParametricPlot accepts the same options as Plot, and its effect is the same, but the default value of the PlotPoints option is 25.
案例展示Case show:
利用ParametricPlot命令画单位圆
(0≤t≤2pi)的图形
Use the ParametricPlot command to draw the graph of the unit circle (0≤t≤2pi)
答案Answer:
In[1]:=ParametricPlot[{Sin[t],Cos[t]},{t,0,2Pi},AspectRatio®Automatic]
Out[1]= -Graphics-
- 极坐标作图Polar coordinate mapping
Mathematica没有直接提供极坐标的绘图命令,我们只要把ParametricPlot稍做修改,就可以定义成极坐标的绘图命令。极坐标方程式可以写成
的形式,而极坐标上的点在x—y直角坐标系统上的坐标,根据几何关系可以写成
因此,如果把ParametricPlot[{x,y},{t,下限,上限}]命令中的x和y改成
则参数方程式的图形即为极坐标方程式的图形。现在我们定义PolarPlot极坐标绘图命令:
(1)PolarPlot[r_,{t_,下限,上限},可选项]
(2)ParametricPlot[{r*Cos[t],r*Sin[t]},{t,下限,上限},可选项]
Mathematica does not directly provide polar coordinate drawing commands. We only need to modify ParametricPlot to define it as polar coordinate drawing commands. The polar coordinate equation can be written in the form:
,and the coordinates of the point on the polar coordinate in the x-y rectangular coordinate system can be written as
Therefore, if you change the x and y as
in the ParametricPlot[{x,y},{t, lower limit, upper limit}] command, the graph of the parametric equation is the graph of the polar coordinate equation.
Now we define PolarPlot polar coordinate drawing command:
(1) PolarPlot[r_,{t_, lower limit, upper limit}, optional]
(2) ParametricPlot[{r*Cos[t], r*Sin[t]}, {t, lower limit, upper limit}, optional]
- 平面数据作图Plane data mapping
Mathematica可以根据一组数据作出图形,使用的函数形式是——ListPlot[数据,可选项]
Mathematica can make graphs based on a set of data, and the function form used is
ListPlot[data, optional]
可选项 |
说明 |
PlotJoined |
是否用直线连接各点。默认值为False,可用True表示得到连接这些点的折线。 |
PlotStyle |
所画的点或直线的类型,默认值为Automatic。 |
案例展示Case show::
画数列
的前100项的散点图
Draw a scatter plot of the first 100 items of
答案Answer:In[2]:=t=Table=[(1+1/n)^n,{n,1,100}]; ListPlot[t]
Out[2]=-Graphics-
- 图形的重新显示、组合和输出Redisplay, combination and output of graphics
案例展示:将y=x^2和y=x的图形重新组合显示在图上
Case show: recombining the graphs of y=x^2 and y=x to display on the graph
答案Answer: In[3]:=f1=Plot[x^2,{x,-2,2}];
f2=Plot[x,{x,-2,2}];
Show[f1,f2,PlotRange®{-2,2},AspectRatio®Automatic,AxesLabel®{“x”,”y”}]
Out[3]=-Graphics-
参考资料:网络
翻译:Google翻译