Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

If possible, please follow the constraints as closely as possible. B. (20 points

ID: 3587488 • Letter: I

Question

If possible, please follow the constraints as closely as possible.

B. (20 points) Approximating the Value of the Fresnel Integral, C(x) The Fresnel integrals C(x) = | cos dt and S(z) = sin appear in a number of areas of science and engineering Write a C+program that has the user input a positive value x (of type double) and a positive value MaxTrapezoids (of type int), and then approximates C(x) using the Trapezium integration method. First approximate C(x) using the Trapezium method with 1 trapezoid, then with 2 trapezoids, and so on, each time increasing the number of trapezoids by one until the last estimate uses MaxTrapeziods trapezoids. For each approximation, the program should print out the number of trapezoids used in that estimate and the result of the estimate This process should be in a user-controlled continuation loop, as shown in the following example (user input is in Bold font) Enter x: 3.14159265 Enter # of Estimates (trapezoids): 5 Estimates C (x) 0.03283499 -1.14969834 0.71268699 2 0.72872487 0.05055231 Continue? (y/n): y According to Wikipedia httllen wikinedia org/wikiFresnel integral accessed Sept. 28, 2017, "The Fresnel integrals were originally used in the calculation of the field intensity in an environment related to the bending of light around opaque objects. More recently they have been used in the design of highways and railways, specifically their curvature transition zones and roller coasters. Another application is for calculating the transitions on a velodrome track to allow rapid entry to the bends and gradual exit." Enterx: 0.5 Enter # of Estimates (trapezoids): 5 Estimates 0.48096988 0.48928112 0.49096596 0.49156568 0.49184499 2 Continue? (y/n): n Additional Constraints. In addition to the constraints implicitly specified in the problem specification above, your program should adhere to the following constraints Use the trapezium numerical integration function in your solution. You should copy the trapezium function from the class Moodle site, and use it exactly as it is. This assignment does not ask you to write or modify this function, only to use it i. ii. Make sure your input and output follows the format shown in the example above iii. Your program should declare, define, and use a function with reference parameters to obtain the values for x and MaxTrapezoids from the user. The values should be a positive real value for x and a positive integer value for MaxTrapezoids. The function should check to ensure each value entered is positive immediately after it is entered, and if it isn't the function should print an error message and re-prompt the user for a correct value. The function should continue in this manner until a correct value is entered. cos ( * t2/2). This function Your program should declare and define the function: f) will be called by the trapezium function to approximate the integral of C(x) iv. v. Print out the approximation of C(x) with 8 digits to the right of the decimal point. Your solution should include a continuation loop that asks the user if they would like to continue after a value for C(r) vi. uccessfully computed and printed out vii. Note that although there are two Fresnel functions, this program only asks you to compute the values of one of them, namely: C(r) onstant named PI in your program and o the value: 3.14159265 X. Yo ould test your program on a variety of inputs in addition to the ones included above, such a the boundary conditions around the legal input values, and so forth. We will be doing so when we grade your progran

Explanation / Answer

//Trapezoidal Method for the evaluation of Fresnel Integral

#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265

double f(double x) // the Fresnel function whose definite integral is to be calculated
{
double a=cos((pi*x*x)/2);
return a;
}

int main()
{
int n,i,j; //n is for no of subintervals and i is for loop
char c='y';
double x,h,sum=0,integral;
while(c=='y'){
cout<<"Enter x : ";
cin>>x;
cout<<"Enter # of Estimates (trapezoids) : ";
cin>>n;
if(n<=0)
{
while(n<=0)
{
cout<<"ERROR! PLEASE ENTER POSITIVE VALUE ";
cin>>n;
}
}
cout<<"Estimates C(x) "<<endl;
for(j=1;j<=n;j++)
{
double xy[j+1],y[j+1];
h=x/j; //get the width of the subintervals
for(i=0;i<=j;i++)
{ //loop to evaluate x0,...xn and y0,...yn
xy[i]=i*h; //and store them in arrays
y[i]=f(xy[i]);
}
for (i=1;i<j;i++) //loop to evaluate h*(y1+...+yn-1)
{
sum=sum+h*y[i];
}
integral=h/2.0*(y[0]+y[j])+sum; //h/2*[y0+yn+2(y1+y2+y3+...yn-1)]
cout<<j<<" "<<integral<<endl;
sum=0;
}
cout<<"Continue? (y/n) : ";
cin>>c;
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote