資源描述:
《Matlab符號(hào)變量》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、Matlab的符號(hào)運(yùn)算功能強(qiáng)大,看了些資料,都比較啰嗦,然后再次總結(jié)為一個(gè)m文件測(cè)試大部分符號(hào)運(yùn)算功能%%符號(hào)變量與符號(hào)表達(dá)式%%%%%%%%%%%%%%%%%%%%%%%%%%%%1.符號(hào)變量與符號(hào)表達(dá)式%%%%%%%%%%%%%%%%%%%%%%%%%%%clearall;clc;closeall;%f=sym('sin(x)+5x')%f——符號(hào)變量名%sin(x)+5x——符號(hào)表達(dá)式%''——符號(hào)標(biāo)識(shí)%符號(hào)表達(dá)式一定要用''單引號(hào)括起來(lái)matlab才能識(shí)別%''的內(nèi)容可以是符號(hào)表達(dá)式,也可以是符號(hào)方程。%例:?%f1=sym('
2、a*x^2+b*x+c')——二次三項(xiàng)式%f2=sym('a*x^2+b*x+c=0')——方程%f3=sym('Dy+y^2=1')——微分方程%符號(hào)表達(dá)式或符號(hào)方程可以賦給符號(hào)變量,以后調(diào)用方便;也可以不賦給符號(hào)變量直接參與運(yùn)算%syms命令用來(lái)建立多個(gè)符號(hào)量,一般調(diào)用格式為:%syms變量1變量2...變量n?%%符號(hào)矩陣的創(chuàng)建%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%2.符號(hào)矩陣的創(chuàng)建%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%數(shù)值矩陣A=[1,2;3,4]%A=[a,b;c,d]——不識(shí)別
3、%@1.用matlab函數(shù)sym創(chuàng)建矩陣(symbolic的縮寫(xiě))%命令格式:A=sym('[]')?%※符號(hào)矩陣內(nèi)容同數(shù)值矩陣%※需用sym指令定義%※需用''標(biāo)識(shí)%例如:A=sym('[a,2*b;3*a,0]')%A=%[a,2*b]%[3*a,0]%這就完成了一個(gè)符號(hào)矩陣的創(chuàng)建。%注意:符號(hào)矩陣的每一行的兩端都有方括號(hào),這是與matlab數(shù)值矩陣的一個(gè)重要區(qū)別。%@2.用字符串直接創(chuàng)建矩陣(這種方法創(chuàng)建的沒(méi)有什么用處)%※模仿matlab數(shù)值矩陣的創(chuàng)建方法%※需保證同一列中各元素字符串有相同的長(zhǎng)度。%例:A=['[a,2*b]'
4、;'[3*a,0]']?%A=%[a,2*b]%[3*a,0]%@3.符號(hào)矩陣的修改%a.直接修改%可用光標(biāo)鍵找到所要修改的矩陣,直接修改%b.指令修改%※用A1=sym(A,*,*,'new')來(lái)修改。這個(gè)經(jīng)過(guò)測(cè)試,不能運(yùn)行%※用A1=subs(A,'new','old')來(lái)修改%%例如:A=[a,2*b]%[3*a,0]A=sym('[a,2*b;3*a,0]')%A1=sym(A,2,2,'4*b')%%等效于A(2,2)='4*b';%A1=[a,2*b]%[3*a,4*b]??A1=subs(A,'0','4*b')A2=su
5、bs(A1,'c','b')??%A2=[a,2*c]?%[3*a,4*c]?%@4.符號(hào)矩陣與數(shù)值矩陣的轉(zhuǎn)換%※將數(shù)值矩陣轉(zhuǎn)化為符號(hào)矩陣%函數(shù)調(diào)用格式:sym(A)A=[1/3,2.5;1/0.7,2/5]%A=%0.33332.5000%1.42860.4000B=sym(A)%ans=%[1/3,5/2]%[10/7,2/5]%※將符號(hào)矩陣轉(zhuǎn)化為數(shù)值矩陣%函數(shù)調(diào)用格式:numeric(A)%B=%[1/3,5/2]%[10/7,2/5]%numeric(B)這個(gè)函數(shù)不存在了VPA(B,4)%發(fā)現(xiàn)這個(gè)函數(shù)可用%R=VPA(S)num
6、ericallyevaluateseachelementofthedoublematrix%SusingvariableprecisionfloatingpointarithmeticwithDdecimal?%digitaccuracy,whereDisthecurrentsettingofDIGITS.?%TheresultingRisaSYM.%??%VPA(S,D)usesDdigits,insteadofthecurrentsettingofDIGITS.%DisanintegerortheSYMrepresentationo
7、fanumber.%ans=?%[.3333,2.500]%[1.429,.4000]%%符號(hào)運(yùn)算%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%3.符號(hào)運(yùn)算%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%例1:f=sym('2*x^2+3*x-5');g=sym('x^2+x-7');h=f+g%h=?%3*x^2+4*x-12%例2:f=sym('cos(x)');g=sym('sin(2*x)');f/g+f*g%ans=%cos(x)/sin(2*x)+cos(x)*sin(2*x)%%查找符號(hào)
8、變量%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%4.查找符號(hào)變量%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%findsym(expr)按字母順序列出符