Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ code help, I need the results to go into an output file to tell the iterarions, integral value, and percent error. n is the

C++ code help, I need the results to go into an output file to tell the iterarions, integral value, and percent error.

n is the number of sub-intervals.

I have attached a link to what the rules are: http://www.ece.mcmaster.ca/~xwu/part6.pdf

I have attached what I have so far... I NEED OF HELP This is due in 24 hours

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

//Trapezoidal Rule

#include #include #include

using namespace std;

double function(double x) { double fun; fun=(1.0 / (1 + exp(x))); return fun; } /* double pe(double num_ans) { double error, per_error,ana_ans; ana_ans = 0.145413; error = ((num_ans - ana_ans) / ana_ans); //% Error per_error = error * 100; return per_error;

} */

int main() { FILE* solution; solution = fopen("Results_trapezoidal.txt", "w");

fprintf(solution, "NAME "); fprintf(solution, " Homework 3 "); fprintf(solution, " "); fprintf(solution, "Integral: (1 / (1 + exp(x))); "); fprintf(solution, " ");

//int n; double a, b, h, integral, sum = 0, analytical, error, percent_e; double x[512]; analytical =0.14541;

printf("Trapezoidal Rule "); printf("Enter the inital limit of integration, a = "); scanf("%lf", &a); printf("Enter the final limit of integration, b = "); scanf("%lf", &b);

string iteration("i"); string answer("x_i"); string p_error = ("Percent Error");

fprintf(solution, "Trapezoidal Rule "); fprintf(solution, "------------------------------------------------------------------------------------- "); fprintf(solution, "%2s%16s%26s ", iteration.c_str(), answer.c_str(), p_error.c_str()); fprintf(solution, "------------------------------------------------------------------------------------- ");

for (int n = 1; n

for (int i = 1; i

integral = 0.5*h*function(a); integral += 0.5*h*function(b);

for (int j = 1; j

fprintf(solution, "%2i\t", n); fprintf(solution, "%11.3lf\t", integral);

error = (integral - analytical) / analytical; percent_e = error * 100; fprintf(solution, "%11.3lf ", percent_e);

}

fclose(solution); return 0; }

2. There are many applications where numerical integration is required in aerospace engineering. Examples include integrating a pressure distribution about an airfoil to find lift and drag, integrating a time-dependent drag profile on a rocket to determine time of flight and burnout altitude, and integrating a probability distribution function to find the average fuel drop diameter in an aircraft engine. In many instances, the function to be integrated may be a set of discrete data points rather than being analytical, but the technique is similar Integrate the following function both analytically (you may want to look this up in a table ofintegrals and numerically: Use both the trapezoidal and Simpson's 1/3 rules to numerically integrate the function out to exactly seven decimal segments. Compute the percent relative errors, out to exactly four decimal points, for the numerical results (as compared to the analytic answer. Numerical Answer Analytic Answer Error Analytic Answer Again, each code should be its own file. Do not combine methods into a single code. Be sure to identify which result file goes with which method. Remember to put the proper language extension at the end of your filename

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions