Advertisement
Guest User

mini project

a guest
Nov 23rd, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. /*Program for calucluating the displacement of a mass on a spring*/
  2. #include <iostream>
  3. #include <cmath>
  4. #include <math.h>
  5. #include <iomanip>
  6. bool valid;
  7. using namespace std;
  8. int main()
  9. {
  10. // declaring initial values
  11. double Wn, Wd, K, M, S, A; // declare variables
  12.  
  13.  
  14. // allow user to input values
  15. cout << "Enter Value For Initial Displacement: ";
  16. cin >> A;
  17. cout << "Enter Value For Spring Constant: ";
  18. cin >> K;
  19. cout << "Enter Value For Mass: ";
  20. cin >> M;
  21.  
  22. do
  23. {
  24. valid = true;
  25. cout << "Please enter a dampening ratio: ";
  26. cin >> S;
  27. cin.ignore(100, '\n');
  28.  
  29. if (S <= 0 || S >= 1)
  30. {
  31. valid = false;
  32. cout << "Dampening ratio must be greater than 0 and less than 1. Try again." << endl;
  33. }
  34.  
  35. } while (!valid);
  36.  
  37.  
  38. //initialise variables
  39. Wn = sqrt(K / M);
  40. Wd = Wn * sqrt(1 - pow(S, 2));
  41.  
  42.  
  43. cout << "Therefore";
  44. cout << "\n";
  45. cout << "Wn = " << Wn;
  46. cout << "\n";
  47. cout << "Wd = " << Wd;
  48. cout << "\n";
  49. //double i;
  50. //double time [100];
  51.  
  52. double t = 0;
  53. double V1;
  54. V1 = -S * Wn;
  55. double X(double A, double V1, double Wd, double t);
  56. {
  57. return A * (exp(V1 * t)) * cos(Wd*t);
  58. }
  59.  
  60. double results[100];
  61. for (size_t i = 0; i < 100; ++i)
  62. {
  63. double t = (i * 250) / 1000.0;
  64. results[i] = X(A, V1, Wd, t);
  65. std::cout << X(A, V1, Wd, t) << "\n";
  66. }
  67.  
  68.  
  69. //for (i = 0; i < 26; i = i + 0.25);
  70. //{
  71.  
  72.  
  73. //time[i] = A * (exp(-S * Wn * i)) * cos(Wd*i);
  74. //cout << time[i] << "*" << endl;
  75.  
  76. //}
  77.  
  78.  
  79. //double V2;
  80. //double V3;
  81.  
  82.  
  83. //i = 2;
  84. //V2 = exp(V1 * i);
  85. //V3 = cos (Wd * i);
  86.  
  87. //X = A * (exp(V1 * i)) * cos( Wd*i );
  88. //cout << "V1 is equal to " << V1 << endl;
  89. //cout << "V2 is equal to " << V2 << endl;
  90. //cout << "value is equal to " << value << endl;
  91. //cout << "X is equal to " << X << endl;
  92.  
  93.  
  94.  
  95.  
  96. system("Pause");
  97.  
  98. return 0;
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement