日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

6-7 Orthogonal Polynomials Approximation (40分)

發布時間:2024/3/26 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 6-7 Orthogonal Polynomials Approximation (40分) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Given a function f and a set of m>0 distinct points x?1?? <x?2?? <?<x?m?? . You are supposed to write a function to approximate f by an orthogonal polynomial using the exact function values at the given m points with a weight w(x?i?? ) assigned to each point x?i?? . The total error err=∑?i=1?m?? w(x?i?? )[7f(x?i?? )?P?n?? (x?i?? )]?2?? must be no larger than a given tolerance.

Format of function:

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

where the function pointer double (*f)(double t) defines the function f; int m is the number of points; double x[] contains points x
?1?? <x?2?? <?<x?m?? ; double w[] contains the values of a weight function at the given points x[]; double c[] contains the coefficients c?0?? ,c?1?? ,?,c?n?? of the approximation polynomial P?n?? (x)=c?0?? +c
?1?? x+?+c?n?? x?n?? ; double *eps is passed into the function as the tolerance for the error, and is supposed to be returned as the value of error. The function OPA is supposed to return the degree of the approximation polynomial.

Note: a constant Max_n is defined so that if the total error is still not small enough when n = Max_n, simply output the result obtained when n = Max_n.

Sample program of judge:

#include <stdio.h> #include <math.h>#define MAX_m 200 #define MAX_n 5double 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 */

Sample Output:
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

思路

1.需要利用一個結構實現多項式相加,多項式內積。

最簡單的方法就是使用數組,并且不需要記錄最高次數,只需要將前面的項系數都變為0即可。相當于一個次數為MAX_n的多項式,前面某些項系數為0。

多項式加法:系數直接相加。

多項式乘x:將系數后移一位

多項式乘常數:系數直接乘

多項式內積:比較麻煩的是,變量可能是y也可能是x。一種思路是兩個都先按照多項式算出∑k=0max_na[k]?xik\sum\limits_{k=0}^{max\_n} a[k]\cdot x_i^kk=0max_n?a[k]?xik?,之后根據傳入的flag確定到底應該選擇f(xi)還是∑k=0max_na[k]?xik\sum\limits_{k=0}^{max\_n}a[k]\cdot x_i^kk=0max_n?a[k]?xik?

2.ppt上計算正交多項式的時候用到了?(x)(x?B1)\phi(x)(x-B_1)?(x)(x?B1?),很明顯應該拆成?(x)x?B1?(x)\phi(x)x-B_1\phi(x)?(x)x?B1??(x)

3.內積別忘了乘w[i]

4.如果內積沒算錯,這題大概率就不會錯。

上代碼

double gx[MAX_m]; double gy[MAX_m]; double gw[MAX_m]; int gm;double Polynomials_Sum(double* f,int flagf, double* g,int flagg)/*計算f(x),g(y)的求和,flg表示后一個變量*/ {double ret = 0;for (int i = 0; i < gm; i++){ double sumf = 0;double sumg = 0;for (int j = 0; j <= MAX_n; j++){sumf += f[j] * pow(gx[i], j);sumg += g[j] * pow(gx[i], j);} sumf = (flagf == 0) ? sumf : gy[i];sumg = (flagg == 0) ? sumg : gy[i];ret += gw[i] * sumg * sumf;}return ret; }int OPA(double (*f)(double t), int m, double x[], double w[], double c[], double* eps) {for (int i = 0; i < m; i++){gx[i] = x[i];gw[i] = w[i];gy[i] = f(x[i]);gm = m;}double phi0[MAX_n+1] = { 0 };double phi1[MAX_n+1] = { 0 };double phi2[MAX_n+1] = { 0 };phi0[0] = 1;double y[MAX_n+1] = {0};y[1] = 1;double a0=Polynomials_Sum(phi0, 0,y,1) / Polynomials_Sum(phi0,0, phi0, 0);for (int i = 0; i <= MAX_n; i++){c[i] = phi0[i] * a0;}double error = Polynomials_Sum(y,1, y, 1) - a0 * Polynomials_Sum(phi0,0, y,1 );double xphi0[MAX_n+1] = {0};for (int i = 0; i < MAX_n; i++)xphi0[i+1] = phi0[i];double B1 = Polynomials_Sum(xphi0,0, phi0, 0) / Polynomials_Sum(phi0,0, phi0, 0);phi1[0] = -B1;phi1[1] = 1;a0 = Polynomials_Sum(phi1, 0, y, 1) / Polynomials_Sum(phi1,0, phi1, 0);for (int i = 0; i <= MAX_n; i++){c[i] += a0 * phi1[i];}error -= a0 * Polynomials_Sum(phi1,0, y, 1);int k = 1;while (k < MAX_n && fabs(error) >= *eps){k++;xphi0[0] = 0;for (int i = 0; i < MAX_n; i++)xphi0[i+1] = phi1[i];B1 = Polynomials_Sum(xphi0,0, phi1,0) / Polynomials_Sum(phi1,0, phi1, 0);double C1 = Polynomials_Sum(xphi0,0, phi0, 0) / Polynomials_Sum(phi0,0, phi0, 0);phi2[0] = 0;if (phi1[MAX_n] != 0) {*eps = error;return k;}for (int i = 0; i < MAX_n; i++)phi2[i + 1] = phi1[i];for (int i = 0; i <= MAX_n; i++)phi2[i] = phi2[i] - B1 * phi1[i] - C1 * phi0[i];double t1 = Polynomials_Sum(phi2, 0, y, 1);double t2 = Polynomials_Sum(phi2, 0, phi2, 0);a0 = t1/t2 ;for (int i = 0; i <= MAX_n; i++)c[i] += a0 * phi2[i];error -= a0 * Polynomials_Sum(phi2,0, y, 1);for (int i = 0; i <= MAX_n; i++){phi0[i] = phi1[i];phi1[i] = phi2[i];} }*eps = error;return k; }

總結

以上是生活随笔為你收集整理的6-7 Orthogonal Polynomials Approximation (40分)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 俄罗斯porn | 无码人妻精品一区二区 | 国产精品av在线免费观看 | 逼特逼在线视频 | 亚洲欧美自拍视频 | 一区二区三区视频免费观看 | aa黄色大片| 亚洲精品黄 | 青青草视频免费看 | 亚洲AV乱码国产精品观看麻豆 | 成人精品视频99在线观看免费 | 超碰在线伊人 | 成人午夜sm精品久久久久久久 | 日本黄色片免费看 | 精品一区二区久久久久久久网站 | 999精品免费视频 | 中国成人毛片 | 777久久久精品一区二区三区 | www.久久国产| 国产精品视频999 | 成人依人 | 农村少妇无套内谢粗又长 | 欧美国产片 | 深夜福利国产精品 | 日韩欧美一区视频 | 国产69精品久久久久777 | www.黄色av| 爱爱视频免费网站 | 国产对白自拍 | 欧美毛片视频 | av国产在线观看 | a色视频| 亚洲免费视频一区二区三区 | 97人妻精品一区二区三区视频 | 欧美日本一区二区三区 | 可以免费看毛片的网站 | 波多野结衣视频一区二区 | 欧美日韩一区二区中文字幕 | 91午夜精品亚洲一区二区三区 | 欧美日韩高清在线播放 | 国产在线一区二 | 色图在线观看 | 欧美丰满美乳xxⅹ高潮www | 精品少妇一区二区三区在线观看 | 亚洲午夜精选 | 黄色三极片 | 琪琪色av | 一区二区中文在线 | 午夜精品一区二区三区在线视频 | 一卡二卡三卡四卡在线 | 天天操操夜夜操操 | 欧美成人资源 | 日韩精品一区二区三区免费视频 | 欧美日韩亚洲国产精品 | 少妇又紧又深又湿又爽视频 | 欧美精品黄色片 | 欧洲性生活视频 | 国产精品免费一区二区三区 | 久久久久久9999 | 日本内谢少妇xxxxx少交 | 日韩美女啪啪 | 国产99久久久国产精品 | 秋霞视频在线观看 | 欧美变态口味重另类在线视频 | 中文无码一区二区三区在线观看 | 桃色一区二区 | 色妞综合网 | 日韩不卡一二三区 | 久久久久久久久久久国产 | 欧美超碰在线观看 | 91丨porny丨九色 | 奇米影视一区二区三区 | 欧美综合在线视频 | 国产精品老女人 | 91精品久久久久久久久久 | 亚洲制服丝袜一区 | 欧美日韩aaa | 污污的视频在线观看 | 国产伦精品一区二区三区视频1 | 91视频免费视频 | 日日不卡av| 亚洲欧美日本韩国 | 国产又粗又黄又爽 | 日本乱大交xxxx公交车 | 国产免费不卡av | 91麻豆精品国产理伦片在线观看 | 欧美日韩18| 亚洲精品在线免费观看视频 | 久久久久高清 | 中文字幕av影视 | 天天想你在线观看完整版高清 | 欧美日韩一卡二卡 | 欧美国产日韩一区二区 | 羞羞成人 | 精品一区二区三区视频日产 | 日本精品成人 | 日韩国产二区 | 在线观看免费av网站 | 水果视频污 |