C programming Using the definition of a limit the program to

C++ programming

Using the definition of a limit, the program to be written will determine the derivative of a quadratic function (form shown below) at any given value of x with an accuracy of 3 decimal places using an iterative process for increasingly smaller values of delta x until the value determined for the derivative does not vary in the first 3 decimal places. The program will output to the user the equation describing the function, the value of x at which the derivative is found, the numerical value of the derivative, and the number of iterations that were required to get the necessary accuracy in decimal places.

The quadratic function the program is to deal with is: f(x) = c1x2 + c2x + c3 The user must be able to enter whatever values desired for the coefficients {c1, c2, c3} and the value for x at which the derivative is to be determined. The steps to take to find the derivative are: 1) Store values from user for c1, c2, c3, and x. 2) Calculate f(x) using the values from the user and retain that value in a variable (name of your choosing). 3) Start with delta x = 0.1 and a variable called testTolerance = 0.001. 4) Calculate f(x+delta x) using the value of x given by the user and the current value of delta x. 5) Calculate f\'(x) = (f(x+delta x) – f(x))/ delta x using the value calculated in step 2 and step 4 above and the current value of delta x. 6) If (f\'(x) – testTolerance) < 0.001 then the value calculated for f\'(x) is within three decimal places of the correct value for f\'(x) and the work is done. 7) Otherwise, set the new value for delta x to be the old value divided by 2 and set testTolerance equal to the current value of f\'(x) and repeat steps 4 through 6.

Remember this is a C++ program.

Solution

#include #include using namespace std; int main() { float a, b, c, x1, x2, determinant, realPart, imaginaryPart; cout << \"Enter coefficients a, b and c: \"; cin >> a >> b >> c; determinant = b*b - 4*a*c; if (determinant > 0) { x1 = (-b + sqrt(determinant)) / (2*a); x2 = (-b - sqrt(determinant)) / (2*a); cout << \"Roots are real and different.\" << endl; cout << \"x1 = \" << x1 << endl; cout << \"x2 = \" << x2 << endl; } else if (determinant == 0) { cout << \"Roots are real and same.\" << endl; x1 = (-b + sqrt(determinant)) / (2*a); cout << \"x1 = x2 =\" << x1 << endl; } else { realPart = -b/(2*a); imaginaryPart =sqrt(-determinant)/(2*a); cout << \"Roots are complex and different.\" << endl; cout << \"x1 = \" << realPart << \"+\" << imaginaryPart << \"i\" << endl; cout << \"x2 = \" << realPart << \"-\" << imaginaryPart << \"i\" << endl; } return 0; }
C++ programming Using the definition of a limit, the program to be written will determine the derivative of a quadratic function (form shown below) at any given

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site