Advertisement
Guest User

ewq

a guest
Jul 15th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 4.86 KB | None | 0 0
  1. clc
  2. funcprot(0)
  3.  
  4. u = 1 //velocidade de propagação da onda
  5. p = 1 //periodo
  6. tf = 5 //tempo final
  7. dt = 0.008 //variação do tempo
  8. dx = 0.01 //variação do espaço
  9. C = u*(dt/dx) //número de Courant
  10. t = 0:dt:tf
  11. x = 0:dx:p
  12. itert = length(t)
  13. iterx = length(x)
  14.  
  15.  
  16. //Calculo da solução inicial a ser advectada para t=0
  17.  
  18. fi = zeros(1,iterx)
  19. for i=1:iterx
  20.     fi(i) = condInicial(0,x(i),u,p)
  21. end
  22.  
  23. //Solução numérica
  24.  
  25. Quw = upwind(fi,C,t,x)
  26. Qlw = lax(fi,C,t,x)
  27. Qbw = laxfri(fi,C,t,x)
  28. Qrw= leapfrog(fi,C,t,x)
  29.  
  30. //Geração dos vetores a serem impressos para t = 1 e 5
  31.  
  32. Qtuw = [t' Quw]
  33. Qtlw = [t' Qlw]
  34. Qtbw = [t' Qbw]
  35. Qtrw = [t' Qrw]
  36.  
  37. indice = ['t'];
  38. for i=1:iterx
  39.     aux = 'Q('+string(x(i))+')'
  40.     indice = [indice aux]
  41. end
  42.  
  43. Qtuw1 = [indice;string(Qtuw(126,:));string(Qtuw(626,:))]
  44. Qtlw1 = [indice;string(Qtlw(126,:));string(Qtlw(626,:))]
  45. Qtbw1 = [indice;string(Qtbw(126,:));string(Qtbw(626,:))]
  46. Qtrw1 = [indice;string(Qtrw(126,:));string(Qtrw(626,:))]
  47.  
  48.  
  49. //Solução análitica da equação de advecção para grafico
  50. vta = 0.5 //variação do tempo para solução análitica
  51. vxa = 0.0001 //váriação do espaço para solução análitica
  52. xa = 0:vxa:p
  53. ta = 0:vta:tf
  54.  
  55. iterxa = length(xa)
  56. iterta = length(ta)
  57.  
  58. fia = zeros(iterta, iterxa)
  59. for n=1:iterta
  60.     for i=1:iterxa
  61.         fia(n,i) = condInicial(ta(n),xa(i),u,p)
  62.     end
  63. end
  64.  
  65. figure(1)
  66. titulo = 'Solução Númerica com método Upwind para t = 3 '
  67. xtitle(titulo,'x','fi(x,t)')
  68. plot(xa,fia(1,:),'colo','blue','linest','--')
  69. plot(x,Quw(376,:),'colo','red','linest','--','marker','*','markeredg','red','markerFace','green','markersize',6)
  70. a=get("current_axes")
  71. a.data_bounds=[0,-0.4;1,1.4];
  72. a.x_label.font_size = 4;                      
  73. a.y_label.font_size = 4;
  74. a.title.font_size = 4;
  75. a.cube_scaling = "on"
  76.  
  77.  
  78. figure(2)
  79. titulo = 'Solução Númerica com método Upwind para t = 5 '
  80. xtitle(titulo,'x','fi(x,t)')
  81. plot(xa,fia(1,:),'colo','blue','linest','--')
  82. plot(x,Quw(626,:),'colo','red','linest','--','marker','*','markeredg','red','markerFace','green','markersize',6)
  83. a=get("current_axes")
  84. a.data_bounds=[0,-0.4;1,1.4];
  85. a.x_label.font_size = 4;                      
  86. a.y_label.font_size = 4;
  87. a.title.font_size = 4;
  88. a.cube_scaling = "on"
  89.  
  90. figure(3)
  91. titulo = 'Solução Númerica com método Lax-Wendroff para t = 3 '
  92. xtitle(titulo,'x','fi(x,t)')
  93. plot(xa,fia(1,:),'colo','blue','linest','--')
  94. plot(x,Qlw(376,:),'colo','green','linest','--','marker','*','markeredg','green','markerFace','green','markersize',6)
  95. a=get("current_axes")
  96. a.data_bounds=[0,-0.4;1,1.4];
  97. a.x_label.font_size = 4;                      
  98. a.y_label.font_size = 4;
  99. a.title.font_size = 4;
  100. a.cube_scaling = "on"
  101.  
  102. figure(4)
  103. titulo = 'Solução Númerica com método Lax-Wendroff para t = 5 '
  104. xtitle(titulo,'x','fi(x,t)')
  105. plot(xa,fia(1,:),'colo','blue','linest','--')
  106. plot(x,Qlw(626,:),'colo','green','linest','--','marker','*','markeredg','green','markerFace','green','markersize',6)
  107. a=get("current_axes")
  108. a.data_bounds=[0,-0.4;1,1.4];
  109. a.x_label.font_size = 4;                      
  110. a.y_label.font_size = 4;
  111. a.title.font_size = 4;
  112. a.cube_scaling = "on"
  113.  
  114.  
  115. figure(5)
  116. titulo = 'Solução Númerica com método Lax-Friedrichs para t = 3 '
  117. xtitle(titulo,'x','fi(x,t)')
  118. plot(xa,fia(1,:),'colo','blue','linest','--')
  119. plot(x,Qbw(376,:),'colo','red','linest','--','marker','*','markeredg','red','markerFace','green','markersize',6)
  120. a=get("current_axes")
  121. a.data_bounds=[0,-0.4;1,1.4];
  122. a.x_label.font_size = 4;                      
  123. a.y_label.font_size = 4;
  124. a.title.font_size = 4;
  125. a.cube_scaling = "on"
  126.  
  127. figure(6)
  128. titulo = 'Solução Númerica com método Lax-Friedrichs para t = 5 '
  129. xtitle(titulo,'x','fi(x,t)')
  130. plot(xa,fia(1,:),'colo','blue','linest','--')
  131. plot(x,Qbw(626,:),'colo','red','linest','--','marker','*','markeredg','red','markerFace','green','markersize',6)
  132. a=get("current_axes")
  133. a.data_bounds=[0,-0.4;1,1.4];
  134. a.x_label.font_size = 4;                      
  135. a.y_label.font_size = 4;
  136. a.title.font_size = 4;
  137. a.cube_scaling = "on"
  138.  
  139. figure(7)
  140. titulo = 'Solução Númerica com método Leapfrog para t = 3 '
  141. xtitle(titulo,'x','fi(x,t)')
  142. plot(xa,fia(1,:),'colo','blue','linest','--')
  143. plot(x,Qrw(376,:),'colo','red','linest','--','marker','*','markeredg','red','markerFace','green','markersize',6)
  144. a=get("current_axes")
  145. a.data_bounds=[0,-0.4;1,1.4];
  146. a.x_label.font_size = 4;                      
  147. a.y_label.font_size = 4;
  148. a.title.font_size = 4;
  149. a.cube_scaling = "on"
  150.  
  151. figure(8)
  152. titulo = 'Solução Númerica com método Leapfrog para t = 5 '
  153. xtitle(titulo,'x','fi(x,t)')
  154. plot(xa,fia(1,:),'colo','blue','linest','--')
  155. plot(x,Qrw(626,:),'colo','red','linest','--','marker','*','markeredg','red','markerFace','green','markersize',6)
  156. a=get("current_axes")
  157. a.data_bounds=[0,-0.4;1,1.4];
  158. a.x_label.font_size = 4;                      
  159. a.y_label.font_size = 4;
  160. a.title.font_size = 4;
  161. a.cube_scaling = "on"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement