Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function test(U0, UL, phi, vel, D, x_adim, t_adim)
- % Parâmetros adimensionais
- L = max(x_adim); % Comprimento do intervalo
- T = max(t_adim); % Tempo final
- t_ref = D / (phi * L^2); % Tempo característico
- T_estrela = T / t_ref; % Tempo final adimensional
- % Número de pontos na malha espacial
- n = length(x_adim);
- dx = L / (n - 1);
- % Variáveis e malhas adimensionais
- dt = t_adim(2) - t_adim(1);
- B = zeros(n, 1);
- % Preenchimento da matriz inicial B
- B(1) = U0;
- B(end) = UL;
- % Inicialização da matriz A
- A = zeros(n);
- pe = (vel*L)/D;
- % Coeficientes da matriz A
- A1 = dt * (-1/dx^2);
- A2 = dt * (1/dt + pe/dx + 2/dx^2);
- A3 = dt * (-pe/dx - 1/dx^2);
- for i = 2:n-1
- A(i, i - 1) = A1;
- A(i, i) = A2;
- A(i, i + 1) = A3;
- end
- A(1, 1) = 1;
- A(end, end) = 1;
- tempos = [0.09, 0.14, 0.19, 0.32] * T_estrela;
- % Solução dos sistemas A*u = B
- for j = 2:length(t_adim)
- u = A \ B; % Resolve o sistema linear
- % Verificar se o tempo atual está nos tempos desejados
- if any(abs(t_adim(j) - tempos) < eps)
- % Se sim, plotar a solução numérica
- plot(x_adim * L, u, 'r'); % Convertendo x' de volta para x
- hold on;
- end
- % Atualiza o B para o próximo passo de tempo
- B = u;
- end
- xlabel('x');
- ylabel('C');
- title('Solução da Equação de Convecção-Difusão (Adimensional)');
- grid on;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement