Está en la página 1de 14

16) Rotacin de una figura.

close all;
clear all;
p1=[3;0;0];
p2=[3;5;0];
p3=[3;3;4];
mtras=[1,0,0;0,1,0;0,0,1];
line([p1(1),p2(1)],[p1(2),p2(2)],[p1(3),p2(3)]);
line([p2(1),p3(1)],[p2(2),p3(2)],[p2(3),p3(3)]);
line([p1(1),p3(1)],[p1(2),p3(2)],[p1(3),p3(3)]);
axis([-5,5,-5,5,-5,5]);
grid on;
text(10,-5,0,'Eje x');
text(-5,10,0,'Eje y');
text(16,16,25,'Eje z');
title('Programa de rotacion');
pause(0.2);
for m=1:1:3 %ejes
for a=0:0.0174:30*0.0174 %Gradoa a rotar
if m==1
rxyz=[1,0,0;0,cos(a),-sin(a);0,sin(a),cos(a)];
end
if m==2
rxyz=[cos(a),0,sin(a);0,1,0;-sin(a),0,cos(a)];
end
if m==3
rxyz=[cos(a),-sin(a),0;sin(a),cos(a),0;0,0,1];
end

P1=rxyz*p1;
P2=rxyz*p2;
P3=rxyz*p3;


line([P1(1),P2(1)],[P1(2),P2(2)],[P1(3),P2(3)]);
line([P2(1),P3(1)],[P2(2),P3(2)],[P2(3),P3(3)]);
line([P1(1),P3(1)],[P1(2),P3(2)],[P1(3),P3(3)]);

axis([-5,5,-5,5,-5,5]);
grid on;
pause(0.1);
clf;
end
end











Ejecucin.


17) Rotacin de una figura con datos definidos por el usuario.
a=input('Ingrese el valor de a');
b=input('Ingrese el valor de b');
c=input('Ingrese el valor de c');
g=input('Ingrese los grados a rotar.');
[msg]=rota(a,b,c,g);

function[msg]=rota(a,b,c,g)
p1=[a+3;0;0];
p2=[a+3;b+5;0];
p3=[a+3;b+3;c+4];
mtras=[1,0,0;0,1,0;0,0,1];
line([p1(1),p2(1)],[p1(2),p2(2)],[p1(3),p2(3)]);
line([p2(1),p3(1)],[p2(2),p3(2)],[p2(3),p3(3)]);
line([p1(1),p3(1)],[p1(2),p3(2)],[p1(3),p3(3)]);
axis([-40,40,-40,40,-40,40]);
grid on;
text(10,-5,0,'Eje x');
text(-5,10,0,'Eje y');
text(16,16,25,'Eje z');
title('Programa de rotacion');
pause(0.2);
for m=1:1:3 %ejes
for a=0:0.0174:g*0.0174 %Gradoa a rotar
if m==1
rxyz=[1,0,0;0,cos(a),-sin(a);0,sin(a),cos(a)];
end
if m==2
rxyz=[cos(a),0,sin(a);0,1,0;-sin(a),0,cos(a)];
end
if m==3
rxyz=[cos(a),-sin(a),0;sin(a),cos(a),0;0,0,1];
end

P1=rxyz*p1;
P2=rxyz*p2;
P3=rxyz*p3;

line([P1(1),P2(1)],[P1(2),P2(2)],[P1(3),P2(3)]);
line([P2(1),P3(1)],[P2(2),P3(2)],[P2(3),P3(3)]);
line([P1(1),P3(1)],[P1(2),P3(2)],[P1(3),P3(3)]);

axis([-40,40,-40,40,-40,40])
grid on;
pause(0.1);
clf;

end
end
msg='Rotacion terminada';
disp(msg)

