Advertisement
ivodevweb

Untitled

Jan 21st, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | Software | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <fstream>
  4. #include <vector>
  5.  
  6. int main()
  7. {
  8.     // Constantes
  9.     const double m = 2.6;  // Massa em g
  10.     const double L = 1.0;  // Comprimento em m
  11.     const double R = 0.03; // Raio em m
  12.  
  13.     // Valores iniciais
  14.     double theta0 = 0.05;  // Ângulo inicial em rad
  15.     double w0 = 0.0;       // Velocidade angular inicial em rad/s
  16.     double t0 = 0.0;       // Tempo inicial em s
  17.     double h = 0.1;        // Passo de tempo em s
  18.  
  19.     // Listas para armazenar os resultados
  20.     std::vector<double> t;
  21.     std::vector<double> theta;
  22.     std::vector<double> w;
  23.  
  24.     t.push_back(t0);
  25.     theta.push_back(theta0);
  26.     w.push_back(w0);
  27.  
  28.     // Loop de tempo
  29.     while (t.back() < 100.0)
  30.     {
  31.         // Cálculo dos valores intermediários
  32.         double k1x = h * w.back();
  33.         double k1v = h * (-1.0 if w.back() < 0.0 else 1.0);
  34.  
  35.         // Atualização dos valores de θ e w
  36.         theta.push_back(theta.back() + k1x);
  37.         w.push_back(w.back() + k1v);
  38.  
  39.         // Atualização do tempo
  40.         t.push_back(t.back() + h);
  41.     }
  42.  
  43. return 0;
  44. }
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement