Using C++ Enter x: 0.5 B. (20 points) Approximating the Value of the Fresnel Int
ID: 3587574 • Letter: U
Question
Using C++
Enter x: 0.5 B. (20 points) Approximating the Value of the Fresnel Integral, Cf) Enter of Estimates (trapezoids): 5 C (x) 0.48096988 0.4B928112 0.49096596 0.49156568 0.49184499 The Fresnel integrals 2 appear in a number of areas of science and engineering Continue? (y/n) n Additional Constraints. Write a C+ program that has theuser input a positive value x (of type double) and a positive value MaxTrapezoids (of type int), and then approximates C(r) using the Trapezium integration method. In addition to the coustraints implicitly specified in the problem specification above, your program should adhere to the following constraints. i. 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 i is. This assignment does not ask you to write or modify this function, only to use it. 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 trapczoids. For cach approximation, the program should print out the number of trapezoids used in that estimate and the result of the estimate i. Make sure your input and output follows the fomat shown in the example above. iii. Your program should declare, define, and use a function with eference parameters to obtain This process should be in a user-controlled continuation loop, as shown in the following example (user input is in Bold font) 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 fimction 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 Ent r x: 3.14159265 Enter # of Estimates (trapezoids): 5 Estimates C(x) 0.03283499 Your program should declare and define the function: f)-cos ( * f/2). This function will be called by the trapezium function to approximate theintegral of C(a). iv. 1.14969834 0.71268699 Print out the approximation of C(x) with 8 digits to the right of the decimal point. v. 0.72872487 0.05055231 vi. Your solution should include a continuation loop that asks the user if they would like to continue afier a value for C(x) is successfilly computed and printed out Continue? (y/n): y vii. Note that although there are two Fresnel functions, this program only asks you to compute the values of one of them, namely: Cr) According to Wikipedia en wikipedisorewiki Freselesal accessed Sept. 28, 2017, "The Fresnel integrals were vii Define a global constant named PI in your program and sct it to the valuc: 3.14159265 originally used in the caleslation of the field intensity in an enviroament related to the bending of light arcund opaque objects. More recenly they have been used in the design of highways and railways, specitically their curvature transition zones and roller coasters. Another application is for caleulsting the tasitices on a velodrome tock to allow Espid catry to the bends and grdaal exit ix. You shbould test your program on a variety of inputs in addition to the ones inclided above, such as all of the boundary conditions arond tle 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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.