Professional Documents
Culture Documents
Symbolic Math Toolbox 사용법 PDF
Symbolic Math Toolbox 사용법 PDF
(2014/01/15)
(, symbolic expression )
, , , symbolic expression
MATLAB Programming
kmste2@kaist.ac.kr
MATLAB Programming
(polynomial)
MATLAB
= 1 + 2 1 + + + +1 ,
pi
= 1, 2 , , +1
y = polyval( P, X )
P X
= 3 2 2 + 1
evaluate () at = 5
>> p = [3 -2 1];
>> polyval(p,5)
ans =
66
3
MATLAB Programming
MATLAB
= 3 6 3 4 2
x 5, 3, 2, 1 ,
MATLAB 0
P = [3 0 -3 0 0 -2 0]
>> P = [3 0 -3 0 0 -2 0];
>> polyval(P, 0)
ans =
0
>> polyval(P, 1)
ans =
-2
MATLAB Programming
= 3 6 3 4 2
Y = polyval( P, X) , X , ,
Y X
P = [3 0 -3 0 0 -2 0]
>> polyval(P, magic(2))
ans =
ans =
0
1950
140
-2
11512
1938
140
MATLAB Programming
Quiz
x = 0:2:6 .
= 3 2 7 2 + 2 + 23
= 4 3 0.53 4
= 3 2 4 2
MATLAB Programming
, ?
= 3 100 3 90 + 5 23 3 3 2
, 1001 P
P = [3 0 0 0 0 0 0 0 0 0 -3 0 0 0 0 0 0 -3 0 -2 0]
!
Symbolic Math Toolbox !!
P = sym2poly( F )
>> syms x
>> f = 3*x^100 - 3*x^90 + 5*x^23 - 3*x^3 - 2*x;
>> P = sym2poly(f)
7
MATLAB Programming
P = [3 1 -1 0 -5 0]
>> P = [3 1 -1 0 -5 0];
>> poly2sym(P)
ans =
3*x^5 + x^4 - x^3 - 5*x
MATLAB Programming
convolution
C = conv( A, B )
= 4 3 2 2 + 1
F = [4 0 -2 1]
= 3 3 + 5 2 3 2 G = [3 5 -3 -2]
1
-2
4
3
-3
-3
-2
-3
-2
-3
-2
-3
-2
-3
-2
-3
-2
-2
4 x 3 = 12
0 x 3 + 4 x 5 = 20
-2 x 3 + 0 x 5 + 4 x -3 = -18
1 x 3 + -2 x 5 + 0 x -3 + 4 x -2 = -15
>> F = [4 0 -2 1];
>> G = [3 5 -3 -2];
>> conv(F,G)
ans =
1 x 5 + -2 x -3 + 0 x -2 = 11
1 x -3 + -2 x -2 = 1
12
20 -18 -15
11
-2
1 x -2 = -2
MATLAB Programming
Convolution
1. symbolic polynomial
2. symbolic polynomial
11
-2
10
MATLAB Programming
= 2 2 + 1
= 3 2 2 2
= + 1
>> A = [2 -1 1];
>> B = [1 -2 0 -2];
>> C = [1 1];
>> D = conv(conv(A,B),C)
D=
-(x + 1)*(2*x^2 - x + 1)*(- x^3 + 2*x^2 + 2)
D=
>> sym2poly(D)
2
-3
-2
-3
-4
-2
ans =
2 -3
-2
-3
-4
-2
11
MATLAB Programming
g h
= + () () ()
[q, r] = deconv( g, h )
g h , q r (q, r )
= 3 6 2 + 12 8
= 2
>> g = [1 -6 12 -8];
>> h = [1 -2];
>> [q, r] = deconv(g,h)
q=
1
-4
r=
0
12
MATLAB Programming
Quiz
g h symbolic expression
.
= 3 6 2 + 12 8
= 2
symbolic expression
, .
= 3 6 2 + 12 8
= 1
: 1
13
MATLAB Programming
Symbolic
[Q, R] = quorem( F, G )
F G F/G ,
Q, R
= 3 6 2 + 12 8
= 1
>> g = [1 -6 12 -8];
>> h = [1 -1];
>> sg = poly2sym(g); sh = poly2sym(h);
>> [q, r] = quorem(sg, sh)
q=
x^2 - 5*x + 7
r=
-1
%
>> expand(q*sh+r)
ans =
x^3 - 6*x^2 + 12*x - 8
14
MATLAB Programming
sym/coeffs
>> syms x y
>> z = 3*x^2*y^2 + 5*x*y^3
>> [c, terms] = coeffs(z)
c=
[ 3, 5]
terms =
[ x^2*y^2, x*y^3]
>> syms x y
>> z = 3*x^2*y^2 + 5*x*y^3
>> [c, terms] = coeffs(z, x)
c=
[ 3*y^2, 5*y^3]
terms =
[ x^2, x]
>> [c, terms] = coeffs(z, y)
c=
[ 5*x, 3*x^2]
terms =
[ y^3, y^2]
15
MATLAB Programming
[N, D] = numden( A )
A
N (numerator), D (denominator)
>> sym x y
>> r = 1 + x^2 / (3 + x^2/5);
r=
x^2/(x^2/5 + 3) + 1
>> [n, d] = numden( r )
n=
6*x^2 + 15
d=
x^2 + 15
16
MATLAB Programming
Taylor
F = taylor( A )
A , F
0 Taylor 5
>> syms x y z
>> f = taylor(log(1+x))
f=
x^5/5 - x^4/4 + x^3/3 - x^2/2 + x
>> ezplot( 'log(1+x)' )
>> hold on;
>> h = ezplot( f );
>> set(h, 'color', 'red');
17
MATLAB Programming
Taylor
F = taylor( A, x, a, order, n )
A x = a n
% sin(x) x=0
>> syms x;
>> f = taylor(sin(x), x, 0, 'order', 10)
f=
x^9/362880 - x^7/5040 + x^5/120 - x^3/6 + x
>> ezplot( 'sin(x)' );
>> hold on;
>> h = ezplot( f );
>> set( h, 'color', 'red' );
18
MATLAB Programming
Taylor
F = taylor( A, x, a, order, n )
A x = a n
% sin(x) x=2
>> syms x;
>> f = taylor(sin(x), x, 2, 'order', 10)
f=
x^9/362880 - x^7/5040 + x^5/120 - x^3/6 + x
>> ezplot( 'sin(x)' );
>> hold on;
>> h = ezplot( f );
>> set( h, 'color', 'red' );
>> ylim( [-5 5] )
19
MATLAB Programming
Multivariable Taylor
% 2 (x,y) = (0, 0)
>> syms x y;
>> f = x + y + 3*exp(-x^2-y^2);
>> ezsurf(f, [-1 2]);
>> g = taylor(f, [x,y], [0,0], 'order', 10);
>> hold on;
>> ezsurf(g, [-1 2]);
20
MATLAB Programming
Parametric Taylor
20
cos , =
20
sin , = ,
syms x y t
x = exp(-t/20)*cos(t);
y = exp(-t/20)*sin(t);
z = t;
figure(1);
ezplot3(x,y,z, [-10 10]);
p = [x y z];
f = taylor(p, t, 0, 'order', 30);
figure(2);
ezplot3(f(1), f(2), f(3), [-10, 10]);
21
MATLAB Programming
22
MATLAB Programming
solve
2 + + = 0
>> syms a b c x
>> f = a*x^2+b*x+c;
>> solve(f)
f==0
ans =
-(b + (b^2 - 4*a*c)^(1/2))/(2*a)
-(b - (b^2 - 4*a*c)^(1/2))/(2*a)
2 4
2
23
MATLAB Programming
solve
eg) 2 2 4 = 0
solve , symbolic ,
.
>> syms x
>> f = x^2-2*x-4;
>> solve(f==0, x)
ans =
5^(1/2) + 1
1 - 5^(1/2)
>> solve('x^2-2*x-4==0')
ans =
5^(1/2) + 1
1 - 5^(1/2)
24
MATLAB Programming
= () ,
>> syms x
>> f = cos(2*x) + sin(x) - 1
f=
cos(2*x) + sin(x) - 1
>> solve(f)
ans =
0
pi/6
(5*pi)/6
25
MATLAB Programming
, 2 log = 1 ,
>> syms x y
>> f = 2*x-log(y)-1
ans =
>> solve(f, x)
log(y)/2 + 1/2
ans =
log(y)/2 + 1/2
>> solve(f, y)
exp(2*x - 1)
ans =
exp(2*x - 1)
26
MATLAB Programming
, 2 = 2 y 2 = 5
1. ,
(y )
= 2 2 , 2 = 2 + 5
2. ,
2 2 = 2 + 5
3. (x )
= 1 2 2
4. 3
= 7 + 4 2, = 7 4 2
27
MATLAB Programming
, 2 = 2 y 2 = 5
ans =
xsols =
2*2^(1/2) + 1
1 - 2*2^(1/2)
ans =
4*2^(1/2) + 7
7 - 4*2^(1/2)
4*2^(1/2) + 7
7 - 4*2^(1/2)
28
MATLAB Programming
solve
2 = 2 y 2 = 5
%
>> sols.x(1)
>> sols.x(2)
>> syms x y
>> sols = solve( x^2 - y == 2, y - 2*x == 5 )
ans =
ans =
sols =
2*2^(1/2) + 1
1 - 2*2^(1/2)
>> sols.y(1)
>> sols.y(2)
ans =
ans =
4*2^(1/2) + 7
7 - 4*2^(1/2)
x: [2x1 sym]
y: [2x1 sym]
29
MATLAB Programming
Quiz
solve .
+ = 0
3 + 2 = 5
2 3 = 6
= 32
= 5 + 1
1 + 22 + 43 34 = 5
21 + 32 3 64 = 2
1 + 52 33 + 24 = 4
1 32 53 = 1
30
MATLAB Programming
Quiz
f(x,y) g(x,y) .
, = 4 2 + 3
2
, = 4 + 2 1
31
MATLAB Programming
Quiz
, x, y
.
= 0 cos()
= 0 sin 12 2
32
MATLAB Programming
fzero
, 2
>> syms x
>> ezplot('sin(x) - 0.5*x')
>> grid on
fzero f (, f(x) = 0)
x0 ,
2 1016 x*
33
MATLAB Programming
fzero
, 2
>> solve('sin(x)-0.5*x==0')
ans =
0
>> fzero('sin(x)-0.5*x', [1 3])
ans =
1.8955
>> fzero('sin(x)-0.5*x', [-3 -1])
ans =
-1.8955
>> fzero('sin(x)-0.5*x', [-5 -3])
Error using fzero (line 274)
The function values at the interval endpoints must differ in sign.
34
MATLAB Programming
Quiz
fzero .
x tan(x) = 0
cos(x) x = 0
35
MATLAB Programming
roots
p
z = roots( p )
z p = 0
>> syms x
>> p = sym2poly(x^2 - x - 1)
p=
1
-1
-1
>> z = roots(p)
z=
-0.6180
1.6180
36
MATLAB Programming
polyval
p
v = polyval( p, z )
%
>> syms x
>> p = sym2poly(x^2 - x - 1)
p=
1
-1
-1
>> z = roots(p)
z=
-0.6180
1.6180
%
>> polyval(p, z)
ans =
1.0e-15 *
-0.1110
0.2220
37
MATLAB Programming
38
MATLAB Programming
MATLAB
D,
2
2
D2,
3
3
D3, ,
Dn
= 2 Dy = -2xy
= 2, y 1 = 1
MATLAB Programming
Symbolic Expression
Symbolic Math D
D,
2
2
D2,
3
3
D3, ,
diff(x)
Dn
= 2, y 1 = 1
40
MATLAB Programming
+ 6 + 9 = 0, y 0 = 4, y 0 = 14
y
2
2
D2y, y
Dy
41
MATLAB Programming
+ 6 + 9 = 0, y 0 = 4, y 0 = 14
y
2
2
D2y, y
Dy
symbolic expression
>> syms x y(t)
>> D2y = diff(diff(y));
>> Dy = diff(y);
>> Dsol = dsolve(D2y+6*Dy+9*y==0, y(0)==-4, Dy(0)==14, x)
Dsol =
2*x*exp(-3*x) - 4*exp(-3*x)
42
MATLAB Programming
(D =
2 3 = 2 2
2
1
,
x
0
=
,
y
0
=
3
3
+ 4 = 3 2
x
Dx, y
Dy
>> DSol2.y
ans =
exp(2*t)/4 - exp(5*t)*((11*exp(-3*t))/12 - 1)
43
MATLAB Programming
(D =
Symbolic Expression
2 3 = 2 2
2
1
,
x
0
=
,
y
0
=
3
3
+ 4 = 3 2
x
Dx, y
Dy
44
MATLAB Programming
Quiz
symbolic expression
=
=
+ 2
(
+ 1) = 1 , (0) = 1
12
1 2
=0
45
MATLAB Programming
46
MATLAB Programming
f(t) F(s) .
f(t) F(s) .
, ,
1. f(t) F(s) ( )
2. F(s)
3. F(s) f(t)
47
MATLAB Programming
Laplace
: =
: =
= 0
+
1
%
>> syms t w
>> laplace(t^2)
%
>> syms s w
>> ilaplace( 1/s^3 )
ans =
2/s^3
ans =
t^2/2
>> laplace(cos(w*t))
ans =
s/(s^2 + w^2)
ans =
3*exp(-t*w)
>> laplace(t^1)
ans =
1/s^2
ans =
cos(2*t)
48
MATLAB Programming
Laplace
(1/2)
1 2 Laplace
2
2
= 0
= 2 (0)
+ 6 + 9 = 0, y 0 = 4, y 0 = 14
Laplace
+ 6 + 9 = + 6 + 9
= 2 0 + 6 6 0 + 9 = 0
2 + 6 + 9 = 4 + 14
4+14
2 +6+9
49
MATLAB Programming
Laplace
(2/2)
=
4+14
2 +6+9
F(s)
>> syms s
>> Y = (-4*s+14)/(s^2+6*s+9)
Y=
-(4*s - 14)/(s^2 + 6*s + 9)
>> ilaplace(Y)
ans =
26*t*exp(-3*t) - 4*exp(-3*t)
50
MATLAB Programming
Z : =
% Z
>> syms t
>> f = sin(2*t)
=
=0
% Z
>> syms z
>> f = 3*z/(z^2 - 4*z + 5);
>> f = 3*z/(z^2 - 4*z + 5)
f=
(3*z)/(z^2 - 4*z + 5)
>> ft = iztrans(f)
3
2 4 + 5
f=
sin(2*t)
ft =
((-1)^n*(- 2 - i)^(n - 1)*15*i)/4 - ((-1)^n*(- 2 + i)^(n - 1)*15*i)/4 + (3*(-1)^n*5^n*cos(n*(pi - a
>> fz = ztrans(f)
>> pretty(ft)
fz =
(z*sin(2))/(z^2 - 2*cos(2)*z + 1)
>> pretty(fz)
z sin(2)
------------------2
z - 2 cos(2) z + 1
/ /
/ 1/2 \ \ \
n n | |
|25 |||
3 (-1) 5 cos| n | pi - acos| ------ | | |
n
n-1
\ \
\ 5 / / / 15 (-1) (i - 2)
i
------------------------------------------- - ----------------------- +
1/2 n
4
2 (5 )
n
n-1
15 (-1) (- i - 2)
i
------------------------4
51
MATLAB Programming
Fourier
Fourier : =
Fourier : =
% Fourier
>> syms x u
>> f = x*exp(-abs(x))
f=
x*exp(-abs(x))
1
2
= ||
% Fourier
>> syms x
>> f = exp(-abs(x))
= ||
f=
exp(-abs(x))
>> g = fourier(f, u)
>> g = ifourier(f)
g=
-(u*4*i)/(u^2 + 1)^2
g=
>> pretty(g)
1/(pi*(t^2 + 1))
4ui
- --------2 2
(u + 1)
52
MATLAB Programming
syms
symbolic
ezplot
symbolic plotting
double
symbolic double
diff
int
limit
symsum
solve
fourier
fourier transform
ifourier
laplace
laplace transform
ilaplace
ztrans
z transformation
iztrans
inverse z transformation
collect
expand
factor
hornor
nested form
simple
simplify
pretty
symbolic
53