Question

Given class Function {     public:     virtual double compute(double value) = 0;     virtual double differentiate(double value) =...

Given

class Function

{

    public:

    virtual double compute(double value) = 0;

    virtual double differentiate(double value) = 0;

    virtual double integrate(double value) = 0;

};

class Sine : public Function

{

    public:

    double compute(double value); // compute sin(x) for a given x

    double differentiate(double value); // compute derivative sin'(x) for a given x

    double integrate(double value); // integrate sin(x) for a given x

};

class Tangent : public Function

{

    public:

    double compute(double value); // compute tan(x) for a given x

    double differentiate(double value); // compute derivative tan'(x) for a given x

    double integrate(double value); // integrate tan(x) for a given x

};

The classes represent mathematical functions, where each function f(x) (e.g. sine, tangent) can be computed, differentiated and integrated for a given x.

Writea method named quotientRule to compute the derivative of a quotient of any two functions. Using the notation f'(x) to indicate the derivative of function f(x), the derivative ofthe quotient f(x)/g(x) is defined as [f'(x)*g(x) + f(x) * g'(x)]/[g(x)*g(x)], where f(x) and g(x) are any two given functions, and f'(x) and g'(x) are function derivatives, respectiveley. Your method should be applicable to any two functions derived from the the Function interface. An example of the method call is given below:

Sine sin;  // the sine function

Tangent tan;   // the tangent function

double answer = sin.quotientRule(tan, 5.3);    // compute the derivative of sin(5.3)/tan(5.3)

Homework Answers

Answer #1

I've written a method quotientRule within the program for better understanding, please find explanation at the bottom.

#include<iostream>
#include<cmath>
using namespace std;

class Function

{

    public:

    virtual double compute(double value) = 0;

    virtual double differentiate(double value) = 0;

    virtual double integrate(double value) = 0;
    
    /* Here's the method which takes two parameter, a Function object reference and value */ 

        double quotientRule(Function &t,double value)
        {
                return (differentiate(value)*t.compute(value)+compute(value)*t.differentiate(value))/(t.compute(value)*t.compute(value));
        }

};

class Sine : public Function

{

    public:

    double compute(double value)// compute sin(x) for a given x
        { return sin(value);
        } 

    double differentiate(double value)// compute derivative sin'(x) for a given x
    {
        return cos(value);
        }
    double integrate(double value) // integrate sin(x) for a given x
        {
                return -cos(value);
        }

};

class Tangent : public Function

{

    public:

    double compute(double value)
    {
        return sin(value)/cos(value);
        }

    double differentiate(double value)
    {
        return (1/pow(cos(value),2));
        }

    double integrate(double value)// integrate tan(x) for a given x
        { return -log(abs(cos(value)));
        }


};
int main()
{
        Tangent tan;
        Sine sin;
        double answer=sin.quotientRule(tan,5.3);
        cout<<answer;
}

Output:

Explanantion:

In the above program we implement quotientRule method inside definition of Functionclass which uses quotient rule for finding differentiation of the two functions by the formula : [f'(x)*g(x) + f(x) * g'(x)]/[g(x)*g(x)]

In abstract class one can not create object of the abstract class hence we use reference to the class Function.

When we assign a child class object to the parent class reference it calls the function with that particular child class,

This is the reason why when we use sin.quotientRule(tan,5.3) it calls the method using Sine object and uses refrence to Tangent class as parameter.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1a. Find the domain and range of the function. (Enter your answer using interval notation.) f(x)...
1a. Find the domain and range of the function. (Enter your answer using interval notation.) f(x) = −|x + 8|   domain= range= 1b.   Consider the following function. Find the composite functions f ∘ g and g ∘ f. Find the domain of each composite function. (Enter your domains using interval notation.) f(x) = x − 3 g(x) = x2 (f ∘ g)(x)= domain = (g ∘ f)(x) = domain are the two functions equal? y n 1c. Convert the radian...
1a.) Find the linearization of the function f(x) = (sin x+1)^2 at a = 0. 1b.)...
1a.) Find the linearization of the function f(x) = (sin x+1)^2 at a = 0. 1b.) Differentiate the two functions below. f(x) = ln(e^x - sin x) ; g(x) = e^-x^2
Answer each of the questions below. (a) Find an equation for the tangent line to the...
Answer each of the questions below. (a) Find an equation for the tangent line to the graph of y = (2x + 1)(2x 2 − x − 1) at the point where x = 1. (b) Suppose that f(x) is a function with f(130) = 46 and f 0 (130) = 1. Estimate f(125.5). (c) Use linear approximation to approximate √3 8.1 as follows. Let f(x) = √3 x. The equation of the tangent line to f(x) at x =...
13. Consider f(x)=sqrt x-2 a) Using any of the three limit formulas to find f ′...
13. Consider f(x)=sqrt x-2 a) Using any of the three limit formulas to find f ′ ( a ), what is the slope of the tangent line to f ( x )at x = 18? (6 points execution, 2 points notation) b) Find the equation of the tangent line at x = 18 14. State the derivative. a) d/ d x [ x ^n ] b) d /d x [ cos ⁡ x ] c) d /d x [ csc...
Use the shortcut rules to mentally calculate the derivative of the given function. HINT [See Examples...
Use the shortcut rules to mentally calculate the derivative of the given function. HINT [See Examples 1 and 2.] f(x) = 4x4 + 7x3 − 3 f '(x) = Use the shortcut rules to mentally calculate the derivative of the given function. HINT [See Examples 1 and 2.] f(x) = −x + (8/x) +1 f '(x) = Find the derivative of the function. HINT [See Examples 1 and 2.] f(x) = 8x3 − 4x2 + x f '(x) = Find...
1. (5pts.) Compute the derivative dy/dx for y = 7√ 9π + x ^5 /6 +...
1. (5pts.) Compute the derivative dy/dx for y = 7√ 9π + x ^5 /6 + 27e^x . 3. (5pts.) Write the equation of the tangent line to the graph of y = 3 + 8 ln x at the point where x = 1. 4. (5pts.) Determine the slope of the tangent line to the curve 2x^3 + y^3 + 2xy = 14 at the point (1, 2). 5. (5pts.) Compute the derivative dw/dz of the function w =...
Find the directional derivative of the function at the given point, in the vector direction v...
Find the directional derivative of the function at the given point, in the vector direction v 1- f(x, y) = ln(x^2 + y^2 ), (2, I), v = ( - 1, 2) 2- g(r, 0) = e^-r sin ø, (0, ∏/ 3), v = 3 i - 2 j
B.) Let R be the region between the curves y = x^3 , y = 0,...
B.) Let R be the region between the curves y = x^3 , y = 0, x = 1, x = 2. Use the method of cylindrical shells to compute the volume of the solid obtained by rotating R about the y-axis. C.) The curve x(t) = sin (π t) y(t) = t^2 − t has two tangent lines at the point (0, 0). List both of them. Give your answer in the form y = mx + b ?...
Calculus, Taylor series Consider the function f(x) = sin(x) x . 1. Compute limx→0 f(x) using...
Calculus, Taylor series Consider the function f(x) = sin(x) x . 1. Compute limx→0 f(x) using l’Hˆopital’s rule. 2. Use Taylor’s remainder theorem to get the same result: (a) Write down P1(x), the first-order Taylor polynomial for sin(x) centered at a = 0. (b) Write down an upper bound on the absolute value of the remainder R1(x) = sin(x) − P1(x), using your knowledge about the derivatives of sin(x). (c) Express f(x) as f(x) = P1(x) x + R1(x) x...
Given: The following boundary value problem:    y"+ lamda*y = 0;                0 < x...
Given: The following boundary value problem:    y"+ lamda*y = 0;                0 < x < 2;         y(0) = 0;          y’(2) = 0 Find corresponding eigenvalues, (lamda)n and normalized eigenfunctions yn Expand the function f(x) = x, in terms of the eigen functions obtained in (i)
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT