• 沒有找到結果。

MATLAB MATLAB ––符號運算功能符號運算功能

N/A
N/A
Protected

Academic year: 2021

Share "MATLAB MATLAB ––符號運算功能符號運算功能"

Copied!
21
0
0

加載中.... (立即查看全文)

全文

(1)

MATLAB

MATLAB – – 符號運算功能 符號運算功能

(參考資料:電腦在化工上之應用 逢甲大學陳奇中老師)

(2)

利用利用SymbolicSymbolic 微分微分 (Differentiate)

(Differentiate) 運算運算

• • Symbolic Math Toolbox Symbolic Math Toolbox

• Ex1: 求 之微分式

>>syms x

>>f=3*x^4-x^3+2*x^2+x+1

>>diff(f) ans =

12*x^3-3*x^2+4*x+1

1 2

3x4 - x3 + x2 + x +

(3)

Ex2: 求 之微分式

>>syms x

>>f=sin(x^2)

>>diff(f) ans=

2*cos(x^2)*x

•二次微分 diff(f,2)

>>syms a x

>>f=sin(a*x^2)

>>diff(f,2)

>>diff(f,a,2) % differentiate with respect to a )

sin(x2

(4)

利用利用SymbolicSymbolic 積分積分(Integrate) (Integrate) 運算運算

• Ex1: 求 之積分式,即

>>syms x

>>f=-2*x/(1+x^2)^2

>>int(f) ans=

1/(1+x^2)

2 2) 1

(

2 x

x + -

2 2

2 ?

(1 ) x dx x

- =

ò

+

(5)

• Ex1: 求 之值

>>syms x

>>f= x*log(1+x)

>>int(f,0,1) ans=

1/4

1

0

x ln(1 + x dx )

ò

(6)

利用利用SymbolicSymbolic 級數之和級數之和 (Summation of series) (Summation of series)

Ex1: 求

>>syms n k

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

1/2*(k+1)^2-1/2*k-1/2 若所求為

>>k=10

>>1/2*(k+1)^2-1/2*k-1/2 ans=

55

? ...

3 2 1 0

0

= +

+ + +

+

å

=

=

k

k n

n

? 10

...

3 2 1 0

10 0

= +

+ +

+

å

=

= n

n

(7)

• Ex2: 求 之值

>>

syms n

>>

symsum(1/(n*(n+1)*(n+2)),1,inf)

ans=

1/4

å

¥

=1 ( +1)( + 2) 1

n n n n

(8)

利用利用Symbolic Symbolic 展開多項式展開多項式

Ex1:

>>syms x

>>expand((x-2)*(x-4)) ans=

x^2-6*x+8 Ex2:

>>syms x y

>>expand(cos(x+y)) ans=

cos(x)*cos(y)-sin(x)*sin(y)

8 6

) 4 )(

2

(x - x - = x2 - x +

) sin(

) sin(

) cos(

) cos(

)

cos(x + y = x y - x y

(9)

利用利用Symbolic Symbolic 簡化多項式簡化多項式

Ex1:

>>syms x

>>simple(x^3+3*x^2+3*x+1) ans=

(x+1)^3 Ex2:

>>syms x

>>simple(2*cos(x)^2-sin(x)^2) ans=

3*cos(x)^2-1

3 2

3 + 3x + 3x +1 = (x +1) x

2 2

2cos ( ) sin ( ) ?x - x =

(10)

利用利用SymbolicSymbolic求求 多項式和聯立多項式和聯立 方程之解方程之解

Ex1:

>>syms a b c x

>>y=solve(a*x^2+b*x+c) y=

1/2/a*(-b+(b^2-4*a*c)^(1/2)) 1/2/a*(-b-(b^2-4*a*c)^(1/2))

% pretty 漂亮的表示式 pretty(y)

2 0, ?

ax + bx c+ = x =

a

ac b

x b

2

2 - 4

±

= -

(11)

• Ex2: 求解

>>syms x y

>>S=solve('x+y-1','x-11*y-5') S =

x: [1x1 sym]

y: [1x1 sym]

S.x = 4/3 S.y = -1/3

註:請比較[x,y]=solve('x+y-1', 'x-11*y-5')之指令

î í ì

= -

= +

5 11

1 y x

y

x

(12)

• Ex3: 求解

>>syms x y z

>>S=solve('x+y+z=1','x-y+z=2','x+y-z=-1') S =

x: [1x1 sym]

y: [1x1 sym]

z: [1x1 sym]

S.x=1/2 S.y=-1/2 S.z=1

註:請比較[x,y,z]=solve('x+y+z=1','x-y+z=2','x+y-z=-1') 之指令

ïî ïí ì

-

= -

+

= +

-

= +

+

1 2 1 z

y x

z y

x

z y

x

(13)

• Ex4: 求解

>>syms x y alpha

>>[x,y]=solve('x^2*y^2','x-y/2-alpha')

• Ex5:求解

>>syms u v a

>>[a,u,v]=solve('u^2-v^2=a^2','u+v=1','a^2-2*a=3') ïî

ïí ì

= -

=

a y

x y x

2 1

2 0

2

ïî ïí ì

= -

= +

= -

3 2

1

2

2 2

2

a a

v u

a v

u

(the results are sorted alphabetically and assigned to the outputs)

(14)

利用利用SymbolicSymbolic求極限值求極限值

lim ( ) ?

x a

f x

®

=

>> limit(f,x,a)

• Ex1:

>>syms x

>>limit(sin(x)/x,x,0)

• Ex2:

>>syms x h

>>limit((sin(x+h)-sin(x))/h,h,0)

0

sin( )

lim ?

x

x x

® =

0

sin( ) sin( )

lim ?

x

x h x

h

®

+ - =

è 1

è cos(x)

(15)

利用利用SymbolicSymbolic解微分方程式解微分方程式

Ex1: solve

>>dsolve('Dy=1+y^2')

Ex2: solve , I.C.

>>dsolve('Dy=1+y^2','y(0)=1')

Ex2: solve , I.C.

>>dsolve('(Dx)^2+x^2=1','x(0)=0')

1 y2

dt

dy = +

1 y2

dt

dy = + y(0) = 1

2 1

2

=

÷ + ø ç ö

è

æ x

dt

dx x(0) = 1

(16)

• Ex 4: solve ,

>>y=dsolve('D2y=cos(2*x)-y','y(0)=1','Dy(0)=0','x')

• Ex 5: solve

>>u=dsolve('D3u=u','u(0)=1', 'Du(0)=-1', 'D2u(0)=pi', 'x')

• Ex 6: solve , I.C.

>>[f,g]=dsolve('Df=3*f+4*g','Dg=-4*f+3*g','f(0)=0','g(0)=1') y

dx x y

d 2 = cos(2 ) -

2

, 1 ) 0

( =

y y'(0) = 0

3 ,

3

dx u u

d = u(0) =1, u'(0) = -1, u"(0) = p

ïî ïí ì

+ -

=

+

=

g dt f

dg

g dt f

df

3 4

4

3 f (0) = 0, g(0) = 1

(17)

利用利用SymbolicSymbolic求求 LaplaceLaplace轉換轉換

Ex1:

>>syms t

>>laplace(t^4) ans=

24/s^5

¥

ò

= - 0

) ( ]

[ f f t e dt

L ts

) 4

(t t

f = 5

) 24 (s s

F =

(18)

• Ex2:

>>syms t a

>>laplace(exp(-a*t)) ans=

1/(s+a)

e at

t

f ( ) = -

) (

) 1

(s s a

F = +

(19)

利用利用SymbolicSymbolic求求 反反LaplaceLaplace轉轉 換換

Ex1:

>>syms s

>>ilaplace(1/s^2) ans =

t

ò

¥

+

¥ -

- = c i

i c

stds e

s i f

f

L ( )

2 ] 1

1[

p

2

) 1

(s s

f = F(t) = t

(20)

• Ex2:

>>syms s a

>>ilaplace(1/(s-a)^2) ans =

t*exp(a*t)

)2

( ) 1

(s s a

f = - F(t) = teat

(21)

利用利用SymbolicSymbolic FourierFourier轉換轉換

Ex1:

>>syms x

>>fourier(exp(-x^2)) ans=

pi^(1/2)*exp(-1/4*w^2)

ò

¥

¥ -

= f x e- dx F(w) ( ) iwx

( ) x2

f x = e- F(w) = p e-w2 4

參考文獻

相關文件

[r]

[r]

[r]

製圖符號 能應用製圖符號繪製剖視圖。 瞭解木工製圖常 用之符號及顏色

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

各國的課程綱要均強調運算的概念性了解。我國 2009 年課程綱要談到所謂

print –dtiff my_image.tif: 將目前指定的圖形,產生 TIFF 格式的影像檔,並以my_image.tif 的檔名儲存。.

[r]