数据结构-9阶多项式

Posted MintTremor

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据结构-9阶多项式相关的知识,希望对你有一定的参考价值。

#include<stdio.h>
#include<time.h>
#include<math.h>
clock_t start, stop;
double duration;
#define MAXN 10 //多项式最大项数,即多项式阶数+1

double f1(int n, double a[], double x)
{
int i;
double p = a[0];
for (i = 1; i <= n; i++)
p += (a[i]*pow(x, i));
return p;

}

double f2(int n, double a[], double x)
{
int i;
double p = a[n];
for (i = n; i > 0; i++)
p = a[i - 1] + x*p;
return p;

}

int main()
{
int i;
double a[MAXN];
for (i = 0; i < MAXN; i++)
a[i] = (double)i;
start = clock();
f1(MAXN - 1, a, 1.1);
stop = clock();
duration = ((double)(stop - start)) / CLK_TCK;
printf("ticks1= %f\n", (double)(stop - start));
printf("duration1 = %6.2e\n", duration);


start = clock();
f1(MAXN - 1, a, 1.1);
stop = clock();
duration = ((double)(stop - start)) / CLK_TCK;
printf("ticks2= %f\n", (double)(stop - start));
printf("duration2 = %6.2e\n", duration);
getchar();
return 0;
}

以上是关于数据结构-9阶多项式的主要内容,如果未能解决你的问题,请参考以下文章

数据结构与算法总结

ML学习七——正则化

利用MATLAB进行曲线拟合

已知一组数据,用JAVA JFRAME利用最小二乘法求出该组数据的多项式拟合公式

比较求N阶多项式的算法比较

R语言ggplot2可视化多项式曲线多项式方程以及多项式模型评估指标R方:使用ploynom包拟合三阶多项式模型