9.符號(hào)代數(shù).ppt_第1頁(yè)
9.符號(hào)代數(shù).ppt_第2頁(yè)
9.符號(hào)代數(shù).ppt_第3頁(yè)
9.符號(hào)代數(shù).ppt_第4頁(yè)
9.符號(hào)代數(shù).ppt_第5頁(yè)
已閱讀5頁(yè),還剩93頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、符號(hào)代數(shù),Symbolic Manipulation,Matlab符號(hào)運(yùn)算是通過(guò)集成在Matlab中的符號(hào)數(shù)學(xué)工具箱(Symbolic Math Toolbox)來(lái)實(shí)現(xiàn)的。 和別的工具箱有所不同,該工具箱不是基于矩陣的數(shù)值分析,而是使用字符串來(lái)進(jìn)行符號(hào)分析與運(yùn)算。 實(shí)際上,Matlab中的符號(hào)數(shù)學(xué)工具箱是建立在Maple基礎(chǔ)上的,當(dāng)進(jìn)行Matlab符號(hào)運(yùn)算時(shí),它就請(qǐng)求Maple軟件去計(jì)算并將結(jié)果返回給Matlab。 Matlab的符號(hào)數(shù)學(xué)工具箱可以完成幾乎所有得符號(hào)運(yùn)算功能。這些功能主要包括:符號(hào)表達(dá)式的運(yùn)算,符號(hào)表達(dá)式的復(fù)合、化簡(jiǎn),符號(hào)矩陣的運(yùn)算,符號(hào)微積分、符號(hào)函數(shù)畫(huà)圖,符號(hào)代數(shù)方程求解,

2、符號(hào)微分方程求解等。此外,工具箱還支持可變精度運(yùn)算,既支持符號(hào)運(yùn)算并以指定的精度返回結(jié)果。,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,用符號(hào)代數(shù)的方法可以求解數(shù)學(xué)方程式。 初看起來(lái),y是一個(gè)關(guān)于x的復(fù)雜函數(shù)。 細(xì)看,該方程可以化簡(jiǎn)。,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(無(wú)意義),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(創(chuàng)建符號(hào)變量),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 (可以同時(shí)創(chuàng)建多個(gè)符號(hào)變量),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不會(huì)在工作區(qū)窗口出現(xiàn)) E was set equal to a character string, defined by the single quotes inside the function.(變量E被設(shè)置為字符串,函數(shù)內(nèi)部要用單引號(hào)括起來(lái)),Workspace,Equations vs Expressions,We can create an entire equation, and give it a name ideal_gas_law=sym(P*V=n*R*Temp) 方程:一個(gè)表達(dá)式等于一個(gè)值或另一個(gè)表達(dá)式 表達(dá)式:數(shù)學(xué)運(yùn)算符號(hào)的集合 表達(dá)式不同于方程,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(符號(hào)表達(dá)式和符號(hào)方程的運(yùn)算),方程是個(gè)等式,而表達(dá)式不是。,Extracting Numerators and Denominators(提取分子和分母),These functions work on expressions 函數(shù)numden可以從表達(dá)式中提取分子和分母。,The numden function extracts the numerator and denominator from an expression,num,den=numden(y) 它創(chuàng)

11、建了兩個(gè)新的變量num和den(可以隨意命名),Expanding and Factoring,num is an expression,expand函數(shù)用于多項(xiàng)式的展開(kāi)運(yùn)算,w is an equation,expand函數(shù)也可以用于方程的展開(kāi)運(yùn)算,collect,函數(shù)collect可以合并同類項(xiàng),與函數(shù)expand類似。,expand、factor、collect,expand(s) 展開(kāi)表達(dá)式或方程 factor(S) 對(duì)表達(dá)式或方程做因式分解 collect(s) 合并同類項(xiàng),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(并不一定總是得到最簡(jiǎn)方程) The simplify function uses a set of built in rules,simplify used on an expression,simplify used on an equation,該函數(shù)不用考慮表達(dá)式中的變量是否被定義為符號(hào) 變量。表達(dá)式z包含變量a,這里a并沒(méi)有明確的定義, 因此也不會(huì)出

13、現(xiàn)在工作區(qū)窗口中。,Simple,The simple function is different from simplify It tries all of the different simplification techniques, and chooses the result that is the shortest(函數(shù)simple使用不同的化簡(jiǎn)方法并給出最簡(jiǎn)結(jié)果,函數(shù)的化簡(jiǎn)過(guò)程會(huì)在屏幕上顯示出來(lái)。),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,函數(shù)solve用于求解表達(dá)式時(shí),設(shè)該表達(dá)式為零,同時(shí)求解它的根。,You can define your expression or equation in the solve function,注意,結(jié)果ans是一個(gè)21的符號(hào)數(shù)組。如果預(yù)先定義x為符號(hào)變量,那么單引號(hào)可以去掉。如果沒(méi)有定義,那么整個(gè)表達(dá)式必須用單引號(hào)括起來(lái),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. (結(jié)果是一個(gè)結(jié)構(gòu)數(shù)組),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的值是作為字符變量列出的。如果要求計(jì)算結(jié)果必須是雙精度浮點(diǎn)數(shù),需要利用函數(shù)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. 經(jīng)常需要替換符號(hào)表達(dá)式的變量。 如果在工作區(qū)窗口中一個(gè)變量不是字符變量,那么使用函數(shù)subs時(shí)必須用單引號(hào)將該變量括起來(lái)。,We could substitute in a new variable in this case well put a y everywhere there used to be an x(用變量y替換變量x) 變量E4沒(méi)有改變,ans中存儲(chǔ)的信息發(fā)生了變化。,使用相同的方法可以實(shí)現(xiàn)用數(shù)值進(jìn)行替換的過(guò)程 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(與其他的符號(hào)運(yùn)算一樣,如果變量已經(jīng)顯示地定義為符號(hào)變量,則單引號(hào)可以去掉。),To substitute into multiple variables group them with curly braces(用大括號(hào)括出所有變量,可以實(shí)現(xiàn)多重替換,定義元胞數(shù)值),Symbolic Plotting(符號(hào)繪圖),The symb

22、olic toolbox includes a group of functions to create symbolic plots(符號(hào)工具箱包括一組函數(shù),可以用來(lái)繪制符號(hào)函數(shù)的圖形) The most basic is the ezplot(最基本的函數(shù)是ezplot),ezplot,Allows you to plot symbolic expressions ezplot(S) Defaults to a range of -2p to +2p (橫坐標(biāo)的取值范圍默認(rèn)為-2p到+2p ) ezplot(S, xmax, xmin) 用戶可以在函數(shù)ezplot的第二個(gè)參數(shù)輸入?yún)^(qū)域設(shè)定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可以專門(mén)指定圖形標(biāo)題,坐標(biāo)軸標(biāo)注和圖形注釋。),Notice that ezplot

24、creates a title and axis labels automatically,ezplot supports implicit (隱函數(shù))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(參數(shù)方程) 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(其他符號(hào)繪圖函數(shù)),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(微積分運(yùn)算),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.(求導(dǎo)和積分運(yùn)算可以代替數(shù)值近似法,得到問(wèn)題的解析解),Differentiation (微分),Concept introduced in Calculus I a derivative is really just the slope of an equation(導(dǎo)數(shù)可以認(rèn)為是函數(shù)的斜率或者函數(shù)的變化率)

31、 A common application of derivatives is to find velocities and accelerations(一輛賽車的速度可以看成是單位時(shí)間內(nèi)距離的變化量),Consider a race car,Assume that during a race the car starts out slowly, and reaches its fastest speed at the finish line (假設(shè)在整個(gè)比賽中,汽車慢慢開(kāi)出,并在終點(diǎn)時(shí)達(dá)到他的最大速度) To avoid running into the stands, the car mu

32、st then slow down until it finally stops (為了避免將汽車開(kāi)入看臺(tái),必須慢慢減速直至停下來(lái)。),Model,We might model the position of the car using a sine wave (可以用一個(gè)正弦曲線來(lái)模擬汽車的位置。),Create a plot of position vs time using ezplot,ezplot of position,diff function,The diff function finds a symbolic derivative(用函數(shù)diff可以求出汽車的速度方程) Th

33、e velocity is the derivative of the position(速度是位移的導(dǎo)數(shù)), 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(汽車的加速度是單位時(shí)間內(nèi)速度的變化率,所以加速度是速度的導(dǎo)數(shù)), 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(偏導(dǎo)數(shù)),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(高階導(dǎo)數(shù)),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(微分方程中包含因變量和自變量的導(dǎo)數(shù)) the dependent variable,is a differential equation,Default variable,Alt

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論