Question

An advantage of programming is the ability to perform millions of calculations and dump it to...

An advantage of programming is the ability to perform millions of calculations and dump it to a file for plotting. This can be extremely useful for engineers if they are simulating or characterizing a system. Below you will calculate data, write it to a file, and plot the contents in excel.

a)

Create a csv file for writing. This can be done by creating a file with the open method as we

have done in class but with a *.csv extension in the file name . For example

outFile.open(“equation.csv”);

b)

Declare a double variable t and initialize its value to 0.01

c)

Write a loop that increments t value by .01 from 0 to 9 and calculate the following for each t

y = e^(−t/1.5)∗cos(t)

d)

To calculate e^(−t/1.5) and cos (t), you can use the exp() function and cos() function in the cmatch library. For example: include<cmath.h> double x = exp(1.1);//the value of x will be

e^1.1

double m=cos(2.2);//

the value of m will be cos(2.2);

e)

Now write your data to the csv file. The goal is to plot the information in excel, which mean that in the first column we shall have our x values, and the second column the calculated y

values. The format of a cvs file states that every comma denotes the end of the contents in a given column. A newline denotes a new row.

Thus

12,3,8

4,6,9

will be saved in excel as:

12, 3, 8

4, 6, 9

Therefore, print the t value followed by a comma and the corresponding y value on a line for each calculation to a your csv file. It should look something like the following.

0,1

0.01,0.993306

0.02,0.986558

0.03,0.979758

0.04,0.972907

f)

Finish the rest of the steps for your file IO.

g)

Find the file, and open it with excel. Good news, excel 2010 an up inherently knows how to

parse the file. Otherwise, you may have to select comma delimited.

h)

Take your two columns of data and plot them using a scatter plot

i)

Convert the file from a csv file to an excel workbook file, xlsx, through the save as dialog box.

j)

Submit your program and corresponding excel workbook.

Homework Answers

Answer #1
#include<bits/stdc++.h>

using namespace std;

// b, function

double calculate(double t){

double val= exp(-t/1.5) * cos(t);

return val;

}

int main()

{

ofstream outFile;

//a. Creating File With Open

outFile.open("equation.csv");

double t;

//c. Loop For Incrementation from 0 to 9

for(t=0;t<=9;t=t+0.01){

// d. calculating from within the loop by the function call each time

double val= calculate(t);

// e. Writing the data to csv file

outFile<<t<<","<<val<<"\n";

}

outFile.close();

return 0;

}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Problem #1 Confidence Interval for Means using the t and z Distribution.    Psychologists studied the percent...
Problem #1 Confidence Interval for Means using the t and z Distribution.    Psychologists studied the percent tip at a restaurant when a message indicating that the next day’s weather would be nice was written on the bill. Here are tips from a random sample of patrons who received such a bill, measured in percent of the total bill: 20.8     18.7     19.9     20.6     21.9     23.4     22.8     24.9     22.2     20.3   24.9     22.3     27.0     20.4     22.2     24.0     21.1     22.1     22.0     22.7 Open an...
Given the data set with t values in the first column and y values in the...
Given the data set with t values in the first column and y values in the second column, write a script file that: -Curve fits the given data set with an appropriate polynomial function -Outputs the R2 value of the appropriate fit along with the values of the polynomial order higher and lower (ex. If you choose a 2nd order fit, display the R2 value for first, second, and third order fits.) - Estimate the value of the data at...
For the next part of the lab, open the Week 3 Excel worksheet. This will be...
For the next part of the lab, open the Week 3 Excel worksheet. This will be used for the next few questions, rather than the data file used for the first question. Click on the “binomial tables” workbook Type in n=10 and p=0.5; this simulates ten flips of a coin where x is counting the number of heads that occur throughout the ten flips Create a scatter plot, either directly in this spreadsheet (if you are comfortable with those steps),...
Data For Tasks 1-8, consider the following data: 7.2, 1.2, 1.8, 2.8, 18, -1.9, -0.1, -1.5,...
Data For Tasks 1-8, consider the following data: 7.2, 1.2, 1.8, 2.8, 18, -1.9, -0.1, -1.5, 13.0, 3.2, -1.1, 7.0, 0.5, 3.9, 2.1, 4.1, 6.5 In Tasks 1-8 you are asked to conduct some computations regarding this data. The computation should be carried out manually. All the steps that go into the computation should be presented and explained. (You may use R in order to verify your computation, but not as a substitute for conducting the manual computations.) A Random...
The cost of a daily newspaper varies from city to city. However, the variation among prices...
The cost of a daily newspaper varies from city to city. However, the variation among prices remains steady with a population standard deviation of $0.20. A study was done to test the claim that the mean cost of a daily newspaper is $1.00. Thirteen costs yield a mean cost of $0.95 with a standard deviation of $0.18. Do the data support the claim at the 1% level? Note: If you are using a Student's t-distribution for the problem, you may...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...