0% encontró este documento útil (0 votos)
56 vistas29 páginas

Sistemas de Ecuaciones en C y Matlab

Este documento presenta un informe sobre la programación de sistemas de ecuaciones lineales en C y Matlab. Incluye objetivos, marco teórico sobre ecuaciones y sistemas lineales, y marco práctico con ejemplos de códigos y capturas de pantalla de resultados.

Cargado por

David Angel
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
56 vistas29 páginas

Sistemas de Ecuaciones en C y Matlab

Este documento presenta un informe sobre la programación de sistemas de ecuaciones lineales en C y Matlab. Incluye objetivos, marco teórico sobre ecuaciones y sistemas lineales, y marco práctico con ejemplos de códigos y capturas de pantalla de resultados.

Cargado por

David Angel
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd

INTEGRANTES: Raul Angel Arratia Torrez

David Angel Aruquipa Alcon


Boris Romero Salas
MATERIA: ETN 505
FECHA: 22 DE JULIO 2017
GRUPO: 18
INFORME #4

Objetivos
Programar en C y Matlab sistemas de ecuaciones lineales que sean basados en los anteriores
programas presentados

Marco Teórico

1. Ecuaciones lineales
Definición 1.1 Una ecuación lineal, con n incógnitas, es una expresión del
tipo
a1 x1 + a2 x2 + · · · + an xn = b
donde las incógnitas x1, x2, · · · , xn están sometidas a operaciones de suma y
producto por números.
No son lineales por ejemplo las ecuaciones:
x2 − y + 5 = 0
p
x + 2y = 1 ln x + 2 = y
Un sistema lineal es aquel que consta ´únicamente de ecuaciones lineales, como
por ejemplo
3x − 2y + 4z = 3
y − 17z = −33
20y − 19z = −18
o por ejemplo
x + 2y − 3z + t = 34
2x + y + z − 2t = 5
El problema central del ´algebra lineal es la resolución de sistemas de ecuaciones
lineales.

2. Sistemas de ecuaciones lineales


Definición 2.1 Un sistema de m ecuaciones lineales con n incógnitas se
escribe de forma genérica como:
(S) _
a11x1 +a12x2 +a13x3 +· · · +a1nxn = b1
a21x1 +a22x2 +a23x3 +· · · +a2nxn = b2
·········
...···=···
am1x1 +am2x2 +am3x3 +· · · +amnxn = bm
9>>=
>>;
A toda n−tupla (x1, x2, · · · , xn) que cumpla las ecuaciones de (S) se le llama
solución del sistema.
Los sistemas más fáciles de resolver son los sistemas triangulares.
Ejemplo 2.1. Resolver el sistema
2x + y + z = 1
y + 2z = 4
4z = 4
9=
;
Solución:
Primero hallamos z en la tercera ecuación, z = 1.
Sustituyendo en la segunda ecuación obtenemos, y = 2; y sustituyendo la
primera ecuación da x = −1. A este mecanismo lo llamamos sustitución
hacia atrás.

Ejemplo 2.2. Obtener un sistema triangular a partir del sistema de 3 ecuaciones


con tres incógnitas:
2x + y + z = 1
4x + y = −2
−2x + 2y + z = 7
9=
;
Restamos de la segunda ecuación, la primera multiplicada por 2, y
sumamos a la tercera ecuación, la primera. Obtenemos así un sistema
equivalente al anterior:
2x + y + z = 1
− y − 2z = −4
3y + 2z = 8
9=
;
Ahora, con la segunda y tercera ecuación eliminamos y,
Sumamos a la tercera ecuación la segunda multiplicada por 3:
2x + y + z = 1
− y − 2z = −4
− 4z = −4
9=
;
La solución como antes es, z = 1, y = 2 y x = −1. Al proceso seguido se le
llama eliminación gaussiana o método de Gauss . Cuando el sistema tiene
solución decimos que es compatible.

En Matlab
Marco Práctico

Las aplicaciones lo realizamos con archivos .exe a continuación mostramos en imágenes el


funcionamiento, en específico los resultados que nos mostraban al ingresar valores aleatorios.

Para la Bisección
Ecuación 2x2

Ecuación segundo grado


En C

Resolución de ecuación de segundo grado

Hallando raíces de una ecuación de segundo grado

Una vez introducidos los datos se obtiene los resultados

Sistema de ecuaciones por Gauss Jordan


Un Flujograma de la resolución de ecuación de segundo grado
Codigos

En Matlab

Para Biseccion
function varargout = BISECCION(varargin)
% BISECCION MATLAB code for BISECCION.fig
% BISECCION, by itself, creates a new BISECCION or raises the existing
% singleton*.
%
% H = BISECCION returns the handle to a new BISECCION or the handle to
% the existing singleton*.
%
% BISECCION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in BISECCION.M with the given input arguments.
%
% BISECCION('Property','Value',...) creates a new BISECCION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before BISECCION_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to BISECCION_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 BISECCION

% Last Modified by GUIDE v2.5 20-Jul-2017 16:43:27

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @BISECCION_OpeningFcn, ...
'gui_OutputFcn', @BISECCION_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 BISECCION is made visible.


function BISECCION_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 BISECCION (see VARARGIN)

% Choose default command line output for BISECCION


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);
% UIWAIT makes BISECCION wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = BISECCION_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;

function funcion_Callback(hObject, eventdata, handles)


% 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, eventdata, handles)
% 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

function liminf_Callback(hObject, eventdata, handles)


% hObject handle to liminf (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 liminf as text


% str2double(get(hObject,'String')) returns contents of liminf as a double

% --- Executes during object creation, after setting all properties.


function liminf_CreateFcn(hObject, eventdata, handles)
% hObject handle to liminf (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
function limsup_Callback(hObject, eventdata, handles)
% hObject handle to limsup (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 limsup as text


% str2double(get(hObject,'String')) returns contents of limsup as a double

% --- Executes during object creation, after setting all properties.


function limsup_CreateFcn(hObject, eventdata, handles)
% hObject handle to limsup (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

function tolerancia_Callback(hObject, eventdata, handles)


% hObject handle to tolerancia (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 tolerancia as text


% str2double(get(hObject,'String')) returns contents of tolerancia as a double

% --- Executes during object creation, after setting all properties.


function tolerancia_CreateFcn(hObject, eventdata, handles)
% hObject handle to tolerancia (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

% --- Executes on button press in pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
f=get(handles.funcion,'String');
a=get(handles.liminf,'String');
b=get(handles.limsup,'String');
t=get(handles.tolerancia,'String');
f=inline(f);
xai=str2num(a)
xbi=str2num(b)
tol=str2num(t)
i=1;
ea(1)=100;
if f(xai)*f(xbi)<0
xa(1)=xai;
xb(1)=xbi;
xr(1)=(xa(1)+xb(1))/2;
while abs (ea(i))>=tol
if f(xa(i))*f(xr(i))<0
xa(i+1)=xa(i);
xb(i+1)=xr(i);
end
if f(xa(i))*f(xr(i))>0
xa(i+1)=xr(i);
xb(i+1)=xb(i);
end
xr(i+1)=(xa(i+1)+xb(i+1))/2;
ea(i+1)=abs((xr(i+1)-xr(i))/(xr(i+1))*100);
i=i+1
end
r=num2str(xr(i));
set(handles.raiz,'string',r);
fplot(handles.grafica,f,[xai xbi]);
else
errordlg('NO EXISTE UNA RAIZ EN ESTE INTERVALO');
end

function raiz_Callback(hObject, eventdata, handles)


% hObject handle to raiz (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 raiz as text


% str2double(get(hObject,'String')) returns contents of raiz as a double

% --- Executes during object creation, after setting all properties.


function raiz_CreateFcn(hObject, eventdata, handles)
% hObject handle to raiz (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

Ecuaciones 2x2
function varargout = ECUACIONES2X2(varargin)
% ECUACIONES2X2 MATLAB code for ECUACIONES2X2.fig
% ECUACIONES2X2, by itself, creates a new ECUACIONES2X2 or raises the existing
% singleton*.
%
% H = ECUACIONES2X2 returns the handle to a new ECUACIONES2X2 or the handle to
% the existing singleton*.
%
% ECUACIONES2X2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ECUACIONES2X2.M with the given input arguments.
%
% ECUACIONES2X2('Property','Value',...) creates a new ECUACIONES2X2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ECUACIONES2X2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ECUACIONES2X2_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 ECUACIONES2X2

% Last Modified by GUIDE v2.5 17-Jul-2017 13:23:05

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ECUACIONES2X2_OpeningFcn, ...
'gui_OutputFcn', @ECUACIONES2X2_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 ECUACIONES2X2 is made visible.


function ECUACIONES2X2_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 ECUACIONES2X2 (see VARARGIN)

% Choose default command line output for ECUACIONES2X2


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes ECUACIONES2X2 wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = ECUACIONES2X2_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;

function edit2_Callback(hObject, eventdata, handles)


% hObject handle to edit2 (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 edit2 as text


% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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

function edit3_Callback(hObject, eventdata, handles)


% hObject handle to edit3 (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 edit3 as text


% str2double(get(hObject,'String')) returns contents of edit3 as a double

% --- Executes during object creation, after setting all properties.


function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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

function variable4_Callback(hObject, eventdata, handles)


% hObject handle to variable4 (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 variable4 as text


% str2double(get(hObject,'String')) returns contents of variable4 as a double

% --- Executes during object creation, after setting all properties.


function variable4_CreateFcn(hObject, eventdata, handles)
% hObject handle to variable4 (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

function edit5_Callback(hObject, eventdata, handles)


% hObject handle to edit5 (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 edit5 as text


% str2double(get(hObject,'String')) returns contents of edit5 as a double

% --- Executes during object creation, after setting all properties.


function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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

function edit6_Callback(hObject, eventdata, handles)


% hObject handle to edit6 (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 edit6 as text


% str2double(get(hObject,'String')) returns contents of edit6 as a double

% --- Executes during object creation, after setting all properties.


function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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

function edit7_Callback(hObject, eventdata, handles)


% hObject handle to edit7 (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 edit7 as text


% str2double(get(hObject,'String')) returns contents of edit7 as a double

% --- Executes during object creation, after setting all properties.


function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (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

function edit8_Callback(hObject, eventdata, handles)


% hObject handle to edit8 (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 edit8 as text


% str2double(get(hObject,'String')) returns contents of edit8 as a double

% --- Executes during object creation, after setting all properties.


function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (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

function edit9_Callback(hObject, eventdata, handles)


% hObject handle to edit9 (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 edit9 as text


% str2double(get(hObject,'String')) returns contents of edit9 as a double

% --- Executes during object creation, after setting all properties.


function edit9_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit9 (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

% --- Executes on button press in pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
variable1=str2double(get(handles.variable1,'String'));
variable2=str2double(get(handles.variable2,'String'));
variable3=str2double(get(handles.variable3,'String'));
variable4=str2double(get(handles.variable4,'String'));
variable5=str2double(get(handles.variable5,'String'));
variable6=str2double(get(handles.variable6,'String'));

a=[variable1 variable4; variable2 variable5]


b=[variable3; variable6]
r=(a^-1)*b
x=r(1,1)
y=r(2,1)
set(handles.edit8,'String',x,'TooltipString','resultado1');
set(handles.edit9,'String',y,'TooltipString','resultado2');

function variable1_Callback(hObject, eventdata, handles)


% hObject handle to variable1 (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 variable1 as text


% str2double(get(hObject,'String')) returns contents of variable1 as a double

% --- Executes during object creation, after setting all properties.


function variable1_CreateFcn(hObject, eventdata, handles)
% hObject handle to variable1 (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

function variable2_Callback(hObject, eventdata, handles)


% hObject handle to variable2 (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 variable2 as text


% str2double(get(hObject,'String')) returns contents of variable2 as a double

% --- Executes during object creation, after setting all properties.


function variable2_CreateFcn(hObject, eventdata, handles)
% hObject handle to variable2 (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

function variable3_Callback(hObject, eventdata, handles)


% hObject handle to variable3 (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 variable3 as text


% str2double(get(hObject,'String')) returns contents of variable3 as a double
% --- Executes during object creation, after setting all properties.
function variable3_CreateFcn(hObject, eventdata, handles)
% hObject handle to variable3 (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

function variable5_Callback(hObject, eventdata, handles)


% hObject handle to variable5 (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 variable5 as text


% str2double(get(hObject,'String')) returns contents of variable5 as a double

% --- Executes during object creation, after setting all properties.


function variable5_CreateFcn(hObject, eventdata, handles)
% hObject handle to variable5 (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

function variable6_Callback(hObject, eventdata, handles)


% hObject handle to variable6 (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 variable6 as text


% str2double(get(hObject,'String')) returns contents of variable6 as a double

% --- Executes during object creation, after setting all properties.


function variable6_CreateFcn(hObject, eventdata, handles)
% hObject handle to variable6 (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
Ecuación de segundo grado
function varargout = segundo_grado(varargin)
% SEGUNDO_GRADO MATLAB code for segundo_grado.fig
% SEGUNDO_GRADO, by itself, creates a new SEGUNDO_GRADO or raises the existing
% singleton*.
%
% H = SEGUNDO_GRADO returns the handle to a new SEGUNDO_GRADO or the handle to
% the existing singleton*.
%
% SEGUNDO_GRADO('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SEGUNDO_GRADO.M with the given input arguments.
%
% SEGUNDO_GRADO('Property','Value',...) creates a new SEGUNDO_GRADO or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before segundo_grado_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to segundo_grado_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 segundo_grado

% Last Modified by GUIDE v2.5 19-Jul-2017 19:30:20

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @segundo_grado_OpeningFcn, ...
'gui_OutputFcn', @segundo_grado_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 segundo_grado is made visible.


function segundo_grado_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 segundo_grado (see VARARGIN)

% Choose default command line output for segundo_grado


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes segundo_grado wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = segundo_grado_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;

function coeficiente1_Callback(hObject, eventdata, handles)


% hObject handle to coeficiente1 (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 coeficiente1 as text


% str2double(get(hObject,'String')) returns contents of coeficiente1 as a double

% --- Executes during object creation, after setting all properties.


function coeficiente1_CreateFcn(hObject, eventdata, handles)
% hObject handle to coeficiente1 (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

function coeficiente2_Callback(hObject, eventdata, handles)


% hObject handle to coeficiente2 (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 coeficiente2 as text


% str2double(get(hObject,'String')) returns contents of coeficiente2 as a double

% --- Executes during object creation, after setting all properties.


function coeficiente2_CreateFcn(hObject, eventdata, handles)
% hObject handle to coeficiente2 (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

function coeficiente3_Callback(hObject, eventdata, handles)


% hObject handle to coeficiente3 (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 coeficiente3 as text


% str2double(get(hObject,'String')) returns contents of coeficiente3 as a double

% --- Executes during object creation, after setting all properties.


function coeficiente3_CreateFcn(hObject, eventdata, handles)
% hObject handle to coeficiente3 (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

function edit4_Callback(hObject, eventdata, handles)


% hObject handle to edit4 (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 edit4 as text


% str2double(get(hObject,'String')) returns contents of edit4 as a double

% --- Executes during object creation, after setting all properties.


function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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

function edit5_Callback(hObject, eventdata, handles)


% hObject handle to edit5 (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 edit5 as text


% str2double(get(hObject,'String')) returns contents of edit5 as a double

% --- Executes during object creation, after setting all properties.


function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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

% --- Executes on button press in pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
coeficiente1=str2double(get(handles.coeficiente1,'String'));
coeficiente2=str2double(get(handles.coeficiente2,'String'));
coeficiente3=str2double(get(handles.coeficiente3,'String'));

d=(coeficiente2)^2-4*(coeficiente1)*(coeficiente3);
if d>0
x0=(-(coeficiente2)+sqrt(d))/(2*(coeficiente1));
x1=(-(coeficiente2)-sqrt(d))/(2*(coeficiente1));
errordlg('valor positivo de la raiz')
elseif d==0
x0=-(coeficiente2)/(2*(coeficiente1));
x1=-(coeficiente2)/(2*(coeficiente1));
errordlg('la raiz vale 0')
else
x0=-coeficiente2/(2*(coeficiente1));
j0=i*sqrt(d)/(2*(coeficiente1));
x1=-(coeficiente2)/(2*(coeficiente1));
j1=-i*sqrt(d)/(2*(coeficiente1));
msgbox('la raiz es negativa')
end
set(handles.edit4,'String',x0,'TooltipString','raiz1');
set(handles.edit6,'String',x1,'TooltipString','raiz2');
set(handles.edit5,'String',j0,'TooltipString','raiz3');
set(handles.edit7,'String',j1,'TooltipString','raiz4');

function edit6_Callback(hObject, eventdata, handles)


% hObject handle to edit6 (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 edit6 as text


% str2double(get(hObject,'String')) returns contents of edit6 as a double

% --- Executes during object creation, after setting all properties.


function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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

function edit7_Callback(hObject, eventdata, handles)


% hObject handle to edit7 (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 edit7 as text


% str2double(get(hObject,'String')) returns contents of edit7 as a double

% --- Executes during object creation, after setting all properties.


function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (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

En C

Resolucion de ecuacion de Segundo grado

#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <Windows.h>
#include <cstdlib>
////////////////A
//double a,b,c,operacion,OP,x,r,m,s,d,f;
int respuesta;
////////////////////////B
//double re,con;
//double r3,esf,h,v1,v2,r2;
float num;
///////////////////E
//float voltaje;
//float intensidad;
//float resistencia;
int eleccion;
//////////////////////
float a,b,c,g,f;
float D,R,I;
/////////////////////
/////////////////////////////////////////
int main() //comienza la ejecucion del programa
{
retorno9: //eleccion del usuario
printf("Elija la opcion deseada\n");
printf("1. UNA VARIABLE\n");
printf("2. DOS O MAS VARIABLES \n");
printf("3. SALIR\n");
printf("Su eleccion (1,2,3) --> ");
scanf("%d", &eleccion);
system("cls");

switch(eleccion)
{
case 1:
{
retorno:
printf("INTRODUCE EL TIPO DE OPERACION A USAR\n");
printf("1. Resolver ecuacion de 2do grado\n2. Salir\n3. Regresar Menu Principal\n");
scanf ("%d",&respuesta);
system("cls");
switch (respuesta)
{
case 1:
system ("segundogrado");

//return 0;
Sleep(2000);
system("cls");
goto retorno;

case 2:
printf("Gracias por usar el programa\n");
printf("Hasta pronto\n");
break;
// break;

case 3:
goto retorno9;

default: printf("\n\t\t\tUNICAMENTE DEL 1 AL 3\n");


Sleep(2000);
system("cls");
goto retorno;
}
}
break;
/////////////////////CASO B
case 2:
{
retorno2:
printf("INTRODUCE EL TIPO DE OPERACION A USAR\n");
printf("1. Resolver sistema de ecuaciones\n2. Salir\n3. Regresar Menu Principal\n");
scanf ("%d",&respuesta);
system("cls");
switch (respuesta)
{
case 1:
system ("sistemaecuaciones");
Sleep(2000);
system("cls");
goto retorno2;

case 2:
printf("Gracias por usar el programa\n");
printf("Hasta pronto\n");
break;
case 3:
goto retorno9;

default: printf("\n\t\t\tUNICAMENTE DEL 1 AL 3\n");


Sleep(2000);
system("cls");
goto retorno2;
}
}
break;
//////////////////////////CASO C

case 3:
{
printf("Gracias por usar el programa\n");
printf("Hasta pronto\n");
break;
}
default: printf("\n\t\t\tUNICAMENTE 1,2,3\n");
Sleep(1000);
system("cls");
goto retorno9;

}//fin del switch origen


}//fin del INT MAIN

Hallando raíces de una ecuación de segundo grado

/*Programa que halla las raíces de una ecuación de 2º grado*/


#include<stdio.h>
#include<conio.h>
#include<math.h>
// ECUACION DE 2DO GRADO

int main()
{
printf("Programa que halla las raices de una ecuacion de segundo grado\n");
printf(" ax^2 + bx + c = 0 ");
float a,b,c,g;
float D,R,I;
printf(" \n introduce un numero (a): a=");
scanf("%f",&a);
printf("\n introdusca el numero (b): b=");
scanf("%f",&b);
printf("\n introdusca el numero (c): c=");
scanf("%f",&c);
if(a==0&&b!=0)
{ g=(-c)/b;
printf("\nLa ecuacion no es de segundo grado el resultado es:%0.3f",g);
}
else {if(a==0&&b==0) printf("Solucion Inconsistente");
else {
D=b*b-4*a*c;
R=-b/(2*a);
I=sqrt(fabs(D))/(2*a);
if(D>=0)
{printf("\nx1=%f\nx2=%f",R+I,R-I);}
else
{printf("\nx1=%f+%fi\nx2=%f-%fi",R,I,R,I);}
}
}

getch();

return 0;
}

Sistema de ecuaciones por Gauss Jordan

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include<iostream>
void datos(int *tam, float mat1[][102]);
void esc_data(int tam1, float mat2[][102]);
void solucion(int Dim, float Sist[][102]);

int main(void)
{
int i,tam;
float mat[101][102];
datos(&tam,mat);
printf("\n\n\nEcuacion: \n\n");
esc_data(tam,mat);
solucion(tam,mat);
printf("\n\n\nSolucion:\n");
for(i=1;i<=tam;i++)
printf("\n X%d=%f\n",i,mat[i][tam+1]);

scanf("");
getch();
return(0);
}
void datos(int *tam,float mat1[][102])
{
int j,k;
printf("\n\n SISTEMA DE ECUACIONES POR GAUS JORDAN");
printf("\n\n\n INCOGNITAS: ");
scanf("%d",&*tam);
// printf("\n\n VARIABLES:");
// printf("\n\n MATRIZ j:\n");
for(j=1;j<=*tam;j++)
for(k=1;k<=*tam;k++)
{
printf("\n VALORES MATRIZ(%d,%d):",j,k);
scanf("%f",&mat1[j][k]);
}
printf("\n\n\n RESULTADO:\n");
for(j=1;j<=*tam;j++){
printf("\n VECTOR(%d):",j);
scanf("%f",&mat1[j][*tam+1]);
}
}

void esc_data(int tamano, float mat2[][102])


{
int x,y;
for(x=1;x<=tamano;x++)
{
for(y=1;y<=(tamano+1);y++)
{
printf("%7.2f",mat2[x][y]);
if(y==tamano)
printf(" |");
}
printf("\n");
}
}

void solucion(int tam, float mat[][102])


{
int res,i,j,k,m;
float col_pivote,x;

for(i=1;i<=tam;i++)
{
res=0;m=i;
while(res==0)
{
if((mat[m][i]>0.0000001)||((mat[m][i]<-0.0000001)))
{
res=1;
}
else
m++;
}
col_pivote=mat[m][i];
for(j=1;j<=(tam+1);j++)
{
x=mat[m][j];
mat[m][j]=mat[i][j];
mat[i][j]=x/col_pivote;
}
for(k=i+1;k<=tam;k++)
{
x=mat[k][i];
for(j=i;j<=(tam+1);j++)
{
mat[k][j]=mat[k][j]-x*mat[i][j];
}
}
}

for(i=tam;i>=1;i--)
for(j=(i-1);j>=1;j--)
{
mat[j][tam+1]=mat[j][tam+1]-mat[j][i]*mat[i][tam+1];
mat[j][i]=0;
}
getch();
}

Conclusiones

Durante la resolución y presentación del programa solo tuvimos un detalle en la presentación del
código de Matlab ya que lo hicimos con un ejecutable .exe el ejecutable tarda un poco en tardar
debido a la cantidad de líneas de código, aun estamos buscando optimizar esta parte aunque no
afecta en la parte de los resultados.

Bibliografía

www.librow.con/articles/article-10

También podría gustarte