真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

分段插值函數(shù)C語(yǔ)言 c語(yǔ)言三次樣條插值函數(shù)

拉格朗日插值用c語(yǔ)言怎么編程?各位高手幫幫忙啦

#includestdio.h

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊(cè)、虛擬空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、鶴峰網(wǎng)站維護(hù)、網(wǎng)站推廣。

#includestring.h

#define N 100

typedef struct tag{

double x;

double y;

}POINT;

void main()

{

int i,j,n;

double x,temp,Ln=0;

POINT pt[N];

printf("請(qǐng)輸入你要輸入點(diǎn)的個(gè)數(shù),,1=n=%d:\n",N);

printf("n=");

scanf("%d",n);

printf("\n");

printf("\n請(qǐng)輸入對(duì)應(yīng)的點(diǎn)數(shù)\n");

for(i=0;in;i++)

scanf("%lf,%lf",pt[i].x,pt[i].y);

printf("\n");

printf("輸入插值點(diǎn)x的值:\n");

scanf("%lf",x);

printf("\n");

for(i=0;in;i++)

{

for(j=0,temp=1;jn;j++)

{

if(j!=i)

temp=temp*(x-pt[j].x)/(pt[i].x-pt[j].x);

}

Ln=Ln+temp*pt[i].y;

}

printf("輸出:\nLn(%lf)=%lf\n",x,Ln);

}

求C#分段線性插值算法代碼

///summary

///分段線性插值,將一組數(shù)插值為所需點(diǎn)數(shù)

////summary

///param name="dataIn"待插值的數(shù)據(jù)數(shù)組/param

///param name="n"插值點(diǎn)數(shù)/param

///returns插值后的數(shù)據(jù)數(shù)組/returns

public static double[] Interpolation(double[] dataIn,int n)

{

double[] dataOut = new double[n];

int lenIn = dataIn.Length;

double[] a = new double[lenIn];

double[] divIn = new double[lenIn];

double[] divOut = new double[n];

divIn[0] = 0;

for (int i = 1; i lenIn; i++)

{

divIn[i] = divIn[i - 1] + 1;

}

divOut[0] = 0;

for (int i = 1; i n; i++)

{

divOut[i] = divOut[i - 1] + lenIn / Convert.ToDouble(n);

}

int k = 0;

for (int i = k; i n; i++)

{

for (int j = 0; j lenIn - 1; j++)

{

if (divOut[i] = divIn[j] divOut[i] divIn[j + 1])

{

dataOut[i] = (dataIn[j + 1] - dataIn[j]) * (divOut[i] - divIn[j]) / (divIn[j + 1] - divIn[j]) + dataIn[j];

k = i;

}

}

}

return dataOut;

}

分段線性插值問(wèn)題

#includestdio.h

#includemath.h

double Lagrange1(double *x, double *y, double xx) //拉格郎日插值

{

int i,j;

double *a,yy=0.000;

a=new double[6];

for(i=0;i 6;i++)

{

a[i]=y[i];

for(j=0;j 6;j++)

if(j!=i)

a[i]*=(xx-x[j])/(x[i]-x[j]);

yy+=a[i];

}

delete a;

return yy;

}

double Lagrange2(double *x, double *y, double input) //分段線性插值

{

double output;

int i;

for (i=0;i5;i++)

{

if (x[i] = input x[i+1] = input)

{

output=y[i] +(y[i+1]-y[i])*(input-x[i])/(x[i+1]-x[i]);

break;

}

}

return output;

}

double Lagrange3(double *x,double *y,double u) //分段二次插值

{

int i,k=0;

double v;

for(i=0;i6;i++)

{

if(ux[1])

{

k=0;

v=y[k]*(u-x[k+1])*(u-x[k+2])/((x[k]-x[k+1])*(x[k]-x[k+2]))+y[k+1]*(u-x[k])*(u-x[k+2])/((x[k+1]-x[k])*(x[k+1]-x[k+2]))+y[k+2]*(u-x[k])*(u-x[k+1])/((x[k+2]-x[k])*(x[k+2]-x[k+1]));

}

if((x[i]uu=x[i+1])(fabs(u-x[i])=fabs(u-x[i+1])))

{

k=i-1;

v=y[k]*(u-x[k+1])*(u-x[k+2])/((x[k]-x[k+1])*(x[k]-x[k+2]))+y[k+1]*(u-x[k])*(u-x[k+2])/((x[k+1]-x[k])*(x[k+1]-x[k+2]))+y[k+2]*(u-x[k])*(u-x[k+1])/((x[k+2]-x[k])*(x[k+2]-x[k+1]));

}

if ((x[i]uu=x[i+1])fabs(u-x[i])fabs(u-x[i+1]))

{

k=i;

v=y[k]*(u-x[k+1])*(u-x[k+2])/((x[k]-x[k+1])*(x[k]-x[k+2]))+y[k+1]*(u-x[k])*(u-x[k+2])/((x[k+1]-x[k])*(x[k+1]-x[k+2]))+y[k+2]*(u-x[k])*(u-x[k+1])/((x[k+2]-x[k])*(x[k+2]-x[k+1]));

}

if(ux[4])

{

k=3;

v=y[k]*(u-x[k+1])*(u-x[k+2])/((x[k]-x[k+1])*(x[k]-x[k+2]))+y[k+1]*(u-x[k])*(u-x[k+2])/((x[k+1]-x[k])*(x[k+1]-x[k+2]))+y[k+2]*(u-x[k])*(u-x[k+1])/((x[k+2]-x[k])*(x[k+2]-x[k+1]));

}

}

return v;

}

void main()

{

double x[6] = {0.0, 0.1, 0.195, 0.3, 0.401, 0.5},y[6] = {0.39894,0.39695,0.39142,0.38138,0.36812,0.35206};

double u;

scanf("%lf",u);

printf("%f\n",Lagrange1(x,y,u)); //拉格郎日插值

printf("%f\n",Lagrange2(x,y,u)); //分段線性插值

printf("%f\n",Lagrange3(x,y,u)); //分段二次插值

}

C 語(yǔ)言編程 分段拋物線插值

我這里有2個(gè)程序,第一個(gè)用了2個(gè)函數(shù)

第二個(gè)用了1個(gè)函數(shù),感覺(jué)誤差小些

說(shuō)下用法吧

先輸入數(shù)據(jù) 兩個(gè)兩個(gè)的輸,中間用空格隔開(kāi),比如

please input data1: 11 11.08然后回車

依次輸入完五組數(shù)據(jù)

完了你想查某個(gè)溫度的溶解度,他要求你輸入溫度你輸入11.5

它就輸出對(duì)應(yīng)的溶解度,然后他提示你是否繼續(xù)查溶解度,是就輸入y,想結(jié)束程序

就輸入n.

#includestdio.h

#includestdlib.h

#define NUMBER 5

typedef struct

{

double x;

double y;

}Point;

double * parabola(Point*, Point*, Point*);

double calculate(double* , double );

int main()

{

double x = 0, y = 0;

double* f = NULL;

int i = 0, n = 0;//n為要插的中間那個(gè)點(diǎn)的位置

char c = 'y';

Point p[NUMBER];

for(i = 0; i NUMBER; i++)

{

printf("Please input the point%d:", i+1);

scanf("%lf%lf", p[i].x, p[i].y);

while(10 != getchar())

{

continue;

}

}

while('n' != c)

{

printf("Please input the temperature:");

scanf("%lf", x);

while(10 != getchar())

{

continue;

}

//計(jì)算插值點(diǎn)的位子

if(2 * x = (p[1].x + p[2].x)) n = 1;

else if(2 * x = (p[NUMBER-2].x + p[NUMBER-1].x)) n = NUMBER - 2;

else n = (int)NUMBER / 2;

printf("%d\n", n);

f = parabola(p[n-1],p[n],p[n+1]);//計(jì)算拋物線方程

y = calculate(f,x);//計(jì)算溶解度

printf("The solubility at this temperature is %lf\n", y);

printf("Continue?(y/n) ");

scanf("%c", c);

while(10 != getchar())

{

continue;

}

//釋放內(nèi)存

free(f);

}

return 0;

}

//下面為計(jì)算拋物線方程的函數(shù)

//設(shè)拋物線函數(shù)為y = a * x^2 + b * x + c

//以下f[0]為a,f[1]為b,f[2]為c

double * parabola(Point* p1, Point* p2, Point* p3)

{

double temp1 = 0, temp2 = 0;

double * f = NULL;

f = (double*)calloc(3,sizeof(double));

if(NULL == f)

{

printf("Calloc failed!\n");

return NULL;

}

temp1 = (p2-y - p1-y)/(p2-x - p1-x);

temp2 = (p3-y - p2-y)/(p3-x - p2-x);

f[0] = (temp2 - temp1)/(p3-x - p1-x);

f[1] = temp1 - f[0] * (p1-x + p2-x);

f[2] = p1-y - p1-x * (p1-x * f[0] + f[1]);

return f;

}

//根據(jù)溫度計(jì)算溶解度

double calculate(double* f, double x)

{

double y;

y = x * (f[0] * x + f[1]) + f[2];

return y;

}

//這里是第二個(gè)程序

#includestdio.h

#includestdlib.h

#define NUMBER 5

typedef struct

{

double x;

double y;

}Point;

double parabola(Point*, Point*, Point*, double);

int main()

{

double x = 0, y = 0;

int i = 0, n = 0;//n為要插的中間那個(gè)點(diǎn)的位置

char c = 'y';

Point p[NUMBER];

for(i = 0; i NUMBER; i++)

{

printf("Please input the data%d:", i+1);

scanf("%lf%lf", p[i].x, p[i].y);

while(10 != getchar())

{

continue;

}

}

while('n' != c)

{

printf("Please input the temperature:");

scanf("%lf", x);

while(10 != getchar())

{

continue;

}

//計(jì)算插值點(diǎn)的位子

if(2 * x (p[1].x + p[2].x)) n = 1;

else if(2 * x (p[NUMBER-2].x + p[NUMBER-1].x)) n = NUMBER - 2;

else n = (int)NUMBER / 2;

//printf("%d\n", n);

y = parabola(p[n-1],p[n],p[n+1],x);

printf("The solubility at this temperature is %lf\n", y);

printf("Continue?(y/n) ");

scanf("%c", c);

while(10 != getchar())

{

continue;

}

}

return 0;

}

//直接套用公式計(jì)算溶解度

double parabola(Point* p1, Point* p2, Point* p3, double x)

{

double temp1 = 0, temp2 = 0, temp3 = 0, y = 0;

double a = 0, b = 0, c = 0;

temp1 = (p2-y - p1-y) * (x - p1-x);

temp2 = (p3-y - p1-y) * (p2-x - p1-x) - (p2-y - p1-y) * (p3-x - p1-x);

temp3 = (p3-x - p1-x) * (p3-x - p1-x) * (p2-x - p1-x);

y = p1-y + temp1 / (p2-x - p1-x) + temp2 * (x - p1-x) * (x - p2-x) / temp3;

return y;

}

該程序誤差絕對(duì)小 但結(jié)果和你不是完全符合

你的數(shù)據(jù)好象有點(diǎn)問(wèn)題 14度的溶解度不太正常


新聞名稱:分段插值函數(shù)C語(yǔ)言 c語(yǔ)言三次樣條插值函數(shù)
網(wǎng)頁(yè)地址:http://weahome.cn/article/dojdcpc.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部