A mathematical relationship between x and y is described by the following expres
ID: 3631650 • Letter: A
Question
A mathematical relationship between x and y is described bythe 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 you 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
*/
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;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.