function[msg]=rota(a,b,c,g)
p1=[a+3;0;0];
p2=[a+3;b+5;0];
p3=[a+3;b+3;c+4];
mtras=[1,0,0;0,1,0;0,0,1];
line([p1(1),p2(1)],[p1(2),p2(2)],[p1(3),p2(3)]);
line([p2(1),p3(1)],[p2(2),p3(2)],[p2(3),p3(3)]);
line([p1(1),p3(1)],[p1(2),p3(2)],[p1(3),p3(3)]);
axis([-40,40,-40,40,-40,40]);
grid on;
text(10,-5,0,'Eje x');
text(-5,10,0,'Eje y');
text(16,16,25,'Eje z');
title('Programa de rotacion');
pause(0.2);
for m=1:1:3 %ejes
for a=0:0.0174:g*0.0174 %Gradoa a rotar
if m==1
rxyz=[1,0,0;0,cos(a),-sin(a);0,sin(a),cos(a)];
end
if m==2
rxyz=[cos(a),0,sin(a);0,1,0;-sin(a),0,cos(a)];
end
if m==3
rxyz=[cos(a),-sin(a),0;sin(a),cos(a),0;0,0,1];
end

P1=rxyz*p1;
P2=rxyz*p2;
P3=rxyz*p3;

line([P1(1),P2(1)],[P1(2),P2(2)],[P1(3),P2(3)]);
line([P2(1),P3(1)],[P2(2),P3(2)],[P2(3),P3(3)]);
line([P1(1),P3(1)],[P1(2),P3(2)],[P1(3),P3(3)]);

axis([-40,40,-40,40,-40,40])
grid on;
pause(0.1);
clf;

end
end
msg='Rotacion terminada';
disp(msg)
Ejecucin.
a=input('Ingrese el valor de a');
b=input('Ingrese el valor de b');
c=input('Ingrese el valor de c');
g=input('Ingrese los grados a rotar.');

[msg]=rota(a,b,c,g);




18) Programa que captura texto y lo copia.
function[msg]=rota(a,b,c,g)
p1=[a+3;0;0];
p2=[a+3;b+5;0];
p3=[a+3;b+3;c+4];
mtras=[1,0,0;0,1,0;0,0,1];
line([p1(1),p2(1)],[p1(2),p2(2)],[p1(3),p2(3)]);
line([p2(1),p3(1)],[p2(2),p3(2)],[p2(3),p3(3)]);
line([p1(1),p3(1)],[p1(2),p3(2)],[p1(3),p3(3)]);
axis([-40,40,-40,40,-40,40]);
grid on;
text(10,-5,0,'Eje x');
text(-5,10,0,'Eje y');
text(16,16,25,'Eje z');
title('Programa de rotacion');
pause(0.2);
for m=1:1:3 %ejes
for a=0:0.0174:g*0.0174 %Gradoa a rotar
if m==1
rxyz=[1,0,0;0,cos(a),-sin(a);0,sin(a),cos(a)];
end
if m==2
rxyz=[cos(a),0,sin(a);0,1,0;-sin(a),0,cos(a)];
end
if m==3
rxyz=[cos(a),-sin(a),0;sin(a),cos(a),0;0,0,1];
end

P1=rxyz*p1;
P2=rxyz*p2;
P3=rxyz*p3;

line([P1(1),P2(1)],[P1(2),P2(2)],[P1(3),P2(3)]);
line([P2(1),P3(1)],[P2(2),P3(2)],[P2(3),P3(3)]);
line([P1(1),P3(1)],[P1(2),P3(2)],[P1(3),P3(3)]);

axis([-40,40,-40,40,-40,40])
grid on;
pause(0.1);
clf;

end
end
msg='Rotacion terminada';
disp(msg)





Ejecucin.


19) Programa que calcula la derivada e integral de una funcin.
function varargout = prog2(varargin)
% PROG2 MATLAB code for prog2.fig
% PROG2, by itself, creates a new PROG2 or raises the existing
% singleton*.
%
% H = PROG2 returns the handle to a new PROG2 or the handle to
% the existing singleton*.
%
% PROG2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PROG2.M with the given input arguments.
%
% PROG2('Property','Value',...) creates a new PROG2 or raises the
% existing singleton*. Starting from the left, property value pairs
are
% applied to the GUI before prog2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to prog2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only
one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help prog2

% Last Modified by GUIDE v2.5 11-May-2014 14:55:07

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @prog2_OpeningFcn, ...
'gui_OutputFcn', @prog2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before prog2 is made visible.
function prog2_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to prog2 (see VARARGIN)

% Choose default command line output for prog2
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes prog2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = prog2_OutputFcn(~, ~, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in Calculos.
function Calculos_Callback(~, ~, handles)
res=get(handles.funcion,'String');
syms x;
d=diff(res,x);
i=int(res ,x);
set(handles.integral,'String',char(i))
set(handles.derivada,'String',char(d))
% hObject handle to Calculos (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in reset.
function reset_Callback(~, ~, handles)
set(handles.funcion,'String','')
set(handles.integral,'String','')
set(handles.derivada,'String','')
% hObject handle to reset (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)



function funcion_Callback(~, ~, ~)
% hObject handle to funcion (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of funcion as text
% str2double(get(hObject,'String')) returns contents of funcion as
a double


% --- Executes during object creation, after setting all properties.
function funcion_CreateFcn(hObject, ~, ~)
% hObject handle to funcion (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

Ejecucin.


20) Calculadora.
function varargout = calculadora(varargin)
% CALCULADORA MATLAB code for calculadora.fig
% CALCULADORA, by itself, creates a new CALCULADORA or raises the
existing
% singleton*.
%
% H = CALCULADORA returns the handle to a new CALCULADORA or the
handle to
% the existing singleton*.
%
% CALCULADORA('CALLBACK',hObject,eventData,handles,...) calls the
local
% function named CALLBACK in CALCULADORA.M with the given input
arguments.
%
% CALCULADORA('Property','Value',...) creates a new CALCULADORA or
raises the
% existing singleton*. Starting from the left, property value pairs
are
% applied to the GUI before calculadora_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to calculadora_OpeningFcn via
varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only
one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help calculadora

% Last Modified by GUIDE v2.5 11-May-2014 16:15:41

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @calculadora_OpeningFcn, ...
'gui_OutputFcn', @calculadora_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before calculadora is made visible.
function calculadora_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to calculadora (see VARARGIN)

% Choose default command line output for calculadora
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes calculadora wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = calculadora_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in uno.
function uno_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'1');
set(handles.res,'String',textString)
% hObject handle to uno (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in dos.
function dos_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'2');
set(handles.res,'String',textString)
% hObject handle to dos (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in tres.
function tres_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'3');
set(handles.res,'String',textString)
% hObject handle to tres (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in cuatro.
function cuatro_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'4');
set(handles.res,'String',textString)
% hObject handle to cuatro (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in cinco.
function cinco_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'5');
set(handles.res,'String',textString)
% hObject handle to cinco (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in seis.
function seis_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'6');
set(handles.res,'String',textString)
% hObject handle to seis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in siete.
function siete_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'7');
set(handles.res,'String',textString)
% hObject handle to siete (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in ocho.

function ocho_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'8');
set(handles.res,'String',textString)
% hObject handle to ocho (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in nueve.
function nueve_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'9');
set(handles.res,'String',textString)
% hObject handle to nueve (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in cero.
function cero_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'0');
set(handles.res,'String',textString)
% hObject handle to cero (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in sum.
function sum_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'+');
set(handles.res,'String',textString)
% hObject handle to sum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in resta.
function resta_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'-');
set(handles.res,'String',textString)
% hObject handle to resta (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in mul.
function mul_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'*');
set(handles.res,'String',textString)
% hObject handle to mul (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in div.
function div_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'/');
set(handles.res,'String',textString)
% hObject handle to div (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in pot.
function pot_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=strcat(textString,'^');
set(handles.res,'String',textString)
% hObject handle to pot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in borrar.
function borrar_Callback(hObject, eventdata, handles)
ini=char(' ');
set(handles.res,'String',ini);
% hObject handle to borrar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in igual.
function igual_Callback(hObject, eventdata, handles)
textString=get(handles.res,'String');
textString=eval(textString,'1');
set(handles.res,'String',textString)
% hObject handle to igual (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Ejecucin.

También podría gustarte