Core 1.0
Linear Class Reference

Linear polynomials. More...

#include <linear.h>

Public Member Functions

 Linear ()
 Empty.
 
 Linear (const double &, const double &)
 Creates a linear function.
 
 Linear (const double &)
 Creates a constant function.
 
 ~Linear ()
 Empty.
 
constexpr double & operator[] (int)
 Access class components.
 
constexpr double operator[] (int) const
 Overloaded.
 
Linear operator- () const
 Unary.
 
Linearoperator+= (const Linear &)
 Destructive sum of two linear polynomials.
 
Linearoperator-= (const Linear &)
 Destructive difference of two linear polynomials.
 
Linearoperator*= (const double &)
 Scale a linear polynomial by a double value.
 
Linearoperator/= (const double &)
 Scales a linear polynomial by a double value.
 
constexpr double operator() (const double &) const
 Evaluates the linear function.
 
int Solve (double &) const
 Solve linear equations.
 
int Solve (double &, const double &, const double &) const
 Search the roots of a linear equation over a given interval.
 
void Range (double &, double &, const double &=0.0, const double &=1.0) const
 This function computes the range of values taken by a Linear over a given interval.
 

Static Public Member Functions

static double Step (const double &, const double &, const double &)
 Create a linear step.
 
static double Step (const double &, const double &, const double &, const double &, const double &)
 Create a linear step.
 
static double Affine (const double &, const double &, const double &)
 Create the linear part of a linear step.
 
static double Solve (const double &, const double &, const double &, const double &)
 Compute the root of a linear function such that f(a)=va and f(b)=vb.
 
static double SolveAlpha (const double &, const double &, const double &, const double &)
 Compute the root of a linear function.
 

Protected Attributes

double c [2] = { 0.0 }
 Array of coefficients.
 

Friends

Linear operator+ (const Linear &u, const Linear &v)
 Overloaded.
 
Linear operator- (const Linear &v, const Linear &u)
 Overloaded.
 
Linear operator* (const Linear &u, const double &e)
 Multiply a polynomial by a scalar value.
 
Linear operator* (const double &a, const Linear &p)
 Overloaded.
 
Linear operator/ (const Linear &p, const double &a)
 Overloaded.
 
std::ostream & operator<< (std::ostream &s, const Linear &p)
 Overloaded output-stream operator.
 

Detailed Description

Linear polynomials.

When using constructors, the coefficients are given in descending order:

Linear p(-1.0,1.0); // Linear polynomial -x + 1
Linear()
Empty.
Definition linear.h:12

Constructor & Destructor Documentation

◆ Linear() [1/2]

Linear::Linear ( const double & a,
const double & b )
inlineexplicit

Creates a linear function.

The function is defined as f(x) = a x + b.

Parameters
a,bCoefficients.

◆ Linear() [2/2]

Linear::Linear ( const double & a)
inlineexplicit

Creates a constant function.

Parameters
aConstant.

Member Function Documentation

◆ Affine()

double Linear::Affine ( const double & x,
const double & a,
const double & b )
inlinestatic

Create the linear part of a linear step.

This function does not test limits.

Parameters
xValue
a,bInterval values.
Returns
Real in unit inverval.
See also
Linear::Step

◆ operator()()

double Linear::operator() ( const double & x) const
inlineconstexpr

Evaluates the linear function.

Parameters
xArgument.

◆ Range()

void Linear::Range ( double & x,
double & y,
const double & a = 0.0,
const double & b = 1.0 ) const

This function computes the range of values taken by a Linear over a given interval.

Parameters
a,bInterval.
x,yReturned range.

◆ Solve() [1/3]

double Linear::Solve ( const double & a,
const double & b,
const double & va,
const double & vb )
inlinestatic

Compute the root of a linear function such that f(a)=va and f(b)=vb.

Assuming that the root exists, this function reads easier than the following code, and avoids constructor and parameter computation.

double t;
int n=Linear((vb-va)/(b-a),b*va+a*vb).Solve(t);
See also
Vector::Solve(const Vector& a, const Vector& b, const double&, const double&);

◆ Solve() [2/3]

int Linear::Solve ( double & x) const

Solve linear equations.

This function store the root (ifit exists) in a double and returns the number of roots.

Parameters
xSolution.

◆ Solve() [3/3]

int Linear::Solve ( double & x,
const double & a,
const double & b ) const

Search the roots of a linear equation over a given interval.

Parameters
xSolution.
a,bInterval.

◆ SolveAlpha()

double Linear::SolveAlpha ( const double & a,
const double & b,
const double & va,
const double & vb )
static

Compute the root of a linear function.

The linear function satisfies the constraints: f(a)=va and f(b)=vb; the function returns an interpolant t such that the root satisties r=(1-t) a+t b.

See also
Linear::Solve(const Vector& a, const Vector& b, const double&, const double&);

◆ Step() [1/2]

double Linear::Step ( const double & x,
const double & a,
const double & b )
inlinestatic

Create a linear step.

Parameters
xValue
a,bInterval values.
Returns
Real in unit inverval.
See also
Cubic::SmoothStep, Quintic::SmoothStep

◆ Step() [2/2]

double Linear::Step ( const double & x,
const double & a,
const double & b,
const double & ya,
const double & yb )
inlinestatic

Create a linear step.

This function is the same as coding:

double y=Math::Lerp(ya,yb,Linear::Step(x,a,b));
static double Step(const double &, const double &, const double &)
Create a linear step.
Definition linear.h:195
static double Lerp(const double &, const double &, const double &)
Linear interpolation.
Definition mathematics.h:529
Parameters
xValue
a,bInterval values.
ya,ybOutput interval values.
See also
Cubic::SmoothStep, Quintic::SmoothStep

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const Linear & p )
friend

Overloaded output-stream operator.

Parameters
sStream.
pLinear polynomial.