Advertisement
FelipeNeto2

Matlab backup

Apr 1st, 2024 (edited)
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.97 KB | None | 0 0
  1. % Parâmetros
  2. u1 = 1;           % Condição inicial
  3. phi = 1;          % Porosidade
  4. V = 1;            % Velocidade
  5. L = 1;            % Comprimento do domínio (0,L)
  6. T = 1;            % Tempo Final
  7. n = 100;          % Número de pontos
  8.  
  9. dx = L / (n - 1);
  10. x = linspace(0, L, n);  % Malha espacial
  11.  
  12. dt = 0.01;
  13. t = 0:dt:T;  % Malha temporal
  14.  
  15. % Inicialização da matriz B com as condições iniciais
  16. B = zeros(n, 1);
  17. B(1) = u1;
  18.  
  19. % Inicialização da matriz A
  20. A = zeros(n, n);
  21. A(1, 1) = 1;
  22.  
  23. % Coeficientes da matriz A
  24. A1 = -(V*dt/(phi*dx));
  25. A2 = 1 + V*dt/(phi*dx);
  26.  
  27. for i = 2:n - 1
  28.     A(i, i - 1) = A1;
  29.     A(i, i) = A2;
  30. end
  31.  
  32. % Solução dos sistemas A*u = B
  33. figure;  % Criação da figura
  34. for j = 2:length(t)
  35.     u = A\B;
  36.     B = u;
  37.     plot(x, u);
  38.     hold on;
  39. end
  40.  
  41. xlabel('x');
  42. ylabel('u');
  43. title('Solução usando Volumes Finitos - Implícito');
  44. legend('t=0.1', 't=0.2', 't=0.3', 't=0.4', 't=0.5', 't=0.6', 't=0.7', 't=0.8', 't=0.9', 't=1.0');
  45. grid on;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement