2019独角兽企业重金招聘Python工程师标准>>>
头文件:
/** Copyright (c) 2008-2011 Zhang Ming (M. Zhang), zmjerry@163.com** This program is free software; you can redistribute it and/or modify it* under the terms of the GNU General Public License as published by the* Free Software Foundation, either version 2 or any later version.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions are met:** 1. Redistributions of source code must retain the above copyright notice,* this list of conditions and the following disclaimer.** 2. Redistributions in binary form must reproduce the above copyright* notice, this list of conditions and the following disclaimer in the* documentation and/or other materials provided with the distribution.** This program is distributed in the hope that it will be useful, but WITHOUT* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for* more details. A copy of the GNU General Public License is available at:* http://www.fsf.org/licensing/licenses*//****************************************************************************** interpolation.h** Base class for interpolation.** Zhang Ming, 2010-04, Xi'an Jiaotong University.*****************************************************************************/#ifndef INTERPOLATION_H
#define INTERPOLATION_H#include
{template
// namespace splab#endif
// INTERPOLATION_H
/** Copyright (c) 2008-2011 Zhang Ming (M. Zhang), zmjerry@163.com** This program is free software; you can redistribute it and/or modify it* under the terms of the GNU General Public License as published by the* Free Software Foundation, either version 2 or any later version.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions are met:** 1. Redistributions of source code must retain the above copyright notice,* this list of conditions and the following disclaimer.** 2. Redistributions in binary form must reproduce the above copyright* notice, this list of conditions and the following disclaimer in the* documentation and/or other materials provided with the distribution.** This program is distributed in the hope that it will be useful, but WITHOUT* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for* more details. A copy of the GNU General Public License is available at:* http://www.fsf.org/licensing/licenses*//****************************************************************************** newtoninterp.h** Newton interpolation method.** For a given points set "Pn" {xn,yn}, this class can find a polynomial which* cross all points of "Pn".** Zhang Ming, 2010-04, Xi'an Jiaotong University.*****************************************************************************/#ifndef NEWTONINTERP_H
#define NEWTONINTERP_H#include
{template
// namespace splab#endif
// NEWTONINTERP_H
实现文件:
/** Copyright (c) 2008-2011 Zhang Ming (M. Zhang), zmjerry@163.com** This program is free software; you can redistribute it and/or modify it* under the terms of the GNU General Public License as published by the* Free Software Foundation, either version 2 or any later version.** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions are met:** 1. Redistributions of source code must retain the above copyright notice,* this list of conditions and the following disclaimer.** 2. Redistributions in binary form must reproduce the above copyright* notice, this list of conditions and the following disclaimer in the* documentation and/or other materials provided with the distribution.** This program is distributed in the hope that it will be useful, but WITHOUT* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for* more details. A copy of the GNU General Public License is available at:* http://www.fsf.org/licensing/licenses*//****************************************************************************** newtoninterp-impl.h** Implementation for NewtonInterp class.** Zhang Ming, 2010-04, Xi'an Jiaotong University.*****************************************************************************//*** constructors and destructor*/
template
NewtonInterp
{
}template
NewtonInterp
{
}/*** Compute polynomial' coefsficients.*/
template
void NewtonInterp
{int N = xi.size();for( int j=1; j
}/*** Compute the value of polynomial at given "x".*/
template
Type NewtonInterp
{int N = xi.size();Type y = 0,tmp = 0;for( int j=0; j
template
inline Vector
{return coefs;
}
测试代码:
/****************************************************************************** newtoninterp_test.cpp** Newton interpolation testing.** Zhang Ming, 2010-04, Xi'an Jiaotong University.*****************************************************************************/#define BOUNDS_CHECK#include
#include
#include
using namespace splab;typedef double Type;int main()
{Vector
运行结果:
Coefficients of Newton interpolated polynomial:size: 5 by 1
0.0000
0.0167
-0.0001
-0.0000
0.0000The true and interpolated values:
0.1736 0.1734
0.3420 0.3419
0.7660 0.7660Process returned 0 (0x0) execution time : 0.078 s
Press any key to continue.