Anda di halaman 1dari 35

# Matlab: Symbolic Math Toolbox,

## Symbolic Math Toolbox

Permite:
Calculus integration, differentiation, Taylor series
expansion,
Linear Algebra inverses, determinants, eigenvalues,

## Simplification algebraic and trigonometric expressions

Equation Solutions algebraic and differential equations
Transforms Fourier, Laplace, Z transforms and inverse
transforms,

Symbolic
Use sym to create a symbolic number, and double
to convert to a normal number.
>> sqrt(2)
ans = 1.4142
>> var = sqrt(sym(2))
var = 2^(1/2)
>> double(var)
ans = 1.4142
>> sym(2)/sym(5) + sym(1)/sym(3)
ans = 11/15

Symbolic variables
Use syms to define symbolic variables. (Or use sym to create
an abbreviated symbol name.)
>> syms m n b c x
>> th = sym('theta')
>> sin(th)
ans = sin(theta)
>> sin(th)^2 + cos(th)^2
ans = cos(theta)^2 + sin(theta)^2
>> y = m*x + b
y = b + m*x

Expresiones simblicas
The subs function substitutes values or expressions for
variables in a symbolic expression.
>>
>>
>>
>>
>>
>>

clear
syms m x b
y = m*x + b
y = b
subs(y,x,3)
ans =
subs(y, [m b], [2 3]) ans =
subs(y, [b m x], [3 2 4]) ans

+ m*x
b + 3*m
2*x + 3
= 11

## The symbolic expression itself is unchanged.

>> y

y = b + m*x

Diferenciacin
Use diff to do symbolic differentiation.
>> clear
>> syms m x b th n y
>> y = m*x + b;
>> diff(y, x)
>> diff(y, b)
>> p = sin(th)^n
>> diff(p, th)
- 1)

ans = m
ans = 1
p = sin(th)^n
ans = n*cos(th)*sin(th)^(n

Integracin
>> clear
>> syms m b x

>> y = m*x + b;

Indefinite integrals
>> int(y, x)
b*x
>> int(y, b)
>> int(1/(1+x^2))

ans = (m*x^2)/2 +

ans = (b + m*x)^2/2
ans = atan(x)

ans = 3*b +

ans = pi/4

Definite integrals
>> int(y,x,2,5)
(21*m)/2
>> int(1/(1+x^2),x,0,1)

## Graficando expresiones simblicas

The ezplot function will plot symbolic expressions.

>>
>>
>>
>>
>>

clear; syms x y
ezplot( 1 / (5 + 4*cos(x)) );
hold on; axis equal
g = x^2 + y^2 - 3;
ezplot(g);

Solucin de Ecuaciones
diferenciales con Matlab: dsolve
y
dy
dt
2
d y
2
dt
n
d y
n
dt

y
Dy

D2y

Dny

Matlab
dy
2 y 12sin 4t
dt

y(0) 10

## >> y = dsolve('Dy + 2*y = 12*sin(4*t)',

'y(0)=10')
y=
-12/5*cos(4*t)+6/5*sin(4*t)+62/5*exp(-2*t)

## >> ezplot(y, [0 8])

>> axis([0 8 -3 10])

Matlab
2
d y
dy
3 2 y 24
2
dt
dt
y(0) 10 y '(0) 0

## >> y = dsolve('D2y + 3*Dy + 2*y = 24',

'y(0)=10', 'Dy(0)=0')
y=
12+2*exp(-2*t)-4*exp(-t)
>> ezplot(y, [0 6])

simblica con Matlab
Establezca s y t como variables
simblicas.
>> syms t s
La trasformada de laplace de una
funcin f(t) se obtiene como:
>> F = laplace(f)
Algunas simplificaciones utiles son:
>> pretty(F)
>> simplify(F)

## La trasformada inversa de Laplace

simblica con Matlab
Establish t and s as symbolic variables.
>> syms t s

## The Laplace function F is then formed and

the inverse Laplace transform command is:
>> f = ilaplace(F)

de Laplace de v(t) usando Matlab
v(t ) 3e

2 t

sin 5t 4e

2 t

cos5t

>> syms t s
>> v = 3*exp(-2*t)*sin(5*t)
+ 4*exp(-2*t)*cos(5*t)
v=
3*exp(-2*t)*sin(5*t)+4*exp(-2*t)*cos(5*t)

Ejemplo. Continuacin
>> V = laplace(v)
V =15/((s+2)^2+25)+4*(s+2)/((s+2)^2+25)
>> V=simplify(V)
V = (23+4*s)/(s^2+4*s+29)

## Ejemplo. Determine la trasformada Inversa

de Laplace de F(s) usando Matlab

100( s 3)
F ( s)
2
( s 1)( s 2)( s 2 s 5)
>> syms t s
>> F=100*(s+3)/((s+1)*(s+2)*(s^2+2*s+5))
F=
(100*s+300)/(s+1)/(s+2)/(s^2+2*s+5)

Ejemplo. Continuacin
>> f = ilaplace(F)
f = 50*exp(-t)-20*exp(-2*t)-30*exp(-t)*cos(2*t)10*exp(-t)*sin(2*t)
>> pretty(f)
50 exp(-t) - 20 exp(-2 t) - 30 exp(-t) cos(2 t) 10 exp(-t) sin(2 t)

Inversa de Laplace de F(s) usando
Matlab
10
48
Y (s)

2
s 2 ( s 2)( s 16)
>> syms t s
>> Y = 10/(s+2) + 48/((s+2)*(s^2+16))
Y =10/(s+2)+48/(s+2)/(s^2+16)

Ejemplo. Continuacin
>> y = ilaplace(Y)
y = 62/5*exp(-2*t)12/5*cos(16^(1/2)*t)+3/10*16^(1/2)*sin(16^(1/
2)*t)
>> y=simplify(y)
y = 62/5*exp(-2*t)-12/5*cos(4*t)+6/5*sin(4*t)

## Diversos comandos de Matlab para aplicarlos

en diferentes campos de la transformada de
Laplace
El comando roots determina las races de polinomios de

Ejemplo

## El comando pzmap efecta la representacin grfica de polos y ceros

en el plano s de una funcin racional previamente definida.

G(s).

Ejemplo

Ejemplo

Ejemplo

## Funciones de Trasferencia en Matlab

Ejemplos
Escribir en Matlab las siguientes funciones de trasferencia:

## Conversin de una funcin de trasferencia a

formato ganancia-polo-cero y viceversa

Ejemplo
Dada la funcin de trasferencia G(s), expresarla en formato
ganancia-polo-cero.

## Generating a Step Response in MATLAB

>>M = 1; % units of kg
>>K = 10; % units of N/m
>>B = 2; % units of N-s/m
>>num = 1;
>>den = [M B K];
>>sys = tf(num,den)
>>step(sys);

>>t=0:0.1:10;
>>step(sys,t);