Advertisement
ivodevweb

Untitled

Jan 25th, 2023
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 1.87 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. clc         % limpa a tela do terminal
  6. close all   % Fecha os graficos que estão abertos
  7. clear all   % limpa o valor das variaveis em memoria
  8.  
  9. % Constantes
  10. m = 0.0026;  % Massa em g
  11. L = 1.0;  % Comprimento em m
  12. r = 0.3; % Raio em m
  13. g = 9.81; % Aceleração da gravidade em m/s^2
  14. rho = 1.2; % Massa específica do ar em kg/m^3
  15. cd = 0.1;  % Coeficiente de arrasto
  16. A = pi * r^2; % Área transversal da esfera
  17.  
  18. % Calcula o coeficiente de arrasto aerodinâmico
  19. b = 1/2 * rho * cd * A;
  20.  
  21. % Valores iniciais
  22. theta0 = 0.05;  % Ângulo inicial em rad
  23. w0 = 0.0;       % Velocidade angular inicial em rad/s
  24. t0 = 0.0;       % Tempo inicial em s
  25. h = 0.1;        % Passo de tempo em s
  26. t = 0;          % Valor inicial do tempo
  27. tend = 100;     % Valor final do tempo
  28.  
  29.  
  30. ciclos = (tend - t)/h   % Numero de ciclos
  31.  
  32. % Listas para armazenar os resultados
  33. t = t0;
  34. theta = theta0;
  35. w = w0;
  36.  
  37. % Apresentação de Titulo
  38. hold on;
  39. grid;
  40. title('EfolioB - Fisica - Pendulo Gravitico');
  41. axis ([t, tend, -0.15, 0.15]);
  42.  
  43.  
  44. % Loop de tempo
  45. while t(end) < ciclos
  46.     k1x = w(end);
  47.     k1v = -sign(w(end)) * (((b*L)/m) * w(end)^2) - (g / L) * theta(end);
  48.     k2x = w(end) + k1v * h;
  49.     k2v = -sign(w(end) + k1v *h) * (((b*L)/m )* (w(end) + k1v *h)^2) - (g / L) * (theta(end)+k1x(end)*h);
  50.  
  51.     % Atualização dos valores de θ e w
  52.     theta = [theta, theta(end) + ((k1x + k2x) / 2.0)*h];
  53.     w = [w, w(end) + ((k1v + k2v) / 2.0)*h];
  54.  
  55.     % Atualização do tempo
  56.     t = [t, t(end) + h];
  57. end
  58.  
  59.  
  60. % Adiciona uma linha para w com a linha azul
  61. hold on;
  62. plot(t, theta, 'r',t, w, 'b');
  63. % Adiciona uma legenda
  64. legend('Theta', 'w');
  65. % Adiciona títulos aos eixos
  66. xlabel('tempo (s)');
  67. ylabel('Theta (rad), w (rad/s)');
  68. grid on;
  69. % Exibe o gráfico
  70. hold off;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement