0% found this document useful (0 votes)
26 views3 pages

Function: '/N' '/T %8.5f' '/T %8.2f' '/T/T/T' '/T %8.5f' '/T %8.5f'

The document contains two functions: Biseccion and newthon_raph. Biseccion uses the bisection method to find the root of a function Fx within a given interval [xl, xu] to within an error tolerance es. It iterates until the maximum number of iterations iMax is reached or the error ea is below es. newthon_raph uses the Newton-Raphson method to find a root of Fx, using the derivative Dx. It iterates until the error or function value is below the tolerance or the maximum iterations is reached. The document also includes a sample program that calls these functions to calculate the volume of a gas.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Function: '/N' '/T %8.5f' '/T %8.2f' '/T/T/T' '/T %8.5f' '/T %8.5f'

The document contains two functions: Biseccion and newthon_raph. Biseccion uses the bisection method to find the root of a function Fx within a given interval [xl, xu] to within an error tolerance es. It iterates until the maximum number of iterations iMax is reached or the error ea is below es. newthon_raph uses the Newton-Raphson method to find a root of Fx, using the derivative Dx. It iterates until the error or function value is below the tolerance or the maximum iterations is reached. The document also includes a sample program that calls these functions to calculate the volume of a gas.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

function [xr,ea,k] = Biseccion(Fx,xl,xu,iMax,es)

[f] = Evalua(Fx,xl) + Evalua(Fx,xu);


k=0;
ea=100;
xr=0;
xr_ant=(xl+xu)/2;
while (k<=iMax)&&(ea>=es);
xr_ant=xr;
xr=(xl+xu)/2;
k=k+1;
if xr ~= 0;
ea=abs(xr-xr_ant);
end
r=Evalua(Fx,xl)*Evalua(Fx,xr);
if r<0;
xu=xr;
else
if r>0;
xl=xr;
else
if r==0;
ea=0;
end
end
end
fprintf('\n');
fprintf('\t %8.5f',xr_ant);
fprintf('\t %8.2f',Evalua(Fx,xr));
fprintf('\t\t\t');
fprintf('\t %8.5f',xr);
fprintf('\t %8.5f',ea);
end
end

function [xr Ea i]=newthon_raph(Fx,Dx,x0,EPS,EPS1,iMax)


i=1;
while i<=iMax
xr=x0-Evalua(Fx,x0)/Evalua(Dx,x0);
Ea=abs(xr-x0);
if (Ea<EPS)
break
end
if (abs(Evalua(Fx,xr))<EPS1)
break
end
i=i+1;

fprintf('\n');
fprintf('\t %8.5f',x0);
fprintf('\t %8.2f',Evalua(Fx,x0));
fprintf('\t %8.2f',Evalua(Dx,x0));
fprintf('\t %8.5f',xr);
fprintf('\t %8.5f',Ea);

x0=xr;
end
fprintf('\n');
end

programa:

clear all
clc
disp('*******************')
disp('VOLUMEN')
disp('*******************')

global p T a b N k
p = 3.5e7;
T = 300;
a = 0.401;
b = 42.7e-6;
N = 1000;
k = 1.3806503e-23;

% definimos funcion
syms V;
func = '(p + a*(N/V)^2)*(V-N*b)-k*N*T';
Fx = inline(func,'V','p','T','a','b','N','k');
deriv = diff(func,V);
Dx = inline(deriv,'V','p','T','a','b','N','k');

% valores rango
xl=input('Vol inferior : ');
xu=input('Vol superior : ');
es=input('Tolerancia : ');
imax=input('ingrese imax:');
fprintf('\n\t Vi \t\t F(Vi) \t\t F''(Vi) \t\t Vi+1 \t\t Ea');
fprintf('\n\t----\t\t-------\t\t---------\t\t------\t\t---');

Nro = 2;
[xr,ea,iter] = Biseccion (Fx,xl,xu,Nro,es);

Nro=imax;
[xr,ea,iter] = newthon_raph (Fx,Dx,xr,es,es,Nro);

fprintf('\n');
fprintf('Volumen = %8.5f',xr);
fprintf('\n');
programa corrido:

You might also like