Advertisement
ivodevweb

Untitled

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