0% found this document useful (0 votes)
59 views11 pages

Control Automático #1

The document introduces MATLAB through examples of basic operations, functions, and plots. It discusses: 1) Examples of basic operations like assigning values, arrays, and mathematical operations. 2) Examples of user-defined functions and plotting functions. Functions are defined to calculate values and plot results. 3) Exercises implementing user-defined functions to calculate values, find minimums, create step and Dirac comb signals, and plot the results. Functions are defined and values/plots are generated.

Uploaded by

sssnash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views11 pages

Control Automático #1

The document introduces MATLAB through examples of basic operations, functions, and plots. It discusses: 1) Examples of basic operations like assigning values, arrays, and mathematical operations. 2) Examples of user-defined functions and plotting functions. Functions are defined to calculate values and plot results. 3) Exercises implementing user-defined functions to calculate values, find minimums, create step and Dirac comb signals, and plot the results. Functions are defined and values/plots are generated.

Uploaded by

sssnash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 11

CAPITULO 1

INTRODUCCIÓN A MATLAB

1. Ejemplos

a=1
a= a=1;b=2
1 b=
2
b=[1 2] A=[a+b pi 3
b= b^2 0 atan(a)
2 5 sin(b) -1]
A=
a=2+i 3.0000 3.1416 3.0000
a= 4.0000 0 0.7854
2.0000 + 1.0000i 5.0000 0.9093 -1.0000

b=-5-3*i B=zeros()
b= B=
-5.0000 - 3.0000i 0

a==1 B=zeros(2,3)
ans = B=
0 0 0 0
0 0 0
v=[1 2 3 4 5]
v= A=[2 2 3;0 0 7;5 9 -1]
1 2 3 4 5 A=
2 2 3
v=1:5 0 0 7
v= 5 9 -1
1 2 3 4 5
B=zeros(size(A))
A=[2 2 3 B=
007 0 0 0
5 9 -1] 0 0 0
A= 0 0 0
2 2 3
0 0 7 C=ones(2,3)
5 9 -1 C=
1 1 1
A=[2 2 3 ; 0 0 7 ; 5 9 -1] 1 1 1
A=
2 2 3 D=diag(1:5)
0 0 7 D=
5 9 -1 1 0 0 0 0
0 2 0 0 0
0 0 3 0 0
0 0 0 4 0
0 0 0 0 5

A=[1 2 3 C=[1 2 0;0 0 1;0 2 3]


456 C=
7 8 9] 1 2 0
A= 0 0 1
1 2 3 0 2 3
4 5 6 D=A*C
7 8 9 D=
1 2 0
B=diag(A) 0 6 11
B= 5 18 12
1
5 A=[1 0 0;0 2 3;5 0 4]
9 A=
1 0 0
C=diag(diag(A)) 0 2 3
C= 5 0 4
1 0 0
0 5 0 B=[2 0 0;0 2 2;0 0 3]
0 0 9 B=
2 0 0
A=diag(ones(1,3)) 0 2 2
A= 0 0 3
1 0 0
0 1 0 C=A.*B
0 0 1 C=
2 0 0
A=eye(3) 0 4 6
A= 0 0 12
1 0 0
0 1 0 a=C(2,:)
0 0 1 a=
0 4 6
B=A+A
B= b=C(:,3)
2 0 0 b=
0 2 0 0
0 0 2 6
12
C=B+1
C= A=[1 2 3;4 5 6;7 8 9]
3 1 1 A=
1 3 1 1 2 3
1 1 3 4 5 6
7 8 9
A=[1 0 0;0 2 3;5 0 4] t=trace(A)
A= t=
1 0 0 15
0 2 3
5 0 4 r=rank(A)
r=
2 p1=poly(v)
p1 =
B=A' 1 1 0
B=
1 4 7 p2=poly([1 2 1])
2 5 8 p2 =
3 6 9 1 -4 5 -2

A=[0 1;-2 -3] p=roots(p1)


A= p=
0 1 0
-2 -3 -1

B=inv(A) A=[0 1;-2 -3]


B= A=
-1.5000 -0.5000 0 1
1.0000 0 -2 -3

A*B r=eig(A)
ans = r=
1 0 -1
0 1 -2

d=det(A) [V D]=eig(A)
d= V=
2 0.7071 -0.4472
-0.7071 0.8944
v=[0 -1] D=
v= -1 0
0 -1 0 -2

2. Ejercicios

Definicion de función mifuntion.m

function[y]=mifuntion(x)

if x<0
y=x^2
else
y=sin(x*(pi/180))
end

Evaluando

y=mifuntion(30)
y=
0.5000
y=
0.5000

Ploteando

Plot(x,y)
1.5

0.5

-0.5
0 5 10 15 20 25 30 35 40 45 50

mifuntion2.m

function[y]=mifuntion2(x)

y=x+x.^2+sin((2*pi)*x)

x=[-2:0.5:3];
y=mifuntion2(x);

Ploteando

plot(x,y)

12

10

-2
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 3
figure(1)
plot(x,y,'r')

12

10

-2
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 3

figure(2)
plot(x,y,'b:')

12

10

-2
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 3
a) Implemente en Matlab la siguiente función, luego plotee

mifuntion4.m

function[y]=mifuntion4(x)

if x==1
y='error';
elseif x==-1
y='error';
else
y= 1./((x.^2)-1)
end

x=[2:6];

y=mifuntion4(x)
y=

0.3333 0.1250 0.0667 0.0417 0.0286

plot(x,y)

0.35

0.3

0.25

0.2

0.15

0.1

0.05

0
2 2.5 3 3.5 4 4.5 5 5.5 6
b) Implementando en Matlab y plotee

funtion5.m

function[y] =funtion5(x1,x2)

if x1>0
if x2>0
y=x1+x2
else
y=x1.^2+x2.^2
y=sqrt(y)
end
else
y=x1.^2+x2.^2
y=sqrt(y)
end

x1=[0:5];
x2=[0:5];
y=funtion5(x1,x2);

plot(x1,y)
8

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

plot(x2,y,'r')

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

c) Construya una función escalar que ayude a encontrar el mínimo de f(x) = x 3-2x-5,
dentro del intervalo (0,2)
funtion6.m
function[y]=funtion6(x)
y=x.^3-2.*x-5;
y=min(y)

x=[0:2]
x=
0 1 2
y=funtion6(x)
y=
-6
y=
-6

plot(x,y)

min(y)

y=

-6

d) Construya una señal escalón unitario de 0 a 50 segundos, con step inicial en 25s. El
paso deberá ser de 0.5s. Ploteee resultado

funtion7.m

function y = funtion7(t,to)
[m,n] = size(t);
y = zeros(m,n);
i = find(t>=to);
if isempty(i)
return
end
i = i(1);
if m == 1
y(i:n) = ones(1,n-i+1);
else
y(i:m) = ones(m-i+1,1);
end

xlabel('t');ylabel('x(t)');axis([-5 50 0 1.5])

x=[0:0.5:50];
y=funtion7(x,25);
plot(x,y)

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
0 5 10 15 20 25 30 35 40 45 50

e) Construya la señal peine de dirac Plotee el resultado

dirac.m

function y = dirac(x1,x2)
stem(x1,x2)
xlabel('x');ylabel('?');title('PEINE DE DIRAC')

y=ones(1,5);
x2=[1:5];
y=dirac(x2,y);
plot(x2,y)
PEINE DE DIRAC
1

0.9

0.8

0.7

0.6

0.5
?

0.4

0.3

0.2

0.1

0
1 1.5 2 2.5 3 3.5 4 4.5 5
x

You might also like