don t need to submit printed graphs. 1) When an object with mass m oscillates wh
ID: 3732135 • Letter: D
Question
don t need to submit printed graphs. 1) When an object with mass m oscillates while attached to a spring of stiffness constant k, the period of the oscillation is given by: T-2rym/k . The frequency of the oscillation is f=1/T a) Write a function that takes as input a 1 by 2 array S that contains the mass and stiffness constant as its two elements and returns a i by 2 vector that contains as its elements the period and frequency. e.g. p- osc p f(S) where p- (period frequency and S=(mass, stiffness). b) The mechanical energy of an oscillator when the mass has position x and velocity v is given by: E-(1/2)mv? +(1/2)kx?. If frictional forces are negligible this quantity will remain constant over the course of many oscillation cycles. If the energy is known the amplitude of the oscillation can be determined from the equation: E=(I/2)ka". Write a function that calculates the energy and amplitude of an oscillator from a l by4 input vector: z=(mass,stiffness,position, velocity) . The output is a 1 by 2 vector (energy amplitude).Explanation / Answer
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265
double* osc_p_f(double S[2])
{
double T,f,P[2];
T = 2 * PI * sqrt(S[0] / S[1]);
f = 1 / T;
P[0] = T;
P[1] = f;
return P;
}
double* energy_f(double Z[4])
{
double Q[2];
Q[0] = ((Z[0] * Z[3] * Z[3]) + (Z[1] * Z[2] * Z[2])) / 2;
Q[1] = sqrt( ( 2 * Q[0] ) / Z[1] );
return Q;
}
int main()
{
double *P,S[2];
cout<<" Enter the mass : ";
cin>>S[0];
cout<<" Enter the stiffness : ";
cin>>S[1];
P = osc_p_f(S);
cout<<" Time period : "<<P[0];
cout<<" Frequence : "<<P[1];
double Z[4],*Q;
cout<<" Enter the mass : ";
cin>>Z[0];
cout<<" Enter the stiffness : ";
cin>>Z[1];
cout<<" Enter the position :";
cin>>Z[2];
cout<<" Enter the velocity :";
cin>>Z[3];
Q = energy_f(Z);
cout<<" Energy : "<<Q[0];
cout<<" Amplitude : "<<Q[1];
}
For any queries or doubt, please reply in the comment section.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.