Advertisement
ivodevweb

Untitled

Jan 25th, 2023
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 1.44 KB | Software | 0 0
  1. % UC: 21048 - Física Geral
  2. % Ano 2022/23 - EFOLIO B - Gráfico Pêndulo Gravítico - UAb
  3. %  Aluno: 2100927 - Ivo Baptista
  4.  
  5. % Constantes
  6. m = 2.6*0.001;  % Massa em Kg
  7. L = 1.0;  % Comprimento do fio em memtros
  8. R = 30*0.01; % Raio 30 cm convertido para metros
  9. p = 1.28 % densidade do ar em kg/m^3
  10. g = 9.81; % Aceleração da gravidade em m/s^2
  11.  
  12. A = pi * R^2;
  13. % Calcula o coeficiente de arrasto aerodinâmico
  14. b = 1/2 * p * cd *A;
  15.  
  16. % Valores iniciais
  17. theta0 = 0.05;  % Ângulo inicial em rad
  18. w0 = 0.0;       % Velocidade angular inicial em rad/s
  19. t0 = 0.0;       % Tempo inicial em s
  20. h = 0.1;        % Passo de tempo em s
  21.  
  22. % Vetores para armazenar os resultados
  23. t = t0;
  24. theta = theta0;
  25. w = w0;
  26.  
  27. % Loop de tempo
  28. while (t0 < 100.0)
  29.   % Cálculo dos valores intermediários
  30.   k1x = w0;
  31.   k1v = (-sign(w0) * (b*L)/m * (w0)^2 - (g / L) * theta0);
  32.   k2x = w0 + k1v*h;  
  33.   k2v = -sign(w0 + k1v*h) * (((b*L)/m) * (w0 + k1v*h)**2) - (g/L) * (theta0 + k1x*h);
  34.  
  35.   % Atualização dos valores de θ e w
  36.   theta0 = theta0 + ((k1x + k2x) / 2.0)*h;
  37.   w0 = w0 + ((k1v + k2v) / 2.0)*h;
  38.  
  39.   % Atualização do tempo
  40.   t0 = t0 + h;
  41.  
  42.   % Adiciona os resultados aos vetores
  43.   t = [t t0];
  44.   theta = [theta theta0];
  45.   w = [w w0];
  46. end
  47.  
  48. % Cria o gráfico
  49. plot(t, theta, 'r', t, w, 'b')
  50.  
  51. % Adiciona legenda
  52. legend('Theta', 'w')
  53. % Adiciona títulos aos eixos
  54. xlabel('tempo (s)');
  55. ylabel('Theta (rad), w (rad/s)');
  56. % Exibe o gráfico
  57. hold off;
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement