java正交多项式拟合_正交多项式拟合-matlab

任务概述

给定函数f(x)在m个采样点处的值f(xi)以及每个点的权重wi,求曲线拟合的正交多项式Pn(x)满足最小二乘误差||err||2=∑mi=1wi[f(xi)−Pn(xi)]2《TOL。

函数接口定义:

int OPA( double (*f)(double t), int m, double x[], double w[], double c[], double *eps );1

裁判程序样例:

#include 《stdio.h》

#include 《math.h》

#define MAX_m 200

#define MAX_n 5

double f1(double x)

{

return sin(x);

}

double f2(double x)

{

return exp(x);

}

int OPA( double (*f)(double t), int m, double x[], double w[], double c[], double *eps );

void print_results( int n, double c[], double eps)

{

int i;

printf(“%d\n”, n);

for (i=0; i《=n; i++)

printf(“%12.4e ”, c[i]);

printf(“\n”);

printf(“error = %9.2e\n”, eps);

printf(“\n”);

}

int main()

{

int m, i, n;

double x[MAX_m], w[MAX_m], c[MAX_n+1], eps;

m = 90;

for (i=0; i《m; i++) {

x[i] = 3.1415926535897932 * (double)(i+1) / 180.0;

w[i] = 1.0;

}

eps = 0.001;

n = OPA(f1, m, x, w, c, &eps);

print_results(n, c, eps);

m = 200;

for (i=0; i《m; i++) {

x[i] = 0.01*(double)i;

w[i] = 1.0;

}

eps = 0.001;

n = OPA(f2, m, x, w, c, &eps);

print_results(n, c, eps);

return 0;

}

/* Your funcTIon will be put here */

输出样例:

3

-2.5301e-03 1.0287e+00 -7.2279e-02 -1.1287e-01

error = 6.33e-05

4

1.0025e+00 9.6180e-01 6.2900e-01 7.0907e-03 1.1792e-01

error = 1.62e-04

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值