Question: The code I was provided seems to have a problem. The percentage relative error cannot be negative. The picture below is the result of me
The code I was provided seems to have a problem. The percentage relative error cannot be negative. The picture below is the result of me running the c code
I want to be provided with the correct code.
The c code I received:
#include
#include
#include
using namespace std;
Function to be integrated
double fdouble x
return x x expx;
Simpson's rule
double simpsonsRuledouble a double b int n
double h b a n;
double sum fa fb;
for int i ; i n; i
sum fa i h;
for int i ; i n ; i
sum fa i h;
return h sum;
int main
double trueValue exp;
vector hvalues ;
vector nvalues;
vector errors;
vector relativeerrors;
Calculating n values
for double h : hvalues
nvalues.pushbackstaticcast h;
Calculating integrals and errors
cout htIntegraltRelative Error
;
for int n : nvalues
double integral simpsonsRule n;
double error fabsintegral trueValue;
double relativeerror error fabstrueValue;
errors.pushbackerror;
relativeerrors.pushbackrelativeerror;
cout nt integral t relativeerror
;
Calculating rate of change of percentage relative error
cout
Rate of Change of Percentage Relative Error:
;
for sizet i ; i relativeerrors.size; i
double rate relativeerrorsi relativeerrorsi hvaluesi hvaluesi ;
cout "From h hvaluesi to h hvaluesi: rate
;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
