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

i cant seem to find out how to correct my error messages. An explanation on what

ID: 3639616 • Letter: I

Question

i cant seem to find out how to correct my error messages. An explanation on what i was doing wrong would be appreciated. Here is the question.

Write a modular C program to perform numeric integration, using the trapezoidal rule
with Richardson's extrapolation. Use m = 2, and for each integration use values of k
from 10 to 1250 in multiples of 5 (i.e., 10, 50, 250, 1250 implemented with a loop). Use
a C macro to define the function to be integrated, and read the values of a and b, the
limits of the integration, from standard input as real values. Your output should be
clearly labeled, with the numeric values for k and the corresponding calculated integral in
columnar form. Real values should be represented to 6 places of decimals.

#include <stdio.h>
#include <math.h>


#define PI 3.14159

#define Z(X) (1/(1+(X)*(X)))
#define G(X) (sqrt(2*(X)*(X) + 1)*(X))
#define H(X) (sqrt(cos(X))*sin(X))
#define I(X) ((pow(1+(1/(X)),3) * 1/ ((X)*(X)))
#define J(X) (1/(X))

int
main()
{
int wait;
double u1, u2, m = 2, k,k1, k2,h,hi, h2, a, b,sigma1=0, sigma2,y1,y2,y3,y4,y5 = 0;
/* assign our variables, they're all doubles and they can be letters because we are using known formulas*/
double fa,fb,ga,gb,ha,hb,ia,ib,ja,jb;
int all=1;
char select;
FILE *result;
result = fopen("result.dat", "w");



printf ("please select the integral you would like to solve: "); ;

prinff ("a) 1/(1+x*x) from 0 to 1 ");
printf ("b) sqrt(2*x*x + 1)*x from 0 to 2 ");
printf ("c) sqrt(cos(x))*sin(x) from 0 to pi/2 ");
printf ("d) (1+(1/x))^3 * 1/ (x*x) from 0.5 to 1 ");
printf ("e) 1/x from 1 to 2 ");
printf ("f) all, and write to file");
scanf ("%c", &select);

if (select = 'f' || 'F')
all = 1;
else
all = 7;

/*based on what the user selects, the program will do the appropriate calculations, if the user wants to do all calculations and write them to a file, it will initiate a loop that will do all calculations*/

while (all<6)
{
if (all == 1)
select = 'a';
else
if (all == 2)
select = 'b';
else
if (all == 3)
select = 'c';
else
if (all == 4)
select = 'd';
else
if (all ==5)
select = 'e';
else
if (all ==6)
select = 'f';
else
all = 7;

switch (select)
{
case 'a':
case 'A':
all = all+1;
a = 0; /*sets the approptiate limits of integration for the function*/
b = 1;
fa = Z(a);
fb = Z(b);
k = 10;
k2 = m*10;
while (k<1250) /*this loop calculates the sigma components for both trapezoid rule calculations side by side*/
{
h = (b-a)/k;
h2 = (b-a)/k2;
sigma1 = sigma1 + Z(a + (j*h);
sigma2 = sigma2 + Z(a + (j*h2);
j=J+1;
k=k*5;
}
u1 = 0.5 * hi * (fa + 2*sigma + fb); /*caluculate u1, and u2 for Richardson's extrapolation calculations*/
u2 = 0.5 * hi * (fa + 2*sigma2 + fb);
y1 = (((m*m)*u2)/(m*m-1)) - (u1/(m*m-1)); /*does Richardson's extrapolation to approximate the integral*/

break;

case 'b':
case 'B':
all = all+1;
a = 0; /*sets the approptiate limits of integration for the function*/
b = 2;

ga = G(a); /* calculate F(a) and F(b), based on the limits*/
gb = G(b);
k = 10;
k2 = m*10;
while (k<1250) /*this loop calculates the sigma components for both trapezoid rule calculations side by side*/
{
h = (b-a)/k;
h2 = (b-a)/k2;
sigma1 = sigma1 + G(a + (j*h);
sigma2 = sigma2 + G(a + (j*h2);
j=J+1;
k=k*5;
}
u1 = 0.5 * hi * (fa + 2*sigma + fb); /*caluculate u1, and u2 for Richardson's extrapolation calculations*/
u2 = 0.5 * hi * (fa + 2*sigma2 + fb);
y2 = (((m*m)*u2)/(m*m-1)) - (u1/(m*m-1)); /*does Richardson's extrapolation to approximate the integral*/
break;

case 'c':
case 'C':
all = all+1;
a = 0; /*sets the approptiate limits of integration for the function*/
b = (PI/2);

ha = H(a);
hb = H(b);
k = 10;
k2 = m*10;
while (k<1250) /*this loop calculates the sigma components for both trapezoid rule calculations side by side*/
{
h = (b-a)/k;
h2 = (b-a)/k2;
sigma1 = sigma1 + H(a + (j*h);
sigma2 = sigma2 + H(a + (j*h2);
j=J+1;
k=k*5;
}
u1 = 0.5 * hi * (fa + 2*sigma + fb); /*caluculate u1, and u2 for Richardson's extrapolation calculations*/
u2 = 0.5 * hi * (fa + 2*sigma2 + fb);
y3 = (((m*m)*u2)/(m*m-1)) - (u1/(m*m-1)); /*does Richardson's extrapolation to approximate the integral*/
break;
case 'D':
case'd':
all = all+1;
a = 0.5; /*sets the approptiate limits of integration for the function*/
b = 1;

ha = H(a);
hb = H(b);
k = 10;
k2 = m*10;
while (k<1250) /*this loop calculates the sigma components for both trapezoid rule calculations side by side*/
{
h = (b-a)/k;
h2 = (b-a)/k2;
sigma1 = sigma1 + H(a + (j*h);
sigma2 = sigma2 + H(a + (j*h2);
j=J+1;
k=k*5;
}
u1 = 0.5 * hi * (fa + 2*sigma + fb); /*caluculate u1, and u2 for Richardson's extrapolation calculations*/
u2 = 0.5 * hi * (fa + 2*sigma2 + fb);
y4 = (((m*m)*u2)/(m*m-1)) - (u1/(m*m-1)); /*does Richardson's extrapolation to approximate the integral*/
break;

case 'e':
case 'E':
all = all+1;
a = 1; /*sets the approptiate limits of integration for the function*/
b = 2;

ia = I(a);
ib = I(b);
k = 10;
k2 = m*10;
while (k<1250) /*this loop calculates the sigma components for both trapezoid rule calculations side by side*/
{
h = (b-a)/k;
h2 = (b-a)/k2;
sigma1 = sigma1 + I(a + (j*h);
sigma2 = sigma2 + I(a + (j*h2);
j=J+1;
k=k*5;
}
u1 = 0.5 * hi * (fa + 2*sigma + fb); /*caluculate u1, and u2 for Richardson's extrapolation calculations*/
u2 = 0.5 * hi * (fa + 2*sigma2 + fb);
y5 = (((m*m)*u2)/(m*m-1)) - (u1/(m*m-1)); /*does Richardson's extrapolation to approximate the integral*/
break;
case 'f':
case 'F':
fprintf (result,"%5.6lf ",y1);
fprintf (result,"%5.6lf ",y2);
fprintf (result,"%5.6lf ",y3);
fprintf (result,"%5.6lf ",y4);
fprintf (result,"%5.6lf ",y5);

}
}
switch(select)
{
case 'A':
case 'a':
printf ("the integral you selected was: 1/(1+x*x) from 0 to 1 and the extimated value is: %5.6lf",y1);
break;

case 'B':
case 'b':
printf ("the integral you selected was: sqrt(2*x*x + 1)*x from 0 to 2 and the extimated value is: %5.6lf",y2);
break;

case 'C':
case 'c':
printf ("the integral you selected was: sqrt(cos(x))*sin(x) from 0 to pi/2 and the extimated value is: %5.6lf",y3);
break;

case 'D':
case 'd':
printf ("the integral you selected was: (1+(1/x))^3 * 1/ (x*x) from 0.5 to 1 and the extimated value is: %5.6lf",y4);
break;

case 'E':
case 'e':
printf ("the integral you selected was: 1/x from 1 to 2 and the extimated value is: %5.6lf",y5);
break;

case 'F':
case 'f':
printf ("you chose to calculate all integrals the results can be found in the accompanying text file (results.dat) ");
break;
}
fclose (results);
}
}

Explanation / Answer

can you post what error are you getting?? It will be of great help in finding the error!!