Advertisement
ivodevweb

Untitled

Jan 13th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.46 KB | Software | 0 0
  1. % Constantes
  2. m = 2.6;  % Massa em g
  3. L = 1.0;  % Comprimento em m
  4. r = 0.003; % Raio em m
  5. g = 9.81; % Aceleração da gravidade em m/s^2
  6. rho = 1.2; % Massa específica do ar em kg/m^3
  7. cd = 0.1;  % Coeficiente de arrasto
  8. A = pi * r^2; % Área transversal da esfera
  9.  
  10. % Calcula o coeficiente de arrasto aerodinâmico
  11. b = 1/2 * rho * cd * A;
  12.  
  13. % Valores iniciais
  14. theta0 = 0.05;  % Ângulo inicial em rad
  15. w0 = 0.0;       % Velocidade angular inicial em rad/s
  16. t0 = 0.0;       % Tempo inicial em s
  17. h = 0.1;        % Passo de tempo em s
  18.  
  19. % Listas para armazenar os resultados
  20. t = t0;
  21. theta = theta0;
  22. w = w0;
  23. k1x = 0;
  24. k1v = 0;
  25. k2x = 0;
  26. k2v = 0;
  27.  
  28. % Loop de tempo
  29. while t(end) < 100.0
  30.     % Cálculo dos valores intermediários
  31.     k1x = w(end);
  32.     k1v = -sign(w(end)) * (((b*L)/m) * w(end)^2) - (g / L) * theta(end);
  33.     k2x = w(end) + k1v * h;
  34.     k2v = -sign(w(end) + k1v h) * (((b*L)/m ) (w(end) + k1v *h)^2) - (g / L) * (theta(end)+k1x(end)*h);
  35.  
  36.     % Atualização dos valores de θ e w
  37.     theta = [theta, theta(end) + ((k1x + k2x) / 2.0)*h];
  38.     w = [w, w(end) + ((k1v + k2v) / 2.0)*h];
  39.  
  40.     % Atualização do tempo
  41.     t = [t, t(end) + h];
  42. end
  43.  
  44.  
  45.  
  46. % Cria o gráfico para θ com a linha vermelha
  47. plot(t, theta, 'r');
  48. % Adiciona uma linha para w com a linha azul
  49. hold on;
  50. plot(t, w, 'b');
  51. % Adiciona uma 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;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement