please help me about my calculus project. the project is called Derivative of nth power and we will make a code of it. please help me to figure out the codes
Firstly, the purpose of such projects is that you do learn. You do learn by doing. You don't learn if someone else does the work. They don't learn either, because they have already invented bread and sliced wheel.
Second, pretend that we have no clue and explain in detail what this fabulous "Derivative of nth power" is.
Third, show the code that you have written. Then someone could point out whether/how it differs from what you did explain that it should do.
In C++ one can consider a numerical approach to calculate the derivative of a function and, separately, an accurate assessment of it. So, a good approximation gives the formula:
f'(x0) = ( f(x0 + h) - f(x0 - h) ) / (2 * h) here h is an infinitesimal value.
So, for the function f(x) = x ^ n ( nth power of x) here is an attempt to do such a task.
#include <iostream>
usingnamespace std;
double func(double, int);
int main ()
{
int n;
double x0;
cout << "To compute the value of the derivative of f(x) = x ^ n for x = x0, we need " << '\n';
cout << "to enter n: ";
cin >> n;
cout << "and also to enter x0: ";
cin >> x0;
cout << fixed;
cout.precision(6);
double h = .000001; // An infinitesimal change
double x2 = x0 + h; // Pick a point to the right of x0
double x1 = x0 - h; // Pick a point to the left of x0
double f2 = func(x2, n); // Evaluate function for x = x2
double f1 = func(x1, n); // Evaluate function for x = x1
double approxDerivative = (f2 - f1) / (2.0 * h); //Find the slope of the line through those two points.
double exactValue = n * func(x0, n - 1); // Evaluate exact derivative f'(x) = n * x ^ (n - 1) for x = x0
cout << "\nApprox. value = " << approxDerivative << '\n';
cout << "Exact value = " << exactValue << '\n';
cout << " Error = " << approxDerivative - exactValue << "\n\n";
return 0;
}
double func(double x, int n)
{
double f = 1.0;
for(int i = 1; i <= n; ++i)
f *= x; // Evaluate f(x) = x*x*...*x (alias f(x) = x ^ n)
return f;
}
Some outputs:
1 2 3 4 5 6 7
To compute the value of the derivative of f(x) = x ^ n for x = x0, we need
to enter n: 5
and also to enter x0: 1.234
Approx. value = 11.593929
Exact value = 11.593929
Error = -0.000000
1 2 3 4 5 6 7
To compute the value of the derivative of f(x) = x ^ n for x = x0, we need
to enter n: 6
and also to enter x0: -2.3456
Approx. value = -426.011198
Exact value = -426.011198
Error = -0.000000
Well, nth power implies that n is a nonnegative integer <=> n belongs to N = {0, 1, 2, ...}.
In other cases is said in consequence, e.g.: let f(x) = xq where q belongs to Q = { q = m/n | where m, n != 0 are integers}.
@KarlAngelo
Generally speaking the derivative of the function f(x) =1/u(x) is f'(x) =- u'(x)/u2(x) and here everything stops. For the problem to continue in C / C + + you must specify who is u (x), for ex.: u (x) = x or u (x) = x * exp (x) and so on. So be more specific with u(x).