Solutions to the following problems should consist of program codes, computed re
ID: 3688388 • Letter: S
Question
Solutions to the following problems should consist of program codes, computed results, and short write-ups. In the write-up, discuss the results you have obtained and explain them from the numerical point of view. Use SINGLE PRECISION ONLY. Insert COMMENTS in your programs. Find the exact value of the following integral I = integral^2_0 x^1/3 dx. Apply the Trapezoidal quadrature at equally spaced points f(x) = x^1/3. Note that/has singularity at x = 0. Use n = 10,100.1000 and print the corresponding errors. Using a change of variables x = t^3, modify the problem to avoid singularity at x = 0, and next use Trapezoidal quadrature with n = 10,100.1000 and print the corresponding errors. Which errors are smaller: for the original function a:'/3 or for the modified one?Explanation / Answer
#include<iostream> //Header file for cin & cout
#include<cmath> //Header file for mathematical operartions
using namespace std; //calling the standard directory
int x;
//Taking a function f(x)
long f(float(x)) {
return (powf(x,1/3));
}
//Taking diffrentiation of f(x) i.e. g(x)
long g(float(x))
{
return (1/3*powf(x,-2/3));
}
//Taking double diffrentiation of f(x) i.e. h(x)
long h(float(x))
{
return (-2/9*powf(x,-5/3));
}
int main() //Main Program
{
long double a,b,d,i,n,I=0,J=0,A,K=0,E=0;
cout<<"Given f(x)=x^1/3 "<<endl;
cout<<"Enter lower limit "<<endl;
cin>>a;
cout<<"Enter Upper Limit "<<endl;
cin>>b;
cout<<"Enter the number of intervals : "<<endl;
cin>>n;
d=(b-a)/n;
//Steps of solving by Trapezoidal Rule
for(i=0;i<=n;i++)
{
I=I+f(a+(i*d));
}
for(i=1;i<n;i++)
{
J=J+f(a+(i*d));
}
A=(d/2)*(I+J);
//Printing the value of Integral
cout<<"The Value of integral under the enterd limits is : "<<endl;
cout<<A<<endl;
//Finding the mean of intervals
for(i=0;i<=n;i++)
{
K=K+a+(i*d);
}
//Calculating the Total Error
E=-((b-a)*d*d*(h(K/n)/12));
//Printing the Totoal Error
cout<<"The Total Error is : "<<endl;
cout<<E<<endl;
return 0;
}
when x=t^3 value is 0.793700
error =2-793700=1.20629
when we take x^1/3 as it is value is 1.88988
error is 2-1.88988=0.11018
check program for output for n values
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.