46 terms.emplace_back(coefficient, exponent);
50 for (
size_t i = 0; i < terms.size(); ++i) {
51 const auto &term = terms[i];
52 if (term.exponent > 1) {
53 std::cout << term.coefficient <<
"*x^" << term.exponent;
54 }
else if (term.exponent == 1) {
55 std::cout << term.coefficient <<
"*x";
57 std::cout << term.coefficient;
60 if (i < terms.size() - 1) {
64 std::cout << std::endl;
69 for (
const auto &term : terms) {
70 if (term.exponent > 0) {
71 double new_coefficient = term.coefficient * term.exponent;
72 int new_exponent = term.exponent - 1;
73 result.
add_term(new_coefficient, new_exponent);
83 for (
const auto &outer_term : terms) {
89 for (
auto &inner_term : inner_derivative.
terms) {
90 inner_term.coefficient *= outer_term.coefficient;
94 for (
const auto &inner_term : inner_derivative.
terms) {
95 double new_coefficient = inner_term.coefficient;
96 int new_exponent = outer_term.exponent + inner_term.exponent;
97 result.
add_term(new_coefficient, new_exponent);
106 for (
int i = 0; i < n; ++i) {
114 for (
const auto &term : terms) {
115 result += term.coefficient * std::pow(x, term.exponent);
123 for (
const auto &term : terms) {
124 result += term.coefficient * std::pow(x, term.exponent);
133 if (!terms.empty()) {
134 const auto &highest_term =
135 *std::max_element(terms.begin(),
137 [](
const auto &a,
const auto &b) {
138 return a.exponent < b.exponent;
141 if (highest_term.exponent > 0) {
144 return (highest_term.coefficient > 0)
145 ? std::numeric_limits<double>::infinity()
146 : -std::numeric_limits<double>::infinity();
150 return highest_term.coefficient;
155 return std::numeric_limits<double>::quiet_NaN();
Calculus Class with methods pertaining to basic operations.
double limit_at_infinity() const
Calculate the limit of the polynomial as x approaches infinity.
Differential power_rule() const
Computes the derivative using the power rule.
double limit_at(double x) const
Calculate the limit of the polynomial at a specific point.
void add_term(double coefficient, int exponent)
Adds a term to the Differential object.
Differential chain_rule(const Differential &inner) const
Computes the derivative using the chain rule.
void display() const
Displays the polynomial in a readable format.
std::vector< Term > terms
Differential nth_derivative(int n) const
Computes the nth derivative of the current Differential object.
double eval(double x) const
Evaluates the polynomial for a given value of x.