Polynomial evaluation

zhaozj2021-02-16  55

// Copyright (C) Liang Yi, 2004

// Last modified: 2004.7. Hangzhou

#ifndef polynomial_header

#define polynomial_header

#include

Using namespace std;

Template >

Class Polynomial:

Public Container

{

PUBLIC:

Polynomial () {}

Polynomial

Const t * pt, size_t n)

{

Copy (PT, PT N, INSERT_ITERATOR > (*

this, begin ())));

}

Polynomial

Const Polynomial & Other)

{

Copy (Other.begin (), Other.end (), Insert_Iterator > (*

this, begin ())));

}

Template

Inline _in qinjiushao_evaluate (_in x, _in idity)

// Identity is a unit, such as: integer 1, floating point number 1.0, unit matrix

{

SIZE_T N = size ();

IF (n == 0)

Return Identity;

Iterator it = begin ();

IF (n == 1)

Return * it;

ERATOR ITER2 = END ();

_In res = (* ip) * x;

iTer ; item2--;

For (; it! = iter2; ore )

{

RES = (res (* ip) * μ) * x;

}

Return RES (* iter2) * identity;

}

Template

inline

_In qinjiushao_evaluate (_IN X)

// This faster

{

SIZE_T N = size ();

IF (n == 0)

Return 1.0;

Iterator it = begin ();

IF (n == 1)

Return * it;

Iterator iter2 = end ();

_In res = (* ip) * x;

iTer2--

iTer ;

For (; it! = iter2; ore )

{

Res = (res (* iter)) * x;

}

Return RES (* iTer2);

}

}

#ENDIF

转载请注明原文地址:https://www.9cbs.com/read-17518.html

New Post(0)