include #include using namespace std; int main() { const int MAXPOINTS = 100; int i, npts, nval[MAXPOINTS]; double x, fval, ymin, ymax, width, sval[MAXPOINTS]; char label[] = " y axis"; char axis[] = "+---------------------------------------------------->"; char line[] = "| "; ymax = 1.0e-5; ymin = 1.0e5; width = 53; // Load the data to be plotted and find the max and min values i = 1; for (x = −5.0; x ymax) ymax = sval[i]; if (sval[i] < ymin) ymin = sval[i]; i++; if (i >= MAXPOINTS) break; // don't exceed the maximum points } npts =

icon
Related questions
Question
include #include using namespace std; int main() { const int MAXPOINTS = 100; int i, npts, nval[MAXPOINTS]; double x, fval, ymin, ymax, width, sval[MAXPOINTS]; char label[] = " y axis"; char axis[] = "+---------------------------------------------------->"; char line[] = "| "; ymax = 1.0e-5; ymin = 1.0e5; width = 53; // Load the data to be plotted and find the max and min values i = 1; for (x = −5.0; x ymax) ymax = sval[i]; if (sval[i] < ymin) ymin = sval[i]; i++; if (i >= MAXPOINTS) break; // don't exceed the maximum points } npts = i − 1; // Scale all the y values for (i=1; i |* |* |* |* |* |* |* |* |* |* |* |* |* |* |* |* |* |* |* |* |* Please modify to question 15
15. (Physics) Figure 7.16 shows a harmonic oscillator, which consists of an object of mass, m,
attached to one end of a spring. The spring's other end is attached to a wall, and the object is
free to slide over a frictionless surface. Assuming the object is initially at rest (that is, the spring
is neither stretched nor compressed) and then pulled to position A at time t = 0, the displace-
ment of the mass at any other time, 1, is given by this formula:
x = A cos (2 VEm)
x is the displacement.
k is the spring constant (N/m).
m is the mass (kg).
A is the initial displacement (cm).
Assuming A is 10 centimeters, k is 150 N/m, and m is 200 kilograms, modify Program 7.13 to
plot the displacement of the mass from t = 0 to t = 20 seconds in increments of 0.25 seconds.
m
X = -A
X = 0
X = +A
Figure 7.16 A harmonic oscillator
Transcribed Image Text:15. (Physics) Figure 7.16 shows a harmonic oscillator, which consists of an object of mass, m, attached to one end of a spring. The spring's other end is attached to a wall, and the object is free to slide over a frictionless surface. Assuming the object is initially at rest (that is, the spring is neither stretched nor compressed) and then pulled to position A at time t = 0, the displace- ment of the mass at any other time, 1, is given by this formula: x = A cos (2 VEm) x is the displacement. k is the spring constant (N/m). m is the mass (kg). A is the initial displacement (cm). Assuming A is 10 centimeters, k is 150 N/m, and m is 200 kilograms, modify Program 7.13 to plot the displacement of the mass from t = 0 to t = 20 seconds in increments of 0.25 seconds. m X = -A X = 0 X = +A Figure 7.16 A harmonic oscillator
Program 7.13
tinclude <iostream>
linclude <emath>
using namespace std;
int main()
const int MAXPOINTS = 100:
int i, npts, nval(MAXPOINTS];
double x, fval, ymin, ymax, width, sval[MAXPOINTS);
y axis";
char label0 - "
char axis[] = "+-
char line[] = "|
ymax - 1.0e-5;
ymin - 1.0e5;
width = 53;
// Load the data to be plotted and find the max and min values
i- 1;
for (x = -5.0; x <= 5.0; x += 0.5)
sval[i] = pow (x, 3.0);
if (sval[i] > ymax) ymax = sval[i];
if (sval(i) < ymin) ymin = sval[i];
i++;
if (i >= MAXPOINTS) break; // don't exceed the maximum points
npts = i - 1;
// Scale all the y values
for (i=1; i <= npts; i++)
fval = (sval[i] - ymin)/(ymax - ymin)* (width - 1) + 1;
nval[i] - fval + 0.5; // convert to an integer value
// Produce the plot
cout << "Minimum y value: " << ymin << endl;
cout << "Maximum y value: " << ymax << endl;
cout << label << endl;
cout << axis << endl;
Copyright 2012 Cengage Leaming All Righe Reservod. May not he copiod, cannod. or duplicated,in whole orin part. Due to clecic rights, some thind party content muy he ppreed tom the cllook andir Chupter.
Edtorial eview has doemed that any presed cmtet dees t materially allot the overal leaning enperiene. Cenpage Leaning reserves the rightte romeve alitinal ontonty timei vaegent rights rerictio require it
428 Arrays
for (i - 1; i <- npts; i++)
line[ (nval[i] + 2)] - *';
cout <« line << endl;
line[ (nval(i] + 2)) - ';
// set character to an asterisk
// output the line
// reset character to a blank
return 0;
Program 7.13 produces the following output:
Minimum y value: -125
Maximum y value: 125
y axis
Transcribed Image Text:Program 7.13 tinclude <iostream> linclude <emath> using namespace std; int main() const int MAXPOINTS = 100: int i, npts, nval(MAXPOINTS]; double x, fval, ymin, ymax, width, sval[MAXPOINTS); y axis"; char label0 - " char axis[] = "+- char line[] = "| ymax - 1.0e-5; ymin - 1.0e5; width = 53; // Load the data to be plotted and find the max and min values i- 1; for (x = -5.0; x <= 5.0; x += 0.5) sval[i] = pow (x, 3.0); if (sval[i] > ymax) ymax = sval[i]; if (sval(i) < ymin) ymin = sval[i]; i++; if (i >= MAXPOINTS) break; // don't exceed the maximum points npts = i - 1; // Scale all the y values for (i=1; i <= npts; i++) fval = (sval[i] - ymin)/(ymax - ymin)* (width - 1) + 1; nval[i] - fval + 0.5; // convert to an integer value // Produce the plot cout << "Minimum y value: " << ymin << endl; cout << "Maximum y value: " << ymax << endl; cout << label << endl; cout << axis << endl; Copyright 2012 Cengage Leaming All Righe Reservod. May not he copiod, cannod. or duplicated,in whole orin part. Due to clecic rights, some thind party content muy he ppreed tom the cllook andir Chupter. Edtorial eview has doemed that any presed cmtet dees t materially allot the overal leaning enperiene. Cenpage Leaning reserves the rightte romeve alitinal ontonty timei vaegent rights rerictio require it 428 Arrays for (i - 1; i <- npts; i++) line[ (nval[i] + 2)] - *'; cout <« line << endl; line[ (nval(i] + 2)) - '; // set character to an asterisk // output the line // reset character to a blank return 0; Program 7.13 produces the following output: Minimum y value: -125 Maximum y value: 125 y axis
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer