matlab 7 在工程上的應用 -...

83
MATLAB 7 在工程上的應用 10 MATLAB 中的符號處理程序

Upload: others

Post on 16-Sep-2019

3 views

Category:

Documents


0 download

TRANSCRIPT

  • MATLAB 7 在工程上的應用

    第 10 章MATLAB 中的符號處理程序

  • 本章中包含符號數學工具箱,將介紹

    • 符號代數。

    • 求解代數方程式以及超越方程式的符號方法。

    • 求解常微分方程式的符號方法。

    • 符號微積分,包含了積分、微分、極限,以及級數。

    • 拉氏轉換。

    • 某些線性代數的主題,包含求解行列式值、反矩陣,以及特徵值的符號方法。

  • 當讀者完成本章的學習,則具備使用MATLAB進行下列事項的能力

    • 建立符號表示式並且以代數的方式操作。

    • 求解代數方程式以及超越方程式的符號解。

    • 進行符號微分與積分。

    • 以符號方法計算極限與級數。

    • 求出常微分方程式的符號解。

    • 求出拉氏轉換。

    • 進行符號線性代數運算,包含求出行列式值、反矩陣,以及特徵值的算式。

  • 函數 sym 可以用來建立 MATLAB 中的「符號物件」。

    如果 sym 的輸入引數是一個字串,則所得到的結果是一個符號的數字或者變數;如果此函數的輸入引數是一個數值純量

    或者是一個矩陣,則所得到的結果是一個給定數值的符號表

    示式。

    舉例來說,輸入x = sym(’x’)會建立出名稱為 x 的符號變數,並且輸入y = sym(’y’)則會建立出名稱為 y 的符號變數。

    輸入x = sym(’x’,’real’)則是告訴 MATLAB ,假設 x 是一個實數。若是輸入 x = sym(’x’,’unreal’)則是告訴 MATLAB 假設 x 不是一個實數。

  • syms 這個函數則是能夠讓你將超過一個以上的敘述放入單一個敘述之中。

    舉例來說,輸入syms x 等效於輸入 x = sym(’x’),並且輸入 syms x y u v 能夠建立x、y、u,以及 v 這四個符號變數。

  • 你可以使用sym這個函數來建立符號常數,方式是藉由使用數值來當作引數。

    例如,輸入

    pi = sym(’pi’)fraction = sym(’1/3’)以及

    sqroot2 = sym(’sqrt(2)’)

    可以建立出避免數值例如 pi, 1/3以及 等浮點數所繼承而來的近似。

    2

  • 符號表示式

    你可以在算式中使用符號變數或者再將符號變數當作

    函數的引數使用。使用的方式就好像在進行數值運算

    的時候使用運算子 + - * / ^以及內建函數的方式一樣。

    例如,我們輸入

    >>syms x y

    >>s = x + y;

    >>r = sqrt(x^2 + y^2);

    則可以建立符號變數s 以及 r。其中s = x + y 以及 r =

    sqrt(x^2 + y^2)這兩項則是符號表式的例子。

  • 而在 MATLAB 中所使用的向量以及矩陣的標記方法,

    對於符號變數也一併適用。例如,你可以使用下列的對

    話來建立符號矩陣 A :

    >>n = 3;

    >>syms x;

    >>A = x.^((0:n)’*(0:n))

    A =

    [ 1, 1, 1, 1]

    [ 1, x, x^2, x^3]

    [ 1, x^2, x^4, x^6]

    [ 1, x^3, x^6, x^9]

  • 函數collect(E)可以收集算式 E 中相同次方的係數。如果具有超過一個以上的變數,則要使用選擇性的形式collect(E,v),同時收集具有相同次方 v 的係數。

    >>syms x y>>E = (x-5)^2+(y-3)^2;>>collect(E)ans =

    x^2-10*x+25+(y-3)^2>>collect(E,y)ans =

    y^2-6*y+(x-5)^2+9

  • 而expand 以及 simplify 函數的使用方式如下。

    >>syms x y

    >>expand((x+y)^2) % applies algebra rules

    ans =

    x^2+2*x*y+y^2

    >>expand(sin(x+y)) % applies trig identities

    ans =

    sin(x)*cos(y)+cos(x)*sin(y)

    >>simplify(6*((sin(x))^2+(cos(x))^2)) % applies another trig

    identity

    ans =

    6

  • factor 函數可以進行因式分解。

    >>syms x y

    >>factor(x^2-1)

    ans =

    (x-1)*(x+1)

  • subs(E,old,new)可以將算式 E 中 old 的部分以 new取代,其中old 這個部分可以是符號變數或者是符號表示式,並且 new 這個部分可以是符號變數、符號表式、矩陣、數值的值,或者

    是數值的矩陣。

    例如,

    >>syms x y>>E = x^2+6*x+7;>>F = subs(E,x,y)F =

    y^2+6*y+7

  • 若要告訴 MATLAB,函數 f 是變數 t 的函數,則要輸入f = sym(’f(t)’)。結果,f 的行為會像是 t 的函數,並且你可以使用工具箱指令來操作這個函數。

    舉例來說,要建立一個新的函數 g(t) = f (t + 2) - f (t) ,則對話如下

    >>syms t>>f = sym(’f(t)’);>>g = subs(f, t, t+2)-fg =

    f(t+2)-f(t)一旦某一個函式被定義為f (t) ,則函數g (t)也同時定義完成。

  • 使用subs以及double這兩個函數以數值的方式計算算式。使用subs(E,old,new)以數值new 來取代算式 E 中的old。所得到的結果類別是雙倍浮點數。

    例如,

    >>syms x>>E = x^2+6*x+7;>>G = subs(E,x,2)G =

    23>>class(G)ans =

    double

  • MATLAB 函數 ezplot(E)可以產生符號表式 E 的圖形,也就是具有一個變數的函數圖形。

    預設的自變數的範圍落在區間 [-2p, 2p] 之間,除非此區間具有奇異點。

    另一個選擇性的形式為 ezplot(E,[xmin xmax]),可以產生範圍xmin 到 xmax。

  • 圖10.1–1 使用ezplot函數所產生的 E = x 2 - 6x + 7 的函數圖形。

  • 優先順序

    MATLAB並不一定將算式依照我們一般所使用的形式編排。

    例如,MATLAB也許會求出-c+b這種形式的答案,而一般的時候我們通常會寫成 b-c。

    所以必須要將MATLAB使用優先順序牢記在心,以免誤解(請參考課本第1-8~1-9頁對於優先權的相關討論)。

    MATLAB常常也會將結果表示成為1/a*b這樣的形式,而對於這個形式我們通常會寫成 b/a。

  • 瞭解問題測試

    T10.1-1 Given the expression:

    and

    A. Find product E1E2 and express it in its simplest form

    B. Find the quotient E1/E2 and express it in its simplest form

    C. Evaluate the sum E1 + E2 at x = 7.1 in symbolic form and in

    numeric form.

    3 21 15 75 125E x x x

    22 ( 5) 20E x x

  • 瞭解問題測試

    T10.1-1 The sessions are: (a) syms x E1 = x^3-15*x^2+75*x-125; E2 = (x+5)^2-20*x; S1 = E1*E2; factor(S1) ans = (x-5)^5 S2 = E1/E2; simplify(S2) ans = x-5 S3 = E1+E2; simplify(S2)

    ans = x-5 S3 = E1+E2; G = sym(subs(S3,x,7.1)) G = 7696088813222736*2^(-49) G = simplify(G) G = 481005550826421/3518437208

    8832 H = double(G) H = 13.6710

  • solve 函數

    有三種使用solve函數的方式。例如,要求解方程式 x + 5 = 0,一種方式是

    >>eq1 = ’x+5=0’;>>solve(eq1)ans =

    -5

    而第二種方式就是

    >>solve(’x+5=0’)ans =

    -5

    代數與超函數方程式

  • solve 函數(承上頁)

    第三種方式是

    >>syms x>>solve(x+5)ans =

    -5你可以使用以下的方法將結果儲存於命名的變數當中:

    >>syms x>>x = solve(x+5)x =

    -5

  • 求解方程式 e2x + 3ex = 54的對話為

    >>solve(’exp(2*x)+3*exp(x)=54’)ans =

    [ log(-9)][ log(6)]

  • 其他的範例:

    >>eq2 = ’y^2+3*y+2=0’;>>solve(eq2)ans =

    [-2][-1]

    >>eq3 = ’x^2+9*y^4=0’;>>solve(eq3) %Note that x is presumed to be the unknown variableans =

    [ 3*i*y^2][-3*i*y^2]

    (在對話開始前 x 被認定是未知的變數)

  • 當算式中具有超過一個以上的變數的時候,MATLAB 會將

    字母順序最接近於 x 的變數當作找到的變數。你可以使用

    語法solve(E,’v’)來指定你想要的變數,此語法指定 v 是解的

    變數。

  • >>solve(‘b^2+8*c+2*b=0’)ans =

    - b^2/8 - b/4>> solve(‘b^2+8*c+2*b=0’, ‘b’)ans =- (1 - 8*c)^(1/2) - 1(1 - 8*c)^(1/2) – 1

    Also,>>[x, y] = solve(eq1, eq2)>>x =-5-5y =-2-1

    10-22

  • >>eq4 = ’6*x+2*y=14’;>>eq5 = ’3*x+7*y=31’;>>solve(eq4,eq5) ans = x: [1x1 sym] y: [1x1 sym] >> y=ans.y y = 4 >> x=ans.x x = 1

    >>[x,y]=solve(eq4,eq5) x =

    1

    y =

    4 >> s=solve(eq4,eq5) >> s.x ans = 1 >> s.y ans = 4

  • 瞭解問題測試T10.2-1 The session is:syms xsolve(sqrt(1-x^2)-x)ans =1/2*2^(1/2)

    T10.2-2 The session is:S = solve(0x+6*y=a0,02*x-3*y=90);S.xans =18/5+1/5*aS.yans =-3/5+2/15*a

    USE matlab to solve the equation 21 x x

    USE matlab to solve the equation set x+6y=a, 2x-3y=9 for x and y in terms of the parameter a.

  • Ex.10.2.1兩圓交點

    To find the intersection points of two circles. The first circle has a radius of 2 and is centered at x = 3, y=5. The second circle has a radius b and is centered at x=5, y = 3.

    A. Find the (x, y) coordinates of the intersection points in terms of the parameter b.

    B. Evaluate the solution for the case where b = 30.5

  • 圖10.2–1 兩個圓的交點。

  • These equations:

    clear all;clc; syms x y b eq01='(x-3)^2+(y-5)^2=4'; eq02 ='(x-5)^2+(y-3)^2=b^2'; s= solve(eq01, eq02); s.x s.y subs(s.x, b, sqrt(3)) subs(s.y, b, sqrt(3))

    2 2( 3) ( 5) 4x y 2 2 2( 5) ( 3)x y b

  • The solution for the x coordinates of the intersection points is

    For y coordinate is S.y (b) >>subs(S.x, b, sqrt(3)) Ans= 4.9820 3.2680

    2 2 49 1 1 16 242 8 8

    x b b b

  • 瞭解問題測試

    T10.2-3 After the session shown at the end of Example 10.2-1, type

    subs(S.y,b,sqrt(3)) ans = 4.7320 3.0180

  • Ex 10.2.2 Positioning a Robot Arm

    Figure shows a robot arm having two joints and two links. The angles of rotation of the motor at the joints are 1 and 2. From trigonometry we can derive the following expressions for the (x, y) coordinates of the hand:

    x= L1cos1 + L2cos(1 + 2)y= L1sin1 + L2sin(1 + 2)

    Suppose that the link lengths are L1 = 4 ft and L2 = 3 ft.A. compute the motor angles required to position the hand at x=6 ft and y=2 ft.B. It is desired to move the hand along the straight line where x is constant at 6 ft and y varies from y = 0.1 to y =3.6 ft. Obtain a plot of the required motor angles as a function of y.

  • 一個具有兩個連桿以及兩個關節的機器手臂。

  • >>S = solve('4*cos(th1)+3*cos(th1+th2)=6',... '4*sin(th1)+3*sin(th1+th2)=2') S = th1:[2x1 sym] th2:[2x1 sym] >>double(S.th1)*(180/pi) % convert from radians to degrees ans = -3.2981 40.1680 >>double(S.th2)*(180/pi) % convert from radians to degrees ans = 51.3178 -51.3178

  • S = solve('4*cos(th1)+3*cos(th1+th2)=6',... '4*sin(th1)+3*sin(th1+th2)=y', 'th1','th2'); yr = [1:0.1:3.6]; th1r = [subs(S.th1(1),'y',yr);subs(s.th1(2),'y',yr)]; th2r = [subs(S.th2(1),'y',yr);subs(s.th2(2),'y',yr)]; th1d = (180/pi)*th1r; th2d = (180/pi)*th2r; subplot(2,1,1) plot(yr,th1d,2,-3.2981,'x',2,40.168,'o'),xlabel('y(feet)'),... ylabel(‘Theta1 (degrees)’) subplot(2,1,2) plot(yr,th2d,2,-51.3178,'o',2,51.3178,'x'),xlabel('y(feet)'),... ylabel('Theta2 (degrees)')

  • 圖10.2–3 機器手臂的手部沿著一條垂直的直線運動,機器手臂馬達角度的圖形。

  • 以diff函數進行微分

    >>syms n x y>>diff(x^n)ans =

    x^n*n/x>>simplify(ans)ans =

    x^(n-1)*n>>diff(log(x))ans =

    1/x>>diff((sin(x))^2)ans =

    2*sin(x)*cos(x)

  • 如果算式包含了超過一個以上的變數,除非指明其他的狀況,

    否則 diff 函數會針對 x 進行計算,或者最接近於 x 的變數來進行微分。當具有超過一個以上的變數的時候, diff函數會計算偏微分。

    例如,

    >>diff(sin(x*y))ans =

    cos(x*y)*y

  • 函數 diff(E,v)會傳回算式 E 對於變數 v 的微分。

    >>syms x y

    >>diff(x*sin(x*y),y)

    ans =

    x^2*cos(x*y)

  • 函數 diff(E,n) 則會傳回算式 E 對於預設的自變數的第 n 階

    微分。

    >>syms x

    >>diff(x^3,2)

    ans =

    6*x

  • 函數 diff(E,v,n) 則會傳回算式 E 對於變數 v 的第 n 階微分。

    >>syms x y

    >>diff(x*sin(x*y),y,2)

    ans =

    -x^3*sin(x*y)

  • Ex10.3.1越過”綠色怪物”牆的棒球軌跡

    The Green Monster is a wall 37 ft heigh in left field at Fenway Park Boston. The wall is 310 ft from home plate down the left-field line. Assuming that the batter hits the ball 4 ft above the ground, and neglecting air resistance, determine the minimum speed the batter must gave to the ball to hit it over the Green Monster. In addition, find the angle at which the ball must be hit.

    ThusWhen x=d and y=h, g=32.2 ft/sec2

    Which can solve

    ( ) ( cos )ox t v t2

    ( ) ( sin )2 o

    gty t v t 2

    2 2

    ( )( ) ( ) tan2 coso

    g x ty t x tv

    2

    2 2 tan2 coso

    g dh hv

    2ov

    22

    22 cos ( tan )og dv

    d h

  • Because v0 > 0, minimizing is equivalently to minimizing v0. Note also that gd2/2 ia a multiplicative factor in the expression for . Thus the minimizing value of is independent of g and can be found by minimizing the function

    Thus derivative df/d and solve the equation df/d =0 for .

    2ov

    2ov

    2

    1cos ( tan )

    fd h

  • 圖10.3–1 超越綠色怪物的棒球軌跡。

  • syms d g h th f = 1/((cos(th))^2)*(d*tan(th)-h)); dfdth=diff(f,th); thmin = solve(dfdth, th); thmin = subs(thmin, (d,h),(310,33)) thmin= 0.8384 -0.7324

    d2f/dth2

  • >>second = diff(f,2,th); % This is the second derivative. >>second = subs(second,{th,d,h},{thmin(1),310,33}) second = 0.0321 >>v2 = (g*d^2/2)*f; >>v2min = subs(v2,{d,h,g},{310,33,32.2}); >>vmin = sqrt(v2min); >>vmin =

    double(subs(vmin(1),{th,d,h,g},{thmin(1),310,33,32.2})) vmin = 105.3613

  • 瞭解問題測試

    T10.3-1 The session is: syms x E = diff(sinh(3*x)*cosh(5*x)); subs(E,x,0.2) ans = 9.2288

    T10.3-2 The session is: syms x y diff(5*cosh(2*x)*log(4*y),y) ans = 5*cosh(2*x)/y

    Given that y=sinh(3x)cosh(5x),find dy/dx at x=0.2

    Given that z=5cos(2x)ln(4y),find z/y

  • 使用int函數進行積分

    使用函數 2x 來當作例子>>syms x>>int(2*x)ans =

    x^2

  • 函數 int(E) 會傳回算式 E 對於預設的自變數的積分。

    >>syms n x y>>int(x^n)ans =

    x^(n+1)/(n+1)>>int(1/x)ans =

    log(x)>>int(cos(x))ans =

    sin(x)>>int(sin(y))ans =

    -cos(y)

  • int(E,v)這個形式會傳回算式 E 對於變數 v 所積分的結果。

    >>syms n x>>int(x^n,n)ans =

    1/log(x)*x^n

  • 函數int(E,a,b)這個形式則會傳回算式 E 對於預設自變數在區間 [a, b] 之內的積分,其中 a 以及 b 是數值。

    >>syms x>>int(x^2,2,5)ans =

    39

  • 函數int(E,v,a,b)則會傳回算式E對於變數 v 在區間 [a, b]

    之內的積分,其中 a 以及 b 是數值。

    >>syms x y

    >>int(x*y^2,y,0,5)

    ans =

    125*x/3

  • 函數int(E,m,n)傳回算式 E 對於預設自變數在區間 [m, n] 之

    內的積分,其中 m 以及 n 是符號表示式。

    >>syms t x

    >>int(x,1,t)

    ans =

    1/2*t^2-1/2

    int(sin(x),t,exp(t))

    ans =

    -cos(exp(t)) + cos(t)

  • 下列的對話是一個無法找到積分的例子。其不定積分實際

    上是存在的,但若是積分的界限範圍包含奇異點x = 1 的話,則其定積分並不存在。

    >>syms x>>int(1/(x-1))ans =

    log(x-1)>>int(1/(x-1),0,2)ans =

    NaN

  • 瞭解問題測試

    T10.3-3 The session is: syms x int(x*sin(3*x)) ans = 1/9*sin(3*x)-1/3*x*cos(3*x)

    T10.3-4 The session is: syms x y int(6*y^2*tan(8*x),y) ans = 2*y^3*tan(8*x)

    Given that y=x sin(3x),find

    ydx

    Given that z=6y2tan(8x),find

    zdy

  • 瞭解問題測試

    T10.3-5 The session is: syms x E = int(x*sin(3*x)); subs(E,x,5)-subs(E,x,-2) ans = 0.6672

    Solve 5

    2sin(3 )x x dx

  • 泰勒級數

    taylor(f,n,a)這個函數可以求出定義於算式 f 中的函數的n-1 階泰勒級數,所根據計算的點為 x = a。如果參數 a 被省略,則此函數回傳的級數是根據 x = 0 所計算的。

    >>syms x>>f = exp(x);>>taylor(f,4)ans =

    1+x+1/2*x^2+1/6*x^3>>taylor(f,3,2)ans =

    exp(2)+exp(2)*(x-2)+1/2*exp(2)*(x-2)^2

  • 加總

    symsum(E,a,b) 可以傳回當預設符號由 a 遞增到 b,算式 E 的符號加總。

    >>syms k n>>symsum(k,0,10)ans =

    55>>symsum(k^2, 1, 4)ans =

    30>>symsum(k,0,n-1)ans =

    1/2*n^2-1/2*n

  • 極限函數 limit(E) 可以用來求出當 x 0的時候 E 的極限。

    >>syms a x>>limit(sin(a*x)/x)ans =

    a另外limit(E,v,a)這個形式可以用來求出當v a 時的極限。舉例來說,>>syms h x>>limit((x-3)/(x^2-9),3)ans =

    1/6>>limit((sin(x+h)-sin(x))/h,h,0)ans =

    cos(x)

  • 而limit(E,v,a,’right’)與limit(E,v,a,’left’)這個形式可以用來指定由不同方向趨近某一個值所求出的極限。舉例來說,

    >>syms x>>limit(1/x,x,0,’left’)ans =

    -inf>>limit(1/x,x,0,’right’)ans =

    inf

  • 瞭解問題測試

    T10.3-6 The session is: syms x taylor(cos(x),5) ans = 1-1/2*x^2+1/24*x^4

    T10.3-7 The session is: syms m symsum(m^3) ans = 1/4*m^4-1/2*m^3+1/4*m^2

    Find the first three nonzero terms in Taylor series for cosx.

    Find a formula for the sum1

    3

    0

    m

    m

    m

  • 瞭解問題測試

    T10.3-8 The session is: syms x symsum(cos(pi*x),0,7) ans = 0

    T10.3-9 The session is: syms x limit((2*x-10)/(x^3-125),5) ans = 2/75

    Evaluate

    35

    2 10lim125x

    xx

    Evaluate7

    0

    cos( )n

    n

  • END

    HW 4, 13, 19, 29

  • 使用dsolve函數求解微分方程式

    用來求解單一方程式的dsolve函數的語法為dsolve (’eqn’)

    此函數會回傳符號表式 eqn所代表的常微分方程式(ODE)的符號解。

    >>dsolve(’Dy+2*y=12’)ans =

    6+C1*exp(-2*t)

  • 在方程式中可以具有符號常數。例如,

    >>dsolve(’Dy=sin(a*t)’)ans =

    (-cos(a*t)+C1*a)/a

  • 下面是一個二階的例子:

    dsolve(’D2y=c^2*y’)ans =

    C1*exp(-c*t) + C2*exp(c*t)

  • 求解整組微分方程式

    整組方程式也是使用dsolve函數求解。正確的語法為dsolve(’eqn1’,’eqn2’,...)

    >>[x, y] = dsolve(’Dx=3*x+4*y’,’Dy=-4*x+3*y’)x =

    C1*exp(3*t)*cos(4*t)+C2*exp(3*t)*sin(4*t)y =

    -C1*exp(3*t)*sin(4*t)+C2*exp(3*t)*cos(4*t)

  • 指定起始條件以及邊界條件

    使用指定的自變數值對應到的值來求解方程式,需要使用下列的方式來處理。

    函數dsolve(’eqn’, ’cond1’, ’cond2’,...)這個形式會回傳指定於符號表示式 eqn 中的常微分方程式的符號解,所根據的條件指定於算式cond1、cond2之中。

    如果 y是應變數,則這些條件可以以下列方式指定:y(a) = b、 Dy(a) = c 、 D2y(a) = d,其餘依此類推。

  • 舉例來說,

    >>dsolve(’D2y=c^2*y’,’y(0)=1’,’Dy(0)=0’)ans =

    1/2*exp(c*t)+1/2*exp(-c*t)

    任意的邊界條件,例如 y(0) c,都可以使用。舉例來說,

    >>dsolve(’Dy+a*y=b’,’y(0)=c’)ans =

    1/a*b+exp(-a*t)*(-1/a*b+c)

  • 具有邊界條件的方程式組

    我們可以藉由輸入下列的方式來求解具有邊界條件的方程式組。

    函數dsolve(’eqn1’,’eqn2’,...,’cond1’,’cond2’,...)會傳回以符號表示式 eqn1 以及 eqn2等所表示出來的一組方程式的符號解,所根據的起始條件指定於cond1以及cond2等算式之中。

  • 舉例來說,

    >>dsolve(’Dx=3*x+4*y’,’Dy=-4*x+3*y’, ’x(0)=0’,’y(0)=1’)

    [x,y] =x = exp(3*t)*sin(4*t), y =

    exp(3*t)*cos(4*t)

    不一定要指定 t = 0 的起始條件。可以指定其他時間值 t 所對應的值當作條件。

    >>dsolve(’D2y+9*y=0’,’y(0)=1’,’Dy(pi)=2’)ans =

    -2/3*sin(3*t)+cos(3*t)

    更多相關資料請查詢課本第10-35~10-36頁

  • 拉氏轉換

    >>syms b t>>laplace(t^3)ans =

    6/s^4>>laplace(exp(-b*t))ans =

    1/(s+b)>>laplace(sin(b*t))ans =

    b/(s^2+b^2)

  • 反拉氏轉換

    >>syms b s>>ilaplace(1/s^4)ans =

    1/6*t^3>>ilaplace(1/(s+b))ans =

    exp(-b*t)>>ilaplace(b/(s^2+b^2)ans =

    sin(b*t)

    更多相關資料請查詢課本第 10-38~10-47頁

  • 特徵方程式以及特徵根

    >>syms k>>A = [0 ,1;-k, -2];>>poly(A)ans =

    x^2+2*x+k>>solve(ans)ans =

    [ -1+(1-k)^(1/2) ][ -1-(1-k)^(1/2) ]

    更多相關資料請查詢課本第 10-47~10-50頁

  • 藉著 inv(A)以及 det(A)函數,你可以用符號的方式求出矩陣的反矩陣以及行列式。

    >>inv(A)ans =

    [ -2/k, -1/k ][ 1, 0 ]

    >>A*ans % verify that the inverse is correctans =

    [ 1, 0 ][ 0, 1 ]

    >>det(A)ans =

    k

  • 你可以使用 MATLAB 中的矩陣方法,以符號的形式來求解線性代數方程式。在反矩陣存在的情況下,你可以使用反矩陣法,或使用左除法(請參考第6章中對於這些方法的討論)。

    >>syms c>>A = sym([2, -3; 5, c]);>>b = sym([3; 19]);>>x = inv(A)*b % the matrix inverse methodx =

    [3*c/(2*c+15)+57/(2*c+15)][23/(2*c+15)]

    >>x = A\b % the left-division methodx =

    [3*(19+c)/(2*c+15)][23/(2*c+15)]

    更多相關資料請查詢課本第10-49~10-50頁

  • 下列的投影片包含課本中本章節的圖片以及習題問題。

  • 圖P18

  • 圖P23

  • 圖P24

  • 圖P50

  • 圖P51