Beruflich Dokumente
Kultur Dokumente
MATLAB-SIMULINK.
Ejercicio 5.
Ej: Guardarlo como
(Clase#_efren_herrera_m#.m)
Trazado de grficos:
y=[0:.1:1]
plot(y) grfico de y vs. No. de orden del vector
x=[0:.1:1]
plot(x,y) grfico de y vs. X
x1=0:10
y1=x1.^2
y2=x1+1
plot(x1,y1,x1,y2) grfico de y1 vs. X1 y de
y2 vs. X1
grid (rejilla)
xlabel(tiempo) sita el nombre al eje x
ylabel(posicin angular) sita el nombre al
eje y
title(servomecanismo de posicin)
sita nombre al grfico en la parte
superior
x= linspace(-1,3);
p = [1 4 7 10];
v = polyval(p,x);
figure(5)
plot(x,v),title(x^3+4x^2-7x-10)
xlabel(x),ylabel(v)
CREADO POR ING. EFRN HERRERA MUENTES. ESPOL-FIEC.
5/12/2017 10
MODIFICADO POR: ING. RICHARD SNCHEZ ROSADO
Grficos 2D, 3D.
x = linspace(0,2*pi,30);
y = sin(x);
z = cos(x);
figure(10)
plot(x,y,b,x,z,r.-)
legend('Seno(x)','Coseno(x)')
xlabel(x),ylabel(y)
grid
text(2,6,tiempo de establecimiento)
sita el texto en la posicin indicada
gtext(perodo de la seal)
sita el texto en la posicin seleccionada con el ratn
ginput
da un cursor que ofrece el valor que selecciona con el ratn.
Puede marcar infinitos puntos, termina dando retorno
figure(12)
subplot(221)
plot(x,y),axis([0 2*pi 1 1]), title(sin(x))
subplot(222)
plot(x,z),axis([0 2*pi 1 1]), title(cos(x))
subplot(223)
plot(x,a),axis([0 2*pi 1 1]), title(2sin(x)cos(x))
subplot(224)
plot(x,b),axis([0 2*pi 20 20]), title( sin(x)/cos(x))
polar(theta,rho)
diagrama polar,
radio rho vs. ngulo theta en radianes
figure(13)
t=linspace(0,2*pi);
r = sin(2*t).*cos(2*t);
polar(t,r)
title( Grfico polar de sin(2t)cos(2t))
Grficos tridimensionales
plot3(x1,y1,z1)
figure(14)
t= linspace(0,10*pi);
plot3(sin(t),cos(t),t)
ttle(Hlice), xlabel(sin(x)), ylabel(cos(x)), zlabel(t)
Ejemplo:
Se desea generar un juego de puntos
equidistantes en el plano x-y, entre los puntos -
7.5 y 7.5 en ambos ejes
x=-7.5:0.5:7.5;
y=x;
[X,Y] = meshgrid(x,y);
figure(16)
surf(X,Y,Z)
Dibujar un polgono
x=[1,2,1,0];
y=[0,1,2,1];
figure(17)
fill(x,y,'r')
title('rombo')
y='[10*sin(x),5*cos(x)]'
figure(18)
fplot(y,[0 4*pi -12 12])
grid
Matemtica simblica
Permite manipular expresiones que se
calculan utilizando smbolos
2
d (2 x )
2
cos( x ) v
dx
2
x
3x 5 x 1
2
f dx
1 x 2
Variables simblicas
MATLAB utiliza objetos simblicos para
representar las variables simblicas.
Las variables simblicas se crean mediante el
comando sym:
x = sym(x)
o
syms x y z
En la expresin 3 y + z, la variable
independiente es y
Aplicaciones
Diferenciacin:
Para ello se utiliza el comando diff
syms a b c d x s
f= a*x^3 + x^2 b*x c;
diff(f)
ans= 3*a*x^2 + 2*x b
diff(f,a)
ans = x^3
diff(g)
ans= [a 2*b*x]
[3*c*x^2 0]
M=[(1:8).^2]
M=
1 4 9 16 25 36 49 64
diff(M)
ans =
3 5 7 9 11 13 15
Integracin
Para ello se utiliza el comando int
syms x s m n
f = sin(s + 2*x)
int(f)
int(f,s)
ans =
- cos(s + 2*x)
int(f,pi/2,pi)
ans =
cos(s)
ezplot(y,[0 6])
Guardarlo como
(Clase#_efren_herrera_m#.m)
solve(a*x^2+b*x+c,b) % calcule b
b=
-(a*x^2+ c)/x
f=solve(cos(x)-sin(x)) % calcule x
f=
*pi
Para la ecuacin
% tan(x) = sin(2*x), la solucin se obtiene con:
t = solve(tan(x) sin(2*x))
t=
[ 0]
[ 1/4*pi ]
dy/dt= 1 +y^2
Su solucin se obtiene as:
dsolve(Dy = 1 +y^2)
ans =
tan(t-C1)
donde C1 es una constante de integracin
sea y(0) = 1.
ans =
tan(t+1/4*pi)
CREADO POR ING. EFRN HERRERA MUENTES. ESPOL-FIEC.
5/12/2017 45
MODIFICADO POR: ING. RICHARD SNCHEZ ROSADO
Grficos 2D, 3D.
y=
4/3*cos(t)-1/3*cos(2*t)
figure(21)
ezplot(y, [-6 2])
grid
Sea
x2d2y/dx2 + 7xdy/dx + 5y = 10 (4/x)
y(1) = 1, dy/dx(1) = 0.
Transformadas
Transformada de Laplace
syms a s t w
f = exp(-a*t)*cos(w*t)
L = laplace(f,t,s)
sa
ans
(( s a) w )
2 2
ilaplace(L,s,t)
ans =
exp(-a*t)*cos(w*t)
Transformada de Fourier
syms t w
f = t*exp(-t^2)
F = fourier(f,t,w)
F=
-0.5*i*pi^0.5*w*exp(-0.25*w^2)
ifourier(F,w,t)
ans:
1 1
* 4 ^ ( ) * t *exp(t ^ 2)
2 2