Está en la página 1de 19

UNIVERSIDAD MAYOR DE SAN ANDRES

FACULTAD DE INGENIERÍA
INGENIERÍA QUÍMICA, AMBIENTAL, ALIMENTOS Y PETROQUIMICA

PROGRAMACION Y ANALISIS NUMERICO (PRQ – 404)

DOCENTE: M. Sc. Ing. Roberto Parra Zeballos


AUXILIAR: Univ. Álvaro Abel Rivera Cárdenas
ESTUDIANTE: Univ. Flores Santos Ayrton Tadeo
GRUPO: A
GESTIÓN: 2022

TAREA No. 6
PRQ404 – ECUACIONES IMPLICITAS
LOS SIGUIENTES PROBLEMAS DEBEN RESOLVERSE ELABORANDO: 1) ALGORITMO, 2) DF Ó
PSEUDOCÓDIGO, 3) PROGRAMA EN MATLAB.

PROGRAME USANDO SUB-PROGRAMAS (FUNCTION) GENÉRICOS, ES DECIR, QUE RESUELVAN


CUALQUIER ECUACIÓN IMPLÍCITA CON EL MÉTODO SOLICITADO.

EN CADA EJERCICIO DEBE ENTREGARSE CON LOS 3 PUNTOS ANTES EXPLICADOS, ADEMÁS,
INCLUYENDO EL RESULTADO DE CADA PROGRAMA. DEBE SER PRESENTADO EN UN ARCHIVO .doc
o .docx.

1.- a) Aplique el método de Newton-Raphson a la función f(x) = tanh (x2 – 9) para evaluar su raíz
real conocida en x = 3. Use un valor inicial de x0 = 3.2 y haga un mínimo de cuatro iteraciones. b)
¿Converge el método a su raíz real? Bosqueja la gráfica con los resultados para cada iteración que
obtenga. Elabore un programa en MATLAB.

PSEUDOCÓDIGO DIAGRAMA DE FLUJO


1. Función Newton Rhapson
2. function [x] =
NewtonR(f,df,x0,tol)
3. Hacer error=1;
4. Hacer x1=1
5. Mientras error>tol
6. Hacer x1=x0-f(x0)/df(x0)
7. Hacer x0=x1
8. Fin mientras
9. Hacer x=x1
10. Fin

11. Hacer syms x


12. Hacer fsym=tanh(x^2-9)
13. Hacer dfsym=diff(fsym)
14. Hacer f=inline(fsym);
15. Hacer
df=inline(dfsym);
16. Leer x0=3.2;
17. Leer Nit=4;
18. Leer TOL=10^-10;
19. Hacer x1=x0-
f(x0)/(df(x0)); INICIO
20. i=1;
21. Para i=1:1:Nit
22. [x] = function [x] = NewtonR(f,df,x0,tol)
NewtonR(f,df,x0,tol);
23. Fin Para
24. Si i>Nit Error=1
X1=1
25. Imprimir 'NO EXISTE
SOLUCIÓN EN Nit'
26. Fin si
27. Graficar
NO x1=x0-f(x0)/df(x0)
28. FIN
x0=x1
PROGRAMA EN MATLAB
function [x] =
NewtonR(f,df,x0,tol)
error=1; Error>tol SI
x1=1
while error>tol
x1=x0-f(x0)/df(x0);
error=abs(x1-x0);
x=x1
x0=x1
end
x=x1;
end x

%P6-E1
%MÉTODO DE NEWTON RHAPSON
%f=tanh(x^2-9) FIN
syms x
fsym=tanh(x^2-9);
dfsym=diff(fsym);
f=inline(fsym);
df=inline(dfsym);
x0=3.2;
Nit=4;
TOL=10^-10;
x1=x0-f(x0)/(df(x0));
i=1;
for i=1:1:Nit
[x] = NewtonR(f,df,x0,tol);
end
if i>Nit
disp('NO EXISTE SOLUCIÓN EN
Nit')
end

>> f

f=

Inline function:
f(x) = tanh(x.^2-9.0)
INICIO
>> x=1:0.01:10
g=f(h)
>> plot(h,g)
syms x
>> grid on fsym=tanh(x^2-9)
dfsym=diff(fsym)
f=inline(fsym)
df=inline(dfsym)

x0=3.2
Nit=4
TOL=10^-10

x1=x0-f(x0)/(df(x0))

i=1; i=i+1;i<=Nit

[x] = NewtonR(f,df,x0,tol)

i>Nit

NO EXISTE
SOLUCIÓN EN
Nit

GRAFICAR

FIN
2.- Suponga el lector que está diseñando un tanque esférico (véase la figura P6.26 – Libro: Chapra)
de almacenamiento de agua para un poblado pequeño de un país en desarrollo. El volumen del
líquido que puede contener se calcula con

donde V = volumen [pie3 ], h = profundidad del agua en el tanque [pies], y R = radio del tanque
[pies]. Si R = 3 m, ¿a qué profundidad debe llenarse el tanque de modo que contenga 30 m 3 ?
Resuelva utilizando el método de Newton-Raphson. Encuentre el error relativo aproximado
después de cada iteración. Observe que el valor inicial de R convergerá siempre.

PSEUDOCÓDIGO DIAGRAMA DE FLUJO


INICIO
1. [x] = NewtonR(f,df,x0,tol)
error=1;
2. x1=1
3. Mientras error>tol INICIO
4. Hacer x1=x0-f(x0)/df(x0)
5. Hacer error=abs(x1-x0);
6. Hacer x0=x1
7. Fin Mientras function [x] = NewtonR(f,df,x0,tol)
8. Hacer x=x1
9. FIN Error=1
X1=1
10. Leer R=3
11. Leer V=30
12. syms h
13. Hacer
fsym=pi*h^2*(3*R-h)/3-V NO x1=x0-f(x0)/df(x0)
14. Hacer dfsym=diff(fsym) x0=x1
15. Hacer f=inline(fsym)
16. Hacer df=inline(dfsym)
17. Hacer x0=5
Error>tol SI
18. Hacer tol=0.0001
19. [x] =
NewtonR(f,df,x0,tol);
20. Imprimir('La altura
es: %4.f [m]',x) x=x1

PROGRAMA EN MATLAB
function [x] = x
NewtonR(f,df,x0,tol)
error=1;
x1=1
while error>tol FIN
x1=x0-f(x0)/df(x0);
error=abs(x1-x0);
x0=x1
end
x=x1;
end

%P6-E2
%Parametros
R=3;%m
V=30;%m^3
%V=pi*h^2*(3R-h)/3
syms h
fsym=pi*h^2*(3*R-h)/3-V;
dfsym=diff(fsym);
f=inline(fsym);
df=inline(dfsym);
x0=5;
tol=0.0001;
[x] = NewtonR(f,df,x0,tol);
fprintf('La altura es: %4.f
[m]',x)

>> f
f=
INICIO

Inline function:
f(h) = h.^2.*pi.*(h-9.0).*(-1.0./3.0)-3.0e+1
R=3
>> h=1:0.01:10 V=30
x0=5
>> g=f(h) tol=0.0001
>> plot(h,g)
>> grid on Syms h
>> title('GRAFICA f(h)')
xlabel('Eje x')
fsym=pi*h^2*(3*R-h)/3-V
ylabel('Eje y') dfsym=diff(fsym)
f=inline(fsym)
df=inline(dfsym)

[x] = NewtonR(f,df,x0,tol)

FIN

3.- Emplee el método de Müller para determinar las raíces reales y complejas de

a) ƒ(x) = x3 – x2 + 3x – 2

b) ƒ(x) = 2x4 + 6x2 + 10


c) ƒ(x) = x4 – 2x3 + 6x2 – 8x + 8

Formule la subrutina MULLER para resolver estas ecuaciones.

PSEUDOCÓDIGO DIAGRAMA DE FLUJO


1. INICIO
2. function [x] = INICIO
Muller(f,x0,x1,x2,tol)
3. Hacer error=1;
4. Hacer x3=1; function [x] = Muller(f,x0,x1,x2,tol)
5. Mientras error>tol
6. Hacer H0=x1-x0;
7. Hacer H1=x2-x1; Error=1
8. Hacer d0=(f(x1)-f(x0))/H0; x3=1
9. Hacer d1=(f(x2)-f(x1))/H1;
10. Hacer a=(d1-d0)/(H1+H0); x0=x1
x1=x2
11. Hacer b=a*H1+d1;
x2=x3
12. Hacer c=f(x2);
13. Hacer x3=x2-
(2*c)/(b+sign(b)*sqrt(b^2- x3=x2-(2*c)/(b+sign(b)*sqrt(b^2-4*a*c))
4*a*c)); error=abs((x3-x2)*100/x2)
14. Hacer error=abs((x3-
x2)*100/x2);
a=(d1-d0)/(H1+H0)
15. x0=x1; b=a*H1+d1
16. x1=x2; c=f(x2)
17. x2=x3;
18. Fin Mientras
H0=x1-x0
19. x=x3 H1=x2-x1
20. FIN d0=(f(x1)-f(x0))/H0
d1=(f(x2)-f(x1))/H1
%a) f(x)=x^3-x^2+3*x-2
1. INICIO error>tol
2. f=@(x)x^3-x^2+3*x-2
3. Leer x0, x1, x2
4. tol=10^-10
5. [x] = Muller(f,x0,x1,x2,tol) x=x3
6. IMPRIMIR ('La solución es:
',x)
7. FIN
%b) f(x)=2*x^4+6*x^2+10 x
INICIO
1. INICIO
2. f=@(x)2*x^4+6*x^2+10
3. Leer x0, x1, x2 FIN
4. tol=10^-10
5. [x] = Muller(f,x0,x1,x2,tol)
6. IMPRIMIR('La solución es: ',x)
7. FIN
%c) f(x)=x^4-2*x^3+6*x^2-8*x+8
1. INICIO
2. f=@(x)x^4-2*x^3+6*x^2-8*x+8
3. Leer x0, x1, x2
4. tol=10^-10
5. [x] = Muller(f,x0,x1,x2,tol)
6. IMPRIMIR('La solución es: ',x)
7. FIN
PROGRAMA EN MATLAB
function [x] = INICIO
Muller(f,x0,x1,x2,tol)
error=1;
x3=1;
while error>tol
H0=x1-x0;
H1=x2-x1;
d0=(f(x1)-f(x0))/H0; Leer f(x)
d1=(f(x2)-f(x1))/H1;
a=(d1-d0)/(H1+H0);
b=a*H1+d1;
c=f(x2);
x3=x2-(2*c)/(b+sign(b)*sqrt(b^2- tol=10^-10
4*a*c)); [x] = Muller(f,x0,x1,x2,tol)
error=abs((x3-x2)*100/x2);
x0=x1;
x1=x2;
x2=x3; x
end
x=x3;
end

%P6-E3
%a) f(x)=x^3-x^2+3*x-2 FIN
f=@(x)x^3-x^2+3*x-2
x0=input('Introducir valor: ')
x1=input('Introducir valor: ')
x2=input('Introducir valor: ')
tol=10^-10
[x] = Muller(f,x0,x1,x2,tol)
fprintf('La solución es: ',x)
%b) f(x)=2*x^4+6*x^2+10
f=@(x)2*x^4+6*x^2+10
x0=input('Introducir valor: ')
x1=input('Introducir valor: ')
x2=input('Introducir valor: ')
tol=10^-10
[x] = Muller(f,x0,x1,x2,tol)
fprintf('La solución es: ',x)
%c) f(x)=x^4-2*x^3+6*x^2-8*x+8
f=@(x)x^4-2*x^3+6*x^2-8*x+8
x0=input('Introducir valor: ')
x1=input('Introducir valor: ')
x2=input('Introducir valor: ')
tol=10^-10
[x] = Muller(f,x0,x1,x2,tol)
fprintf('La solución es: ',x)

4.- Se ha sumergido el uso del metano, en un cilindro como un combustible de emergencia para el
sistema de calefacción de una planta que normalmente usa gas natural (compuesto por gran parte
por metano) . Se ha de mantener en reserva una cantidad suficiente de cilindros de gas para
suministrar 25,200 kcal/h durante 24 horas si el metano produce 97,200 kcal/kmol al quemarse y
se entrega en un cilindro de 56.62 litros a 204 atm y 21°C . ¿Cuantos cilindros deben ser
mantenidos en reservas ? Obtener predicciones con el método numérico de Punto Fijo y Newton-
Raphson, derive en forma numérica la función. Use un menú de selección del método y programe
en GUIDE.

Datos:

 a 
Ecuación de Van Der Waals:  P + (V − b) = RT
 V2
a = 2.25 atm*lt^2/mol^2

b = 0.0428 lt/mol

R = 0.082 atm*lt/°k*mol
PROGRAMA EN MATLAB
function [x] = Punto_fijo(f,kx,Ea,Nit)
error=1
i=1
while i<Nit
x=kx;
kx=f(x);
Ea=abs(kx-x);
fprintf('%d \t %1.7f \t \t %f \n',i,kx,Ea);
if Ea<=error
i=Nit+1;
break
end
i=i+1
end
fprintf('La aproximación es: %1.7 con un error de: %f\n',i,kx,Ea);
end

function [x] = NewtonR(f,df,x0,tol)


error=1;
x1=1
while error>tol
x1=x0-f(x0)/df(x0);
error=abs(x1-x0);
x0=x1
end
x=x1;
end

%P6-E4
%DATOS
Qnec=25200;%kcal/horas
tiempo=24;%horas
PC=97200;%kcal/kmol

%Calculo de los moles totales de metano


moles_tot=Qnec*tiempo*1000/PC;%mol

%Cilindros
Vcil=56.62;%Litros
P=204;%atm
T=294;%K
R=0.082;%atm*L/K*mol
a=2.25;%atm*L^2/mol^2
b=0.0428;%L/mol
dV=0.0000001;

%La iteración
f=@(V) P*V^3-(P*b+R*T)*V^2+a*V-a*b;

t=input('Introducir 1 (Método del punto fijo) o 2 (Método Newton-


Rhapson)')
if t=1
%funcion Método del Punto Fijo
[x] = Punto_fijo(f,kx,Ea,Nit);
end
if t=2
%funcion Método Newton-Rhapson
[x] = NewtonR(f,df,x0,tol)
end
Videal=x
nmoles_cil=Vcil/Videal;
cilindros=moles_tot/nmoles_cil

5.- La ecuación de estado de Redlich-Kwong está dada por:

donde R = la constante universal de los gases [= 0.518 kJ/(kg K)], T = temperatura absoluta (K),
p = presión absoluta (kPa) y v = volumen de un kg de gas (m3/kg). Los parámetros a y b se
calculan mediante:

donde pc = 4 580 kPa y Tc = 191 K. Como ingeniero químico, se le pide determinar la cantidad de
combustible metano que se puede almacenar en un tanque de 3 m3 a una temperatura de –50 °C
con una presión de 65 000 kPa. Emplee el método de la secante para calcular v y luego determine
la masa de metano contenida en el tanque. Programe en GUIDE.
PSEUDOCÓDIGO
1. INICIO
2. function [x] = secante(f,x0,x1,tol)
3. Hacer error=1;
4. Hacer x2=1
5. Mientras error>tol
6. Hacer x2=x1-(f(x1)*(x0-x1))/(f(x0)-f(x1));
7. Hacer error=abs(x2-x1);
8. Hacer x0=x1;
9. Hacer x1=x2;
10. Fin Mientras
11. x=x2;
12. FIN
13. INICIO
14. Leer R=0.518
15. Leer T=223
16. Leer P=65
17. Leer V=3
18. Leer Pc=4580
19. Leer Tc=191
20. a=0.427*(R^2*Tc^2)/Pc
21. b=0.0866*R*Tc/Pc
22. f=@(V) R*T/(V-b)-a/(V*(V+b)*sqrt(T))-P;
23. x0=1;
24. x1=5;
25. tol=0.0001;
26. [x] = secante(f,x0,x1,tol)
27. m=V/x;
28. IMPRIMIR('La masa contenida de metano es: %4.3f [Kg]',m)
29. FIN

PROGRAMA EN MATLAB
function [x] = secante(f,x0,x1,tol)
error=1;
x2=1
while error>tol
x2=x1-(f(x1)*(x0-x1))/(f(x0)-f(x1));
error=abs(x2-x1);
x0=x1;
x1=x2;
end
x=x2;
end

%P6-E5
%Parametros
R=0.518;%KJ/KgK
T=223;%K
P=65;%KPa
V=3;%m^3
Pc=4580;%KPa
Tc=191;%K
%Calculo a y b
a=0.427*(R^2*Tc^2)/Pc;%Kpa(m^3/Kg)^2
b=0.0866*R*Tc/Pc;%m^3/Kg
%P=RT/(V-b)-a/(V*(V+B)*sqrt(T))
%0=RT/(V-b)-a/(V*(V+B)*sqrt(T))-P
f=@(V) R*T/(V-b)-a/(V*(V+b)*sqrt(T))-P;
x0=5;
x1=7;
tol=0.0001;
[x] = secante(f,x0,x1,tol);
%x=Vol especifico(m^3/Kg)
m=V/x;%Kg
fprintf('La masa contenida de metano es: %4.3f [Kg]',m)

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

% Last Modified by GUIDE v2.5 31-Oct-2021 00:40:10

% Begin initialization code - DO NOT EDIT


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


function P6_E5guide_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 P6_E5guide (see VARARGIN)

% Choose default command line output for P6_E5guide


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);
%set-->salida
%get-->entrada
set(handles.edit1,'String',' ')
set(handles.edit2,'String',' ')
set(handles.edit3,'String',' ')
set(handles.edit4,'String',' ')
set(handles.edit5,'String',' ')
set(handles.edit6,'String',' ')
set(handles.edit7,'String',' ')
axes(handles.axes1);
[x,map]=imread('metano.jpg');
image(x)
colormap(map)
axis off
% UIWAIT makes P6_E5guide wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = P6_E5guide_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 edit1_Callback(hObject, eventdata, handles)


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


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

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

% --- Executes on button press in pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
R=str2double(get(handles.edit1,'String'));
T=str2double(get(handles.edit2,'String'));
P=str2double(get(handles.edit3,'String'));
V=str2double(get(handles.edit4,'String'));
Pc=str2double(get(handles.edit5,'String'));
Tc=str2double(get(handles.edit6,'String'));
%Calculo a y b
a=0.427*(R^2*Tc^2)/Pc;%Kpa(m^3/Kg)^2
b=0.0866*R*Tc/Pc;%m^3/Kg
%P=RT/(V-b)-a/(V*(V+B)*sqrt(T))
%0=RT/(V-b)-a/(V*(V+B)*sqrt(T))-P
f=@(V) R*T/(V-b)-a/(V*(V+b)*sqrt(T))-P;
x0=0;
x1=5;
tol=0.0001;
[x] = secante(f,x0,x1,tol);
%x=Vol especifico(m^3/Kg)
m=V/x;%Kg
set(handles.edit7,'String',m)
% 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)

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
INICIO

function [x] = secante(f,x0,x1,tol)


error=1
x2=1

x2=x1-(f(x1)*(x0-x1))/(f(x0)-f(x1))
error=abs(x2-x1)
x0=x1
x1=x2

error>tol

x=x2

FIN
INICIO

R=0.518
T=223
P=65
V=3
Pc=4580
Tc=191

a=0.427*(R^2*Tc^2)/Pc
b=0.0866*R*Tc/Pc
f=@(V) R*T/(V-b)-a/(V*(V+b)*sqrt(T))-P

x0=1
x1=5
tol=0.0001

[x] = secante(f,x0,x1,tol)
m=V/x

FIN

También podría gustarte