Here’s some C++ functions which evaluate Chebyshev polynomials:

T_{0}(x):

**double** T0(**double** x) ;

T_{1}(x):

**double** T1(**double** x) ;

T_{2}(x):

**double** T2(**double** x) ;

T_{n}(x):

**double** Tn(**unsigned** **int** n, **double** x) ;

These are inline functions defined in the header file, chebyshev.h:

— start —

//==================================================================/** * chebyshev.h -- C++ functions to evaluate Chebyshev polynomials * * Copyright (C) 2007 by James A. Chappell (rlrrlrll@gmail.com) * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * condition: * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. *///================================================================= /* * chebyshev.h: Version 0.01 * Created by James A. Chappell * Created 29 September 2005 * * History: * 28-jul-2007 created */ //==============#ifndef __CHEBYSHEV_H__#define __CHEBYSHEV_H__/* * Function calculates Chebyshev Polynomials Tn(x) */namespaceChebyshev{// n = 0inlinedoubleT0(doublex){return1.0 ;}// n = 1inlinedoubleT1(doublex){returnx ;}// n = 2inlinedoubleT2(doublex){return(2.0 * x*x) - 1.0 ;}/* * Tn(x) */inlinedoubleTn(unsignedintn,doublex){if(n == 0){returnT0(x) ;}elseif(n == 1){returnT1(x) ;}elseif(n == 2){returnT2(x) ;}/* We could simply do this: return (2.0 * x * Tn(n - 1, x)) - Tn(n - 2, x) ; but it could be slow for large n */doubletnm1(T2(x)) ;doubletnm2(T1(x)) ;doubletn(tnm1) ;for(unsignedintl = 3 ; l <= n ; l++){tn = (2.0 * x * tnm1) - tnm2 ; tnm2 = tnm1; tnm1 = tn;}returntn ;}}#endif

— end —

Here’s a sample program:

— start —

#include <iostream>#include "chebyshev.h"usingnamespacestd ;usingnamespaceChebyshev ;intmain(){doubletn ; cout.precision(5) ;for(unsignedintn = 0 ; n <= 5 ; n++){for(doublex = -1.0 ; x <= 1.0 ; x = x + 0.1){tn = Tn(n, x) ; cout << "T" << n << "(" << x << ") = " << tn << endl ;}cout << endl ;}return0 ;}

— end —

**UPDATE: 2014-10-01:**>

This project can now be found on GitHub:

– Chebyshev-polynomials

– HTTPS Clone URL: https://github.com/jachappell/Chebyshev-polynomials.git

– Download ZIP

i just need a C++ polynomial function only input and output streams

I don’t understand your program, however, i have a question for you. “How do you use a struct data type to create a function that evaluates polynomial addition, subtraction and synthetic division?” I would appreciate any help from you. Thanx.

I dont get your program,i have a problem with using struct data to create,input,display,adding,subtracting,dividing ,multiplying,deleting a polynomial of exponents in an array.Please I highly need your help.That will be my pleasure if i get your assistance

This is the same speed as using the trigononmetric definition:

T_n(x) = cos( n*acos(x) ) ONLY FOR -1 <= x <= 1

Tested on Win 7/C++

see http://en.wikipedia.org/wiki/Chebyshev_polynomials#Explicit_expressions