You are on page 1of 3

% definicin de polinomios

p1 = [1 6 5 -3];
p2 = [2 0 1 -1 1];
r1 = roots(p1)
%definicin de polinomios a travs de sus races "poly"
r3 = [-1; 0.5+i; 0.5-i]
p3 = poly(r3)
% operaciones entre polinomios
p1 = [0 p1]
psuma = p1 + p2
% convolucion
pmult = conv(p1,p2)
% derivar un polinomio
plder = polyder(p1)
% resolucin de un polinimo
polyval(p1,1)
%% Creacion de Graficas
v1 = [1 2 3 4];
v2 = [4 3 2 1];
plot(v1,v2)
hold on
plot(v1, 2* v2)
hold off
plot(-v1,v2)
% representacin de tres resultados
plot(v2,v1,v2,2*v1,v2,v1+v2)
plot(v1,v2,'ro-')
grid on
xlabel('vector 1')
ylabel('vector 2')
title('v1 vs v2')
% grafica en 3D
plot3(v1,v2,3*v2)
grid on
gtext('v1 va v2') % insertar texto con el raton

subplot(1,2,1); %dividir en dos celdas (1 fila, 2 columnas)


plot(v2,v1)
subplot(1,2,2);
plot(v2,2*v1,'r')
%% ficheros
w = linspace(1,10,100)
y = sin(w)
plot(w,y)
grid on
title('curva senoidal','Color','r')
hold on
plot(w+3,y,'*')
%axis([ xmin xmax ymin ymax])
axis([ -5 15 -2 2])
%************************************************************************
%% grafica en tiempo real
% x = t;
% y = v(t);
x = 0:45;
y = 0.2 + 3*x.^2;
hold on
grid
for i=1:length(x)-1
hold on
axis([min(x) max(x) min(y) max(y)])
plot(x(i:i+1),y(i:i+1),'linewidth',2);
pause(1)
end
hold off

%% real time
figure(2);
for i=1:1000
T(i)=cos(i);
plot(T);
drawnow;
pause(0.3)
end

%*************************************************************************
%% Abrir puerto serial

s=serial('com2');
set(s,'BaudRate', 115200);
%
set(s,'Terminator','LF','Parity', 'none'); % Default terminator is \n LF=\r
set(s, 'FlowControl', 'none');
set(s,'DataBits', 8);
set(s,'requesttosend','off');
set(s,'StopBits', 1);
warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
% get(s,{'BaudRate','DataBits','Parity','StopBits','Terminator'})
fopen(s);

You might also like