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

A mathematical relationship between x and y is described by the following expres

ID: 3631606 • Letter: A

Question

A mathematical relationship between x and y is described by
the following expressions:

y=A*exp(x^2)-B*x^3+x-1 if x<=0 (Case 1)

y=A*log10(x)-B*x^4+1.5 if 0<x<=10 (Case 2)

y=A/log(x)-B/x+C if x>10 (Case 3)

where A, B, and C are constants. Write a C program that reads
the double values of the constants A,B,C, and the argument x
(by using scanf), and computes the corresponding value of y.
Print x by using %f format with 4 decimal places,
and print y by using %f format with 5 decimal places.

Use the pow(a,b) function to calculate x^2, x^3 and x^4, and if/else
statements to choose the proper expression for y, corresponding
to selected x.

After reading A,B,C, your program should use a do/while loop to
evaluate y for scanned x in each of the above three cases. If you
scan x from the same interval again, your program should ask you
to scan x from another interval, until you scan x once from each
interval.

When you enter the case 2, evaluate the integral of y=y(x)
numerically from x=1 to x=5. Use the program based on the trapezoidal rule
(Problem w4-10.c in the lecture notes week4.txt), appropriately modifed.
Use the do/while statement to continue calculations for different n_trap until y
ou are
satisfied with the accuaracy in evaluating the integral. Print the value of the
integral with the %.3f format.

*****************************************************

Your output should look like:

Enter (double) A, B, C:
-1.5 2.5 0.125

Enter (double) x:
-3.5
Case 1
x value is = -3.5000 and y value is = 84.31250

Enter (double) x:
-5
Enter x from another interval!

Enter (double) x:
1.85
Case 2
x value is = 1.8500 and y value is = -28.18452

Enter the number of trapezoids:
1000
n_trap =1000 del_x =0.004
Integral = -1579.502

Do you want new n_trap: y=1/n=0
1

Enter the number of trapezoids:
10000
n_trap =10000 del_x =0.0004
Integral = -1579.500

Do you want new n_trap: y=1/n=0
0

Enter (double) x:
12
Case 3
x value is = 12.0000 and y value is = -0.68698

THIS IS WHAT I HAVE NOW:

#include <stdio.h>
#include <math.h>
int main()
{
double A, B, C, x, y, del_x, sum;
int k, n_trap, flag, smaller0=0, smaller1=0, greater1=0;
printf("Enter (double) A, B, C: ");
scanf("%lf %lf %lf ", &A, &B, &C);
do{

printf("Enter (double) x: ");
scanf("%lf",&x);
if(x<=0)
{
y=(A*pow(x,2.))-(B*pow(x,3.)+x-1);
printf("Case 1 ");
printf("x value is = %.4f and y value is = %.5f");
smaller0 = 1;
}
else{
if(0<x&& x<=10)
{
y=(A*log10(x))-(B*pow(x,4.)+1.5);
printf("Case 2 ");
do{
printf("Enter the number of trapezoids ");
scanf("%d", &n_trap);
del_x=4.0/(double)n_trap;
printf("n_trap = %d     del_x = %g ", n_trap, del_x);
x = 1.0;
y=(A*log10(x))-(B*pow(x,4.)+1.5);
sum = -0.5 *y;
        for(k=0;k<=n_trap; k++)
        {
        x = 1+k*del_x;
        y=(A*log10(x))-(B*pow(x,4.)+1.5);
        sum += y;
        ;}
sum -= 0.5 *y;
sum *= del_x;
printf("Integral = %.3f ", sum);
printf("Would you like to continue with another n_trap? y=1/n=0 ");
scanf("%d", &flag);
}
while (flag != 0);
smaller1 = 1;
}
else{
if(x>10)
{y=(A/log(x))-B/(x+C);
printf("Case 3 ");
printf("x value is = %.4f and y value is = %.5f", x, y);
greater1= 1;
;}
}
}
while(smaller0 == 0 || smaller1 == 0 || greater1 == 0);
}}}

It says there should be a while statement before the last line but there is one, can anybody help me with the error and check over my work. URGENT

Explanation / Answer

Dear.. #include "stdafx.h" #include <stdio.h> #include <math.h> #include <math.h> main()
{ double A, B, C, x, y,n,a,b,del_x;
printf(" Enter (double) A, B, C: ");
scanf("%lf %lf %lf", &A, &B, &C); do {
printf(" Enter (double) x: ");
scanf("%lf", &x); if(x<=0)
{
y =(A * pow(x,2.)) - (B *pow(x,3.)) + x-1;
printf("Case 1 ");
} else { if(0<x, x<=10)
{
y =(A*log(x))-(B* pow(x,4.))+ 1.5;
printf("Case 2 ");
} else { if(x>10)
{
y = (A/log10(x))-(B / x)+C;
printf("Case 3 ");
}
}
}
printf("x value is = %.3f and y value is = %.5f ", x, y);
}
while(x!=x); 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