Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Program for calucluating the displacement of a mass on a spring*/
- #include <iostream>
- #include <cmath>
- #include <math.h>
- #include <iomanip>
- bool valid;
- using namespace std;
- int main()
- {
- // declaring initial values
- double Wn, Wd, K, M, S, A; // declare variables
- // allow user to input values
- cout << "Enter Value For Initial Displacement: ";
- cin >> A;
- cout << "Enter Value For Spring Constant: ";
- cin >> K;
- cout << "Enter Value For Mass: ";
- cin >> M;
- do
- {
- valid = true;
- cout << "Please enter a dampening ratio: ";
- cin >> S;
- cin.ignore(100, '\n');
- if (S <= 0 || S >= 1)
- {
- valid = false;
- cout << "Dampening ratio must be greater than 0 and less than 1. Try again." << endl;
- }
- } while (!valid);
- //initialise variables
- Wn = sqrt(K / M);
- Wd = Wn * sqrt(1 - pow(S, 2));
- cout << "Therefore";
- cout << "\n";
- cout << "Wn = " << Wn;
- cout << "\n";
- cout << "Wd = " << Wd;
- cout << "\n";
- //double i;
- //double time [100];
- double t = 0;
- double V1;
- V1 = -S * Wn;
- double X(double A, double V1, double Wd, double t);
- {
- return A * (exp(V1 * t)) * cos(Wd*t);
- }
- double results[100];
- for (size_t i = 0; i < 100; ++i)
- {
- double t = (i * 250) / 1000.0;
- results[i] = X(A, V1, Wd, t);
- std::cout << X(A, V1, Wd, t) << "\n";
- }
- //for (i = 0; i < 26; i = i + 0.25);
- //{
- //time[i] = A * (exp(-S * Wn * i)) * cos(Wd*i);
- //cout << time[i] << "*" << endl;
- //}
- //double V2;
- //double V3;
- //i = 2;
- //V2 = exp(V1 * i);
- //V3 = cos (Wd * i);
- //X = A * (exp(V1 * i)) * cos( Wd*i );
- //cout << "V1 is equal to " << V1 << endl;
- //cout << "V2 is equal to " << V2 << endl;
- //cout << "value is equal to " << value << endl;
- //cout << "X is equal to " << X << endl;
- system("Pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement