Está en la página 1de 8

CLASE 5 26 DE AGOSTO

function biseccion_8_4_mezcla_completa_v1
clc, clear all, close all
c0=4; cent=10; c=(93/100)*cent;
x=0:1000; y=f(x);
plot(x,y), grid on
function g=f(t) %raíz de aprox 53.8
g=cent*(1-exp(-0.04*t))+c0*exp(-0.04*t)-c;
end
end
1

-1

-2

-3

-4

-5

-6
0 100 200 300 400 500 600 700 800 900 1000

Raíz es 53.8

function biseccion_8_4_mezcla_completa_v1
clc, clear all, close all
c0=4; cent=10; C=(93/100)*cent;
%x=0:1000; y=f(x); plot(x,y), grid on
a=35; b=65; tol=1e-5;
N=ceil((log(abs(a-b))-log(tol))/log(2));
for it=1:N
c=(a+b)/2;
if f(a)*f(c)<0
b=c;
else
a=c;
end
end
fprintf('tiempo: %6.5f \n',c)
f(c)
function g=f(t)
g=cent*(1-exp(-0.04*t))+c0*exp(-0.04*t)-C;
end
end
tiempo: 53.71085

ans =

-1.7572e-07

1
CLASE 5 26 DE AGOSTO
function biseccion_8_4_mezcla_completa_v1
clc, clear all, close all
c0=4; cent=10; C=(93/100)*cent;
x=0:1e-3:100; y=f(x); plot(x,y), grid on, hold on
a=35; b=65; tol=1e-5;
N=ceil((log(abs(a-b))-log(tol))/log(2));
for it=1:N
c=(a+b)/2;
fprintf('%2.0f\t%7.6f\t%7.6f\t%7.6f\n',it,a,c,b)
if f(a)*f(c)<0
b=c;
else
a=c;
end
end
fprintf('*******tiempo: %6.5f********* \n',c)
plot(c,f(c),'or')
function g=f(t)
g=cent*(1-exp(-0.04*t))+c0*exp(-0.04*t)-C;
end
end
1

-1

-2

-3

-4

-5

-6
0 10 20 30 40 50 60 70 80 90 100

1 35.000000 50.000000 65.000000


2 50.000000 57.500000 65.000000
3 50.000000 53.750000 57.500000
4 50.000000 51.875000 53.750000
5 51.875000 52.812500 53.750000
6 52.812500 53.281250 53.750000
7 53.281250 53.515625 53.750000
8 53.515625 53.632813 53.750000
9 53.632813 53.691406 53.750000
10 53.691406 53.720703 53.750000
11 53.691406 53.706055 53.720703
12 53.706055 53.713379 53.720703
13 53.706055 53.709717 53.713379
14 53.709717 53.711548 53.713379
15 53.709717 53.710632 53.711548
16 53.710632 53.711090 53.711548
17 53.710632 53.710861 53.711090
18 53.710632 53.710747 53.710861
19 53.710747 53.710804 53.710861
20 53.710804 53.710833 53.710861
21 53.710833 53.710847 53.710861
22 53.710847 53.710854 53.710861
*******tiempo: 53.71085*********

2
CLASE 5 26 DE AGOSTO

function biseccion_8_4_mezcla_completa_v2
clc, clear all, close all
c0=4; cent=10; C=(93/100)*cent;
x=0:1e-3:100; y=f(x); plot(x,y), grid on, hold on
a=35; b=65; tol=1e-5;
N=ceil((log(abs(a-b))-log(tol))/log(2));
disp('it a c b f(a) f(c) f(b)')
for it=1:N
c=(a+b)/2;
fprintf('%2.0f\t%7.6f\t%7.6f\t%7.6f\t',it,a,c,b)
fprintf('%7.6f\t%7.6f\t%7.6f\n',f(a),f(c),f(b))
if f(a)*f(c)<0
b=c;
else
a=c;
end
end
fprintf('*******tiempo: %7.6f********* \n',c)
plot(c,f(c),'or')
function g=f(t)
g=cent*(1-exp(-0.04*t))+c0*exp(-0.04*t)-C;
end
end
it a c b f(a) f(c) f(b)
1 35.000000 50.000000 65.000000 -0.779582 -0.112012 0.254359
2 50.000000 57.500000 65.000000 -0.112012 0.098447 0.254359
3 50.000000 53.750000 57.500000 -0.112012 0.001095 0.098447
4 50.000000 51.875000 53.750000 -0.112012 -0.053339 0.001095
5 51.875000 52.812500 53.750000 -0.053339 -0.025612 0.001095
6 52.812500 53.281250 53.750000 -0.025612 -0.012133 0.001095
7 53.281250 53.515625 53.750000 -0.012133 -0.005488 0.001095
8 53.515625 53.632813 53.750000 -0.005488 -0.002189 0.001095
9 53.632813 53.691406 53.750000 -0.002189 -0.000545 0.001095
10 53.691406 53.720703 53.750000 -0.000545 0.000276 0.001095
11 53.691406 53.706055 53.720703 -0.000545 -0.000135 0.000276
12 53.706055 53.713379 53.720703 -0.000135 0.000071 0.000276
13 53.706055 53.709717 53.713379 -0.000135 -0.000032 0.000071
14 53.709717 53.711548 53.713379 -0.000032 0.000019 0.000071
15 53.709717 53.710632 53.711548 -0.000032 -0.000006 0.000019
16 53.710632 53.711090 53.711548 -0.000006 0.000006 0.000019
17 53.710632 53.710861 53.711090 -0.000006 0.000000 0.000006
18 53.710632 53.710747 53.710861 -0.000006 -0.000003 0.000000
19 53.710747 53.710804 53.710861 -0.000003 -0.000002 0.000000
20 53.710804 53.710833 53.710861 -0.000002 -0.000001 0.000000
21 53.710833 53.710847 53.710861 -0.000001 -0.000000 0.000000
22 53.710847 53.710854 53.710861 -0.000000 -0.000000 0.000000
*******tiempo: 53.710854*********

3
CLASE 5 26 DE AGOSTO

function biseccion_8_4_mezcla_completa_v3
clc, clear all, close all
c0=4; cent=10; C=(93/100)*cent;
x=0:1e-3:100; y=f(x); plot(x,y), grid on, hold on
a=35; b=65; tol=1e-5;
N=ceil((log(abs(a-b))-log(tol))/log(2));
disp('it a c b f(a) f(c) f(b)
actualizacion')
for it=1:N
c=(a+b)/2;
fprintf('%2.0f\t%7.6f\t%7.6f\t%7.6f\t',it,a,c,b)
fprintf('%7.6f\t%7.6f\t%7.6f\t',f(a),f(c),f(b))
if f(a)*f(c)<0
fprintf('Der\n')
b=c;
else
fprintf('Izq\n')
a=c;
end
end
fprintf('*******tiempo: %7.6f********* \n',c)
plot(c,f(c),'or')
function g=f(t)
g=cent*(1-exp(-0.04*t))+c0*exp(-0.04*t)-C;
end
end
it a c b f(a) f(c) f(b) actualizacion
1 35.000000 50.000000 65.000000 -0.779582 -0.112012 0.254359 Izq
2 50.000000 57.500000 65.000000 -0.112012 0.098447 0.254359 Der
3 50.000000 53.750000 57.500000 -0.112012 0.001095 0.098447 Der
4 50.000000 51.875000 53.750000 -0.112012 -0.053339 0.001095 Izq
5 51.875000 52.812500 53.750000 -0.053339 -0.025612 0.001095 Izq
6 52.812500 53.281250 53.750000 -0.025612 -0.012133 0.001095 Izq
7 53.281250 53.515625 53.750000 -0.012133 -0.005488 0.001095 Izq
8 53.515625 53.632813 53.750000 -0.005488 -0.002189 0.001095 Izq
9 53.632813 53.691406 53.750000 -0.002189 -0.000545 0.001095 Izq
10 53.691406 53.720703 53.750000 -0.000545 0.000276 0.001095 Der
11 53.691406 53.706055 53.720703 -0.000545 -0.000135 0.000276 Izq
12 53.706055 53.713379 53.720703 -0.000135 0.000071 0.000276 Der
13 53.706055 53.709717 53.713379 -0.000135 -0.000032 0.000071 Izq
14 53.709717 53.711548 53.713379 -0.000032 0.000019 0.000071 Der
15 53.709717 53.710632 53.711548 -0.000032 -0.000006 0.000019 Izq
16 53.710632 53.711090 53.711548 -0.000006 0.000006 0.000019 Der
17 53.710632 53.710861 53.711090 -0.000006 0.000000 0.000006 Der
18 53.710632 53.710747 53.710861 -0.000006 -0.000003 0.000000 Izq
19 53.710747 53.710804 53.710861 -0.000003 -0.000002 0.000000 Izq
20 53.710804 53.710833 53.710861 -0.000002 -0.000001 0.000000 Izq
21 53.710833 53.710847 53.710861 -0.000001 -0.000000 0.000000 Izq
22 53.710847 53.710854 53.710861 -0.000000 -0.000000 0.000000 Izq
*******tiempo: 53.710854*********
8.36 los ingenieros mecánicos ,asi como los de otras especialidades, utilizan mucho la termodinámica para realizarsu trabajo

4
CLASE 5 26 DE AGOSTO

function biseccion_8_36_Cp
clc, clear all, close all
CP=1.2;
%c0=4; cent=10; C=(93/100)*cent;
x=10:4000; y=f(x); plot(x,y), grid on,
function g=f(T)
g=0.99403+1.671e-4*T+9.7215e-8*T.^2-9.5838e-11*T.^3+1.9520e-14*T.^4-CP
end
end
1

0.8

0.6

0.4

0.2

-0.2

-0.4
0 500 1000 1500 2000 2500 3000 3500 4000

function biseccion_8_36_Cp1
clc, clear all, close all
CP=1.2;
%c0=4; cent=10; C=(93/100)*cent;
%x=10:4000; y=f(x); plot(x,y), grid on, hold on
a=1000; b=2000; tol=0.01/100; %si la tol=0.01%
N=ceil((log(abs(a-b))-log(tol))/log(2));
error=abs(b-a); ITER=zeros(N,1); ERROR=zeros(N,1);
disp('it a c b ERROR')
for it=1:N
c=(a+b)/2; error=error/2;
ITER(it)=it; ERROR(it)=error;
fprintf('%2.0f\t%7.4f\t%7.4f\t%7.4f\t',it,a,c,b)
fprintf('%9.8f\n',error)
if f(a)*f(c)<0
b=c;
else
a=c;
end
end
fprintf('*******tiempo: %7.6f********* \n',c)
plot(ITER,ERROR,':dr'), grid on
function g=f(T)
g=0.99403+1.671e-4*T+9.7215e-8*T.^2-9.5838e-11*T.^3+1.9520e-14*T.^4-CP;
end
end

5
CLASE 5 26 DE AGOSTO
500

450

400

350

300

250

200

150

100

50

0
0 5 10 15 20 25

it a c b ERROR
1 1000.0000 1500.0000 2000.0000 500.00000000
2 1000.0000 1250.0000 1500.0000 250.00000000
3 1000.0000 1125.0000 1250.0000 125.00000000
4 1125.0000 1187.5000 1250.0000 62.50000000
5 1125.0000 1156.2500 1187.5000 31.25000000
6 1125.0000 1140.6250 1156.2500 15.62500000
7 1125.0000 1132.8125 1140.6250 7.81250000
8 1125.0000 1128.9063 1132.8125 3.90625000
9 1125.0000 1126.9531 1128.9063 1.95312500
10 1125.0000 1125.9766 1126.9531 0.97656250
11 1125.9766 1126.4648 1126.9531 0.48828125
12 1125.9766 1126.2207 1126.4648 0.24414063
13 1125.9766 1126.0986 1126.2207 0.12207031
14 1125.9766 1126.0376 1126.0986 0.06103516
15 1125.9766 1126.0071 1126.0376 0.03051758
16 1126.0071 1126.0223 1126.0376 0.01525879
17 1126.0071 1126.0147 1126.0223 0.00762939
18 1126.0071 1126.0109 1126.0147 0.00381470
19 1126.0071 1126.0090 1126.0109 0.00190735
20 1126.0090 1126.0099 1126.0109 0.00095367
21 1126.0090 1126.0095 1126.0099 0.00047684
22 1126.0095 1126.0097 1126.0099 0.00023842
23 1126.0097 1126.0098 1126.0099 0.00011921
24 1126.0097 1126.0098 1126.0098 0.00005960
*******tiempo: 1126.009762*********
2.35 la ecuación de estado de beattie-briggeman en su forma virial es

Donde:
function biseccion_beattie_bridgeman_v1
clc, clear all, close all
R=0.08205; P=50; T=100+273.15;
A0=0.0216; a=0.05984; B0=0.01400; b=0.000000; c=0.004e4;
x=-200:1e-3:1000; y=f(x); plot(x,y), grid on
function q=f(V)
beta=R*T*B0-A0-R*c/T.^2;
gamma=-R*T*B0*b+A0*a-R*B0*c/T.^2;
1013
delta=R*B0*b*c/T.^2; 5

%q=R*T+beta./V+gamma./V.^2+delta./V.^3-P*V; 4
q=P*V.^4-(R*T*V.^3+beta.*V.^2+gamma*V+delta);
end 3

end
2

-1
-200 0 200 400 600 800 1000

6
CLASE 5 26 DE AGOSTO

function biseccion_beattie_bridgeman_v1
clc, clear all, close all
R=0.08205; P=50; T=100+273.15;
A0=0.0216; a=0.05984; B0=0.01400; b=0.000000; c=0.004e4;
%x=-200:1e-3:1000; y=f(x); plot(x,y), grid on
izq=-10000; der=200000; tol=0.01/100; %si la tol=0.01%
N=ceil((log(abs(izq-der))-log(tol))/log(2));
error=abs(der-izq); ITER=zeros(N,1); ERROR=zeros(N,1);
disp('it a c b ERROR')
for it=1:N
med=(izq+der)/2; error=error/2;
ITER(it)=it; ERROR(it)=error;
fprintf('%2.0f\t%7.4f\t%7.4f\t%7.4f\t',it,izq,med,der)
fprintf('%9.8f\n',error)
if f(izq)*f(med)<0
der=med;
else
izq=med;
end
end
fprintf('*******tiempo: %7.6f********* \n',med)
f(med)
function q=f(V)
beta=R*T*B0-A0-R*c/T.^2;
gamma=-R*T*B0*b+A0*a-R*B0*c/T.^2;
delta=R*B0*b*c/T.^2;
%q=R*T+beta./V+gamma./V.^2+delta./V.^3-P*V;
q=P*V.^4-(R*T*V.^3+beta.*V.^2+gamma*V+delta);
end
end
it a c b ERROR
1 -10000.0000 95000.0000 200000.0000 105000.00000000
2 95000.0000 147500.0000 200000.0000 52500.00000000
3 147500.0000 173750.0000 200000.0000 26250.00000000
4 173750.0000 186875.0000 200000.0000 13125.00000000
5 186875.0000 193437.5000 200000.0000 6562.50000000
6 193437.5000 196718.7500 200000.0000 3281.25000000
7 196718.7500 198359.3750 200000.0000 1640.62500000
8 198359.3750 199179.6875 200000.0000 820.31250000
9 199179.6875 199589.8438 200000.0000 410.15625000
10 199589.8438 199794.9219 200000.0000 205.07812500
11 199794.9219 199897.4609 200000.0000 102.53906250
12 199897.4609 199948.7305 200000.0000 51.26953125
13 199948.7305 199974.3652 200000.0000 25.63476563
14 199974.3652 199987.1826 200000.0000 12.81738281
15 199987.1826 199993.5913 200000.0000 6.40869141
16 199993.5913 199996.7957 200000.0000 3.20434570
17 199996.7957 199998.3978 200000.0000 1.60217285
18 199998.3978 199999.1989 200000.0000 0.80108643
19 199999.1989 199999.5995 200000.0000 0.40054321
20 199999.5995 199999.7997 200000.0000 0.20027161
21 199999.7997 199999.8999 200000.0000 0.10013580
22 199999.8999 199999.9499 200000.0000 0.05006790
23 199999.9499 199999.9750 200000.0000 0.02503395
24 199999.9750 199999.9875 200000.0000 0.01251698
25 199999.9875 199999.9937 200000.0000 0.00625849
7
CLASE 5 26 DE AGOSTO
26 199999.9937 199999.9969 200000.0000 0.00312924
27 199999.9969 199999.9984 200000.0000 0.00156462
28 199999.9984 199999.9992 200000.0000 0.00078231
29 199999.9992 199999.9996 200000.0000 0.00039116
30 199999.9996 199999.9998 200000.0000 0.00019558
31 199999.9998 199999.9999 200000.0000 0.00009779
*******tiempo: 199999.999902*********
ans =

8.0000e+22

También podría gustarte