Beruflich Dokumente
Kultur Dokumente
Universidad Nacional
de Colombia
Herramientas computacionales.
Facultad de Ciencias
20 de julio de 2019
16 C (1 ,1)=2;
17 C ( numx ,1)=2;
18
19
20 mu =0.3;
21 mu2 =0.7;
22 sigma =0.05;
23 sigma2 =0.03;
24 for i =2:( numx -1) %Pulso Inicial
25 C (i ,1)= exp ( -( x ( i ) - mu )^2/(2* sigma ^2))/ sqrt (2* pi * sigma ^2)+...
26 exp ( -( x ( i ) - mu2 )^2/(2* sigma2 ^2))/ sqrt (2* pi * sigma2 ^2);
27 end
28
29
30
42 plot (x , C (: , j ));
43 axis ([0 1 -2 15])
44 pause (0.2)
45 end
1 clear all ;
2 close all ;
3 clf ;
4
16 C (1 ,1)=2;
17 C ( numx ,1)=2;
18
19 a =1;
20 b =1;
21
22 mu =0.3;
23 mu2 =0.7;
24 sigma =0.05;
25 sigma2 =0.03;
26 for i =2:( numx -1) %Pulso Inicial
27 C (i ,1)= exp ( -( x ( i ) - mu )^2/(2* sigma ^2))/ sqrt (2* pi * sigma ^2);...
28 %exp ( -( x ( i ) - mu2 )^2/(2* sigma2 ^2))/ sqrt (2* pi * sigma2 ^2);
29 end
30 for i =2:( numx -1) %Pulso Inicial
31 C (i ,2)= exp ( -( x ( i ) -1 - mu )^2/(2* sigma ^2))/ sqrt (2* pi * sigma ^2);...
32 %exp ( -( x ( i ) - mu2 )^2/(2* sigma2 ^2))/ sqrt (2* pi * sigma2 ^2);
33 end
34
35 m = sqrt ( -1);
36 figure (1); clf ;
37 for j =1: numt ; %Evolucion Temporal
38 t ( j +1)= t ( j )+ dt ;
39 for i =2:( numx -1) %Despliegue espacial para cada paso de tiempo
40 C (i , j +1)= C (i , j ) +( m * a * dt /( dx ^2))*( C ( i +1 , j ) -2* C (i , j )+...
41 C (i -1 , j ))+ m * dt /(1+ b * C (i , j )^2);
42 G (: , j +1)= real ( C (: , j +1));
43 end
44 G (1 , j +1)=0; %Fixed End
45 G ( numx , j +1)=0; %Fixed End
46
∂u ∂2u
− D 2 − Av = 0
∂t ∂x
∂u ∂2u
− D 2 + Bu = 0
∂t ∂x
Para este caso, las ecuaciones quedan escritas de la siguiente manera:
(uni+1 − 2un−1
i + uni−1 )
uni = d∆t 2
− avin ∆t + uin−1
(δx)
n
(vi+1 − 2vin−1 + vi−1
n
)
vin = d∆t − auni ∆t + vin−1
(∆x)2
1 clear all ;
2 close all ;
3 clf ;
4
18 a =1;
19 b =1;
20
21 mu =0.3;
22 mu2 =0.5;
23 sigma =0.05;
24 sigma2 =0.03;
25 for i =2:( numx -1) %Pulso Inicial
26 C (i ,1)= exp ( -( x ( i ) - mu )^2/(2* sigma ^2))/ sqrt (2* pi * sigma ^2);
27 G (i ,1)= exp ( -( x ( i ) - mu2 )^2/(2* sigma2 ^2))/ sqrt (2* pi * sigma2 ^2);
28 H (i ,1)= exp ( -( x ( i ) - mu )^2/(2* sigma ^2))/ sqrt (2* pi * sigma ^2)+...
29 exp ( -( x ( i ) - mu2 )^2/(2* sigma2 ^2))/ sqrt (2* pi * sigma2 ^2);
30 end
31
32
33
(uni+1 − 2un−1
i + uni−1 )
uni = d∆t − Auni vin ∆t + un−1
i
(∆x)2
n
(vi+1 − 2vin−1 + vi−1
n
)
vin = d∆t 2
+ Buni (vu in )2 ∆t + vin−1
(∆x)
1 clear all ;
2 close all ;
3 clf ;
4
13 t (1)=0;
14 t (2)=0; %Condicion Inicial
15 C = zeros ( numx , numt ); %Se inicia la funcion ceros
16 G = zeros ( numx , numt );
17 H = zeros ( numx , numt );
18
19 a =0.1;
20 b =0.1;
21 f =1000;
22
23 mu =0.3;
24 mu2 =0.5;
25 sigma =0.05;
26 sigma2 =0.03;
27 for i =2:( numx -1) %Pulso Inicial
28 C (i ,1)= exp ( -( x ( i ) - mu )^2/(2* sigma ^2))/ sqrt (2* pi * sigma ^2);
29 G (i ,1)= exp ( -( x ( i ) - mu2 )^2/(2* sigma2 ^2))/ sqrt (2* pi * sigma2 ^2);
30 H (i ,1)= exp ( -( x ( i ) - mu )^2/(2* sigma ^2))/ sqrt (2* pi * sigma ^2)+...
31 exp ( -( x ( i ) - mu2 )^2/(2* sigma2 ^2))/ sqrt (2* pi * sigma2 ^2);
32 end
33 for i =2:( numx -1) %Pulso Inicial
34 C (i ,2)= exp ( -( x ( i ) - mu )^2/(2* sigma ^2))/ sqrt (2* pi * sigma ^2);
35 G (i ,2)= exp ( -( x ( i ) - mu2 )^2/(2* sigma2 ^2))/ sqrt (2* pi * sigma2 ^2);
36 H (i ,2)= exp ( -( x ( i ) - mu )^2/(2* sigma ^2))/ sqrt (2* pi * sigma ^2)+...
37 exp ( -( x ( i ) - mu2 )^2/(2* sigma2 ^2))/ sqrt (2* pi * sigma2 ^2);
38 end
39
40
5. En base al código de dinámica molecular, implementar paredes en la frontera, para que las partı́culas
experimenten colisiones elásticas. Haciendo que la componente de la velocidad normal cambie de direc-
44 %while 1
45 for tiempo = 1:3000
46 step = step + 1;
47 % integrate using Verlet algorithm
48 r = r + v * dt + 0.5* a * dt ^2;
49 K = 0;
50 for i = 1: N % periodic boundary conditions
51 if r (1 , i ) < 0 , v (1 , i )= - v (1 , i ) ; end
52 if r (2 , i ) < 0 , v (2 , i )= - v (2 , i ) ; end
53 if r (1 , i ) > L (1) , v (1 , i )= - v (1 , i ) ; end
54 if r (2 , i ) > L (2) , v (2 , i )= - v (2 , i ) ; end
55 vSquared = v (: , i ). ’* v (: , i );
56 K = K + 0.5* vSquared ;
57 bin = round ( sqrt ( vSquared ) / vMax * nBins );
58 if ( bin > 0 && bin <= nBins ) , vBins ( bin ) = vBins ( bin ) + 1; end
59 end
60 Tsum = Tsum + K / N ;
61 T = Tsum / step ;
62 v = v + 0.5* a * dt ;
63 a = accel (L ,N , r );
64 v = v + 0.5* a * dt ;
65 t = t + dt ;
66 if mod ( step ,10) == 0 % update molecule positions 75
67 figure (1);
68 set (p , ’ XData ’ , r (1 ,:) , ’ YData ’ , r (2 ,:));
69 title ( sprintf ( ’ Step = %i Time t = % .3 g <K > = % .3 g ’ , step ,t , K / N ));
70 drawnow ;
71 %end
72 %if mod ( step ,50) == 0 % update velocity histogram
73 %end
74 figure (2); clf ;
75 bar ( vVals , vBins / max ( vBins ));
76 title ( ’ Maxwell - Boltzmann Velocity Distribution ’ );
77 xlabel ( ’ Velocity v ’ );
78 ylabel ( ’P ( v ) ’ );
79 colormap hsv ;
80 hold on ;
81 for i = 1: nBins
82 MB ( i ) = vVals ( i ) * exp ( -0.5* vVals ( i )^2/ T );
83 end
84 plot ( vVals , MB / max ( MB ) , ’g ’ );
85 legend ( sprintf ( ’T = %g ’ ,T ));
86 drawnow ;
87 end
88 end