9.符号代数.ppt_第1页
9.符号代数.ppt_第2页
9.符号代数.ppt_第3页
9.符号代数.ppt_第4页
9.符号代数.ppt_第5页
已阅读5页,还剩93页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、符号代数,Symbolic Manipulation,Matlab符号运算是通过集成在Matlab中的符号数学工具箱(Symbolic Math Toolbox)来实现的。 和别的工具箱有所不同,该工具箱不是基于矩阵的数值分析,而是使用字符串来进行符号分析与运算。 实际上,Matlab中的符号数学工具箱是建立在Maple基础上的,当进行Matlab符号运算时,它就请求Maple软件去计算并将结果返回给Matlab。 Matlab的符号数学工具箱可以完成几乎所有得符号运算功能。这些功能主要包括:符号表达式的运算,符号表达式的复合、化简,符号矩阵的运算,符号微积分、符号函数画图,符号代数方程求解,

2、符号微分方程求解等。此外,工具箱还支持可变精度运算,既支持符号运算并以指定的精度返回结果。,Capabilities,Manipulate symbolic expressions to Simplify Solve symbolically Evaluate numerically Take derivatives Integrate Perform linear algebraic manipulations More advanced features include LaPlace transforms Fourier transforms Variable precision ari

3、thmetic,Notebook Environment,Symbolic Algebra,用符号代数的方法可以求解数学方程式。 初看起来,y是一个关于x的复杂函数。 细看,该方程可以化简。,Consider this equation,This looks like a fairly complicated function of x,If you expand it, it simplifies dramatically,However, when you simplify you may lose information(信息丢失),When x is equal to -3, the

4、equation is undefined(无意义),Let x equal -3,You can choose,MATLABs symbolic capability allows you perform the simplification, or to manipulate the numerator(分子 ) and denominator(分母 ) separately,Relationships are not always easy to solve,If we know k0 Q R T Its easy to solve for k Its not easy to solve

5、 for T!,MATLABs symbolic capability makes it easy to solve this problem,Creating Symbolic Variables(创建符号变量),Two approaches Use the sym command to create Single variable Expression Equation Use the syms command to create Single variables Compose expressions and equations from the variables youve defi

6、ned,Heres an example,Define x as a symbolic variable x=sym(x) or syms x Use x to create a more complicated expression y = 2*(x+3)2/(x2+6*x+9),x and y are both symbolic variables,The syms command can create multiple variables (可以同时创建多个符号变量),syms Q R T k0 Use these variables to create another symbolic

7、 variables k=k0*exp(-Q/(R*T),Notice that we used standard algebraic operators the array operators (.* , ./ and .) are not used in symbolic algebra,Create an entire expression with the sym command,E=sym(m*c2) Since m and c have not been specifically defined as symbolic variables, they are not stored(

8、m,c不会在工作区窗口出现) E was set equal to a character string, defined by the single quotes inside the function.(变量E被设置为字符串,函数内部要用单引号括起来),Workspace,Equations vs Expressions,We can create an entire equation, and give it a name ideal_gas_law=sym(P*V=n*R*Temp) 方程:一个表达式等于一个值或另一个表达式 表达式:数学运算符号的集合 表达式不同于方程,Workspa

9、ce,Reserved Variable Names,One idiosyncrasy of the implementation of MuPad inside MATLAB is that a number of commonly used variables are reserved. They can be overwritten, however it you try to use them inside expressions or equations you may run into problems.,D, E, I, O, beta, zeta, theta, psi, ga

10、mma, Ci, Si, Ei,Manipulating Symbolic Expressions and Equations(符号表达式和符号方程的运算),方程是个等式,而表达式不是。,Extracting Numerators and Denominators(提取分子和分母),These functions work on expressions 函数numden可以从表达式中提取分子和分母。,The numden function extracts the numerator and denominator from an expression,num,den=numden(y) 它创

11、建了两个新的变量num和den(可以随意命名),Expanding and Factoring,num is an expression,expand函数用于多项式的展开运算,w is an equation,expand函数也可以用于方程的展开运算,collect,函数collect可以合并同类项,与函数expand类似。,expand、factor、collect,expand(s) 展开表达式或方程 factor(S) 对表达式或方程做因式分解 collect(s) 合并同类项,Simplifying,The expand, factor and collect functions ca

12、n be used to “simplify” an expression and sometimes an equation What constitutes a simplification is not always obvious(并不一定总是得到最简方程) The simplify function uses a set of built in rules,simplify used on an expression,simplify used on an equation,该函数不用考虑表达式中的变量是否被定义为符号 变量。表达式z包含变量a,这里a并没有明确的定义, 因此也不会出

13、现在工作区窗口中。,Simple,The simple function is different from simplify It tries all of the different simplification techniques, and chooses the result that is the shortest(函数simple使用不同的化简方法并给出最简结果,函数的化简过程会在屏幕上显示出来。),All of the possibilities evaluated are reported, however there is only one actual answer,Bo

14、th simple and simplify work on expressions and equations,Hint,Use the poly2sym function as a shortcut to create a polynomial,Hint,Extract the coefficients from a polynomial, using the sym2poly function,Solving (求解)Equations and Expressions,Use the solve function Automatically sets expressions equal

15、to 0 and solves for the roots Uses the equality specified in equations Solves for the variables in systems of equations,函数solve用于求解表达式时,设该表达式为零,同时求解它的根。,You can define your expression or equation in the solve function,注意,结果ans是一个21的符号数组。如果预先定义x为符号变量,那么单引号可以去掉。如果没有定义,那么整个表达式必须用单引号括起来,The answer from

16、the solve function is not necessarily a number,You can specify what variable you want to solve for,Remember, if you have defined variables as symbolics previously you can use them in expressions or equations without the single quotes,Example using solve,Sometimes its useful to redefine a variable fo

17、r latter use,Example,Use MATLABs symbolic capability to solve an equation k = k0*exp(-Q/RT) Solve for Q,Hand solution,Solutions,MATLAB Solution,Solving Systems of Equations(求解方程组),This result is a structure array. (结果是一个结构数组),There are several different approaches to find the actual values of x, y,

18、and z,Give the result a name, such as answer, and then specify the field name inside the structure array to retrieve the values for x, y, and z,Assign individual variable names. Notice that x, y and z are symbolic variables,If you need to use the value of x, y or z in a function that needs a double

19、as input, youll need to change the variable type from symbolic to double (x,y和z的值是作为字符变量列出的。如果要求计算结果必须是双精度浮点数,需要利用函数double改变变量类型。),solve,solve(eq) solve(eq, var) solve(eq1, eq2, , eqn) g = solve(eq1, eq2, , eqn, var1, var2, , varn) eq代表方程,var代表的是变量。,Substitution(替换),Once we have a symbolic expressio

20、n well probably want to substitute numbers into it. 经常需要替换符号表达式的变量。 如果在工作区窗口中一个变量不是字符变量,那么使用函数subs时必须用单引号将该变量括起来。,We could substitute in a new variable in this case well put a y everywhere there used to be an x(用变量y替换变量x) 变量E4没有改变,ans中存储的信息发生了变化。,使用相同的方法可以实现用数值进行替换的过程 We could substitute in a number

21、 in this case 3 for x,If the variables inside the expression have been explicitly defined as symbolics we dont need the single quotes(与其他的符号运算一样,如果变量已经显示地定义为符号变量,则单引号可以去掉。),To substitute into multiple variables group them with curly braces(用大括号括出所有变量,可以实现多重替换,定义元胞数值),Symbolic Plotting(符号绘图),The symb

22、olic toolbox includes a group of functions to create symbolic plots(符号工具箱包括一组函数,可以用来绘制符号函数的图形) The most basic is the ezplot(最基本的函数是ezplot),ezplot,Allows you to plot symbolic expressions ezplot(S) Defaults to a range of -2p to +2p (横坐标的取值范围默认为-2p到+2p ) ezplot(S, xmax, xmin) 用户可以在函数ezplot的第二个参数输入区域设定x

23、的最大值和最小值,-2p,+2p,Note this plot was created with the student version The symbolic functionality is included in the student version,Add your own titles, axis labels and other annotations using the same functions described for numeric plotting (与plot一样,ezplot可以专门指定图形标题,坐标轴标注和图形注释。),Notice that ezplot

24、creates a title and axis labels automatically,ezplot supports implicit (隐函数)plotting,The equation for a circle can be expressed implicitly as: x2 + y2 = 1 You could solve for y, but its not necessary with ezplot ezplot(x2 + y2 =1,-1.5,1.5),Ezplot supports parametric equation(参数方程) graphs,The equatio

25、n for a circle can be expressed parametrically as: x=sin(t) y=cos(t) To create the graph use ezplot(sin(x),cos(x),Implicit and Parametric plots of a circle,Hint,Most symbolic functions will allow you to either enter a symbolic variable that represents a function, or to enter the function itself encl

26、osed in single quotes. For example y=sym(x2-1) ezplot(y) is equivalent to ezplot(x2-1),Other Symbolic Plots(其他符号绘图函数),Additional symbolic plotting functions are available, which mirror the functions used in numeric MATLAB plotting options,To demonstrate these plot types create a symbolic version of

27、“peaks”,We broke this function up into three parts to make it easier to enter into the computer. Notice that there are no “dot” operators used in these expressions, since they are all symbolic.,When we created the same plots using a standard MATLAB approach it was necessary to define an array of bot

28、h x and y values, mesh them together, and calculate the values of z based on the two dimensional arrays. The symbolic plotting capability contained in the symbolic toolbox makes creating these graphs much easier.,All of these graphs can be annotated using the standard MATLAB functions such as title,

29、 xlabel, text, etc.,These contour plots are a two-dimensional representation of the three-dimensional peaks function,The polar graph requires us to define a new function,Any of these ezplot graphs can handle parameterized equations,Calculus(微积分运算),MATLABs symbolic toolbox supports Symbolical differe

30、ntiation(微分) Symbolic integration (积分) This makes it possible to find analytical solutions for many problems, instead of numeric approximations.(求导和积分运算可以代替数值近似法,得到问题的解析解),Differentiation (微分),Concept introduced in Calculus I a derivative is really just the slope of an equation(导数可以认为是函数的斜率或者函数的变化率)

31、 A common application of derivatives is to find velocities and accelerations(一辆赛车的速度可以看成是单位时间内距离的变化量),Consider a race car,Assume that during a race the car starts out slowly, and reaches its fastest speed at the finish line (假设在整个比赛中,汽车慢慢开出,并在终点时达到他的最大速度) To avoid running into the stands, the car mu

32、st then slow down until it finally stops (为了避免将汽车开入看台,必须慢慢减速直至停下来。),Model,We might model the position of the car using a sine wave (可以用一个正弦曲线来模拟汽车的位置。),Create a plot of position vs time using ezplot,ezplot of position,diff function,The diff function finds a symbolic derivative(用函数diff可以求出汽车的速度方程) Th

33、e velocity is the derivative of the position(速度是位移的导数), so to find the equation of the velocity of the car well use the diff function, then plot the result,Find the symbolic derivative, which corresponds to the velocity,Create a plot of velocity and time,The velocity is the derivative of the positio

34、n with respect to time,Acceleration,The acceleration is the derivative of the velocity(汽车的加速度是单位时间内速度的变化率,所以加速度是速度的导数), so to find the equation of the acceleration of the car well use the diff function, then plot the result,Determine the equation for the acceleration,Acceleration is the derivative o

35、f the velocity,Partial Derivatives(偏导数),If you have multiple variables, MATLAB takes the derivative with respect to x unless you specify otherwise All the other variables are kept constant,To find the derivative with respect to some variable other than x, you must specify it in the diff function,Not

36、ice that t is enclosed in single quotes, since we havent specified it as a symbolic variable,Higher order derivatives(高阶导数),To find higher order derivatives we can either nest the diff function diff(diff(y) or specify the derivative order in the diff function diff(y,2),Integration(积分),Usually introd

37、uced in Calculus II Often visualized as the area under a curve (通常可以理解为曲线下的面积) MATLAB has built in symbolic integration capability.,Differential Equations(微分方程),Differential equations contain both the derivative of the dependent variable with respect to the independent variable(微分方程中包含因变量和自变量的导数) the dependent variable,is a differential equation,Default variable,Alt

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论