免费观看又色又爽又黄的小说免费_美女福利视频国产片_亚洲欧美精品_美国一级大黄大色毛片

c語言三次樣條差值函數(shù),如何判斷三次樣條函數(shù)

用c語言將x∈[0,2π]區(qū)間幾等分,試用三次樣條插值法方式求x=1.4時y=sinx的值并與y=sin(1.4)作比較

#include stdio.h

創(chuàng)新互聯(lián)建站是專業(yè)的烏審網(wǎng)站建設(shè)公司,烏審接單;提供網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行烏審網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!

#include math.h

double fun(double x,double x0,double x1,double x2,double y0,double y1,double y2)

{

double yx=0;

yx=y0*(x-x1)*(x-x2)/((x0-x1)*(x0-x2))+

y1*(x-x0)*(x-x2)/((x1-x0)*(x1-x2))+

y2*(x-x0)*(x-x1)/((x2-x0)*(x2-x1));//3點插值公式

return yx;

}

int main(int argc, char *argv[])

{

double x,x0,x1,x2,y0,y1,y2;

printf("輸入待求值x:\n");

scanf("%lf",x);

x0=x-0.1;x1=x+0.1;x2=x+0.15;//需要輸入3個插值點,即對應(yīng)的x值和函數(shù)y值,這里簡單計算的可以手動輸入

y0=sin(x0);y1=sin(x1);y2=sin(x2);

printf("sin(%lf)=%lf-------fun(%lf)=%lf\n",x,sin(x),x,fun(x,x0,x1,x2,y0,y1,y2));

return 0;

}

三次樣條插值C語言

我記得大三學(xué)的計算方法課上有,課后作業(yè)實現(xiàn)了的。不過在實驗室那個電腦上,如果你有條件的話先參考《數(shù)值分析》書上吧。

至于c語言和c++的區(qū)別,這個程序應(yīng)該沒什么區(qū)別,反正都拿數(shù)組做。

三次樣條插值計算步驟

三次樣條插值在實際中有著廣泛的應(yīng)用,在計算機上也容易實現(xiàn)。下面介紹用計算機求取三樣條插值函數(shù)S(x)的算法步驟:

(1)輸入初始節(jié)點離散數(shù)據(jù)xi,yi(i=0,1,…,n);

(2)依據(jù)式(6-46),計算hi=xi-xi-1,λi和Ri(i=1,…,n-1);

(3)根據(jù)實際問題,從式(6-49)、式(6-51)和式(6-53)中選擇一類對應(yīng)的邊界條件,求取v0,w0,u0,R0,un,vn,wn,Rn;

(4)根據(jù)形成的方程組(6-54)的特點,選用追趕法、高斯法等解方程組,求出Mi(i=0,1,2,…,n);

(5)依據(jù)式(6-41)、式(6-42),計算插值點的三樣條插值函數(shù)值和該點的導(dǎo)數(shù)值。

求助:求三次樣條插值函數(shù)的C++程序

#includeiostream

#includeiomanip

using

namespace

std;

const

int

MAX

=

50;

float

x[MAX],

y[MAX],

h[MAX];

float

c[MAX],

a[MAX],

fxym[MAX];

float

f(int

x1,

int

x2,

int

x3){

float

a

=

(y[x3]

-

y[x2])

/

(x[x3]

-

x[x2]);

float

b

=

(y[x2]

-

y[x1])

/

(x[x2]

-

x[x1]);

return

(a

-

b)/(x[x3]

-

x[x1]);

}

//求差分

void

cal_m(int

n){

//用追趕法求解出彎矩向量M……

float

B[MAX];

B[0]

=

c[0]

/

2;

for(int

i

=

1;

i

n;

i++)

B[i]

=

c[i]

/

(2

-

a[i]*B[i-1]);

fxym[0]

=

fxym[0]

/

2;

for(i

=

1;

i

=

n;

i++)

fxym[i]

=

(fxym[i]

-

a[i]*fxym[i-1])

/

(2

-

a[i]*B[i-1]);

for(i

=

n-1;

i

=

0;

i--)

fxym[i]

=

fxym[i]

-

B[i]*fxym[i+1];

}

void

printout(int

n);

int

main(){

int

n,i;

char

ch;

do{

cout"Please

put

in

the

number

of

the

dots:";

cinn;

for(i

=

0;

i

=

n;

i++){

cout"Please

put

in

X"i':';

cinx[i];

//coutendl;

cout"Please

put

in

Y"i':';

ciny[i];

//coutendl;

}

for(i

=

0;

i

n;

i++)

//求

步長

h[i]

=

x[i+1]

-

x[i];

cout"Please

輸入邊界條件\n

1:

已知兩端的一階導(dǎo)數(shù)\n

2:兩端的二階導(dǎo)數(shù)已知\n

默認:自然邊界條件\n";

int

t;

float

f0,

f1;

cint;

switch(t){

case

1:cout"Please

put

in

Y0\'

Y"n"\'\n";

cinf0f1;

c[0]

=

1;

a[n]

=

1;

fxym[0]

=

6*((y[1]

-

y[0])

/

(x[1]

-

x[0])

-

f0)

/

h[0];

fxym[n]

=

6*(f1

-

(y[n]

-

y[n-1])

/

(x[n]

-

x[n-1]))

/

h[n-1];

break;

case

2:cout"Please

put

in

Y0\"

Y"n"\"\n";

cinf0f1;

c[0]

=

a[n]

=

0;

fxym[0]

=

2*f0;

fxym[n]

=

2*f1;

break;

default:cout"不可用\n";//待定

};//switch

for(i

=

1;

i

n;

i++)

fxym[i]

=

6

*

f(i-1,

i,

i+1);

for(i

=

1;

i

n;

i++){

a[i]

=

h[i-1]

/

(h[i]

+

h[i-1]);

c[i]

=

1

-

a[i];

}

a[n]

=

h[n-1]

/

(h[n-1]

+

h[n]);

cal_m(n);

cout"\n輸出三次樣條插值函數(shù):\n";

printout(n);

cout"Do

you

to

have

anther

try

?

y/n

:";

cinch;

}while(ch

==

'y'

||

ch

==

'Y');

return

0;

}

void

printout(int

n){

coutsetprecision(6);

for(int

i

=

0;

i

n;

i++){

couti+1":

["x[i]"

,

"x[i+1]"]\n""\t";

/*

coutfxym[i]/(6*h[i])"

*

("x[i+1]"

-

x)^3

+

""

*

(x

-

"x[i]")^3

+

"

(y[i]

-

fxym[i]*h[i]*h[i]/6)/h[i]"

*

("x[i+1]"

-

x)

+

"

(y[i+1]

-

fxym[i+1]*h[i]*h[i]/6)/h[i]"(x

-

"x[i]")\n";

coutendl;*/

float

t

=

fxym[i]/(6*h[i]);

if(t

0)coutt"*("x[i+1]"

-

x)^3";

else

cout-t"*(x

-

"x[i+1]")^3";

t

=

fxym[i+1]/(6*h[i]);

if(t

0)cout"

+

"t"*(x

-

"x[i]")^3";

else

cout"

-

"-t"*(x

-

"x[i]")^3";

cout"\n\t";

t

=

(y[i]

-

fxym[i]*h[i]*h[i]/6)/h[i];

if(t

0)cout"+

"t"*("x[i+1]"

-

x)";

else

cout"-

"-t"*("x[i+1]"

-

x)";

t

=

(y[i+1]

-

fxym[i+1]*h[i]*h[i]/6)/h[i];

if(t

0)cout"

+

"t"*(x

-

"x[i]")";

else

cout"

-

"-t"*(x

-

"x[i]")";

coutendlendl;

}

coutendl;

}

利用c++編程三次樣條插值,題目如下

#include"stdio.h"

#include"math.h"

const double PI = 3.141592654;

const double R=PI/180; //定義常量(角度轉(zhuǎn)弧度的因子)。

double *m(double *y,int length,double j); ////m法////

double *jinsi(double y[],double g[],double a); ///求給定間隔的函數(shù)近似值///

double *jifen(double y[],double g[],double a,double b);//求第一象限內(nèi)的積分

void main()

{

/////給定已知條件////

int a; //給定間隔(角度值a)

double y[361],*p,*q; //定義名為y的數(shù)組存儲函數(shù)值,下標及對應(yīng)角度

double* y1, * y2,*y3,*y4;

double f1[361],f2[361];

printf("請輸入已知sin函數(shù)表的間隔a:");

scanf("%d",a); //就是h (等間距)

for(int i=0;i=360/a;i++)

{

if(i*a%180==0)

y[i]=0.0;

else y[i]=sin(R*i*a); //存儲函數(shù)值

}

p=y;

y1=m(p,360/a+1,R*a); //用m法求一階導(dǎo)(1~n-1)

for(i=0;i=360/a;i++)

{

f1[i]=*(y1+i);

}

///打印///

printf("角度值\t|函數(shù)值\t|一階導(dǎo)數(shù)值\t\n");

for(i=0;i=360/a;i++)

{

if(i/10==0) printf("%d | %f | %f\n",i*a,y[i],f1[i]);

else if(i/100==0) printf("%d | %f | %f\n",i*a,y[i],f1[i]);

else printf("%d | %f | %f\n",i*a,y[i],f1[i]);

}

}

////m法////

double *m(double *y,int length,double j)

{

int n=length-1;

double g1[361];

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

{

g1[i]=(*(y+i+1)-*(y+i-1))*3/(j*2);

}

g1[0]=1;

g1[n]=1;

g1[1]-=0.5*g1[0];

g1[n-1]-=0.5*g1[n];

double a[360];

double c[360];

double d[360];

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

{

a[i]=0.5;

d[i]=2;

c[i]=0.5;

}

c[1]=c[1]/d[1];

g1[1]=g1[1]/d[1];

double t;

for(i=2;in-1;i++)

{

t=d[i]-c[i-1]*a[i];

c[i]/=t;

g1[i]=(g1[i]-g1[i-1]*a[i])/t;

}

g1[n-1]=(g1[n-1]-g1[n-2]*a[n-1])/(d[n-1]-c[n-2]*a[n-1]);

for(i=n-2;i=1;i--)

{

g1[i]=g1[i]-c[i]*g1[i+1];

}

return g1;

}

///求近似函數(shù)值//

double *jinsi(double y[],double g[],double a)//a為弧度值

{

int i=0,j=0;

double f[361];

for(i=0;i360*R/a;i++)

{

for(j=0;ja/R;j++)

{

double x,s,a1,a2,b1,b2;

x=i*a+j*R;//變?yōu)榛《戎?/p>

a1=(1+2*(x-a*i)/a)*(x-a*(i+1))*(x-a*(i+1))/a/a;

a2=(1-2*(x-a*(i+1))/a)*(x-a*i)*(x-a*i)/a/a;

b1=(x-a*i)*(x-a*(i+1))*(x-a*(i+1))/a/a;

b2=(x-a*(i+1))*(x-a*i)*(x-a*i)/a/a;

s=a1*y[i]+y[i+1]*a2+g[i]*b1*g[i+1]*b2; //間隔為10的樣條表達式

f[i*10+j]=s;

}

}

f[360]=0;

return f;

}

double *jifen(double y[],double g[],double a,double b)//a為弧度值

{ int i=0,j=0;

double sum=0;

for(i=0;iPI/2/a;i++)

{

for(j=0;ja/R;j++)

{

double x,s,a1,a2,b1,b2;

x=i*a+j*R;//變?yōu)榛《戎?/p>

a1=(1+2*(x-a*i)/a)*(x-a*(i+1))*(x-a*(i+1))/a/a;

a2=(1-2*(x-a*(i+1))/a)*(x-a*i)*(x-a*i)/a/a;

b1=(x-a*i)*(x-a*(i+1))*(x-a*(i+1))/a/a;

b2=(x-a*(i+1))*(x-a*i)*(x-a*i)/a/a;

s=a1*y[i]+y[i+1]*a2+g[i]*b1*g[i+1]*b2; //間隔為10的樣條表達式

sum+=s*R;

}

}

printf("第一象限內(nèi)的積分值為:%f/n",sum);

return 0;

}

三次樣條插值用c語言具體怎么做

void SPL(int n, double *x, double *y, int ni, double *xi, double *yi); 是你所要。

已知 n 個點 x,y; x 必須已按順序排好。要插值 ni 點,橫坐標 xi[], 輸出 yi[]。

程序里用double 型,保證計算精度。

SPL調(diào)用現(xiàn)成的程序。

現(xiàn)成的程序很多。端點處理方法不同,結(jié)果會有不同。想同matlab比較,你需 嘗試 調(diào)用 spline()函數(shù) 時,令 end1 為 1, 設(shè) slope1 的值,令 end2 為 1 設(shè) slope2 的值。

網(wǎng)頁名稱:c語言三次樣條差值函數(shù),如何判斷三次樣條函數(shù)
文章地址:http://m.newbst.com/article26/hsegcg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、網(wǎng)站策劃、靜態(tài)網(wǎng)站、網(wǎng)站導(dǎo)航網(wǎng)站設(shè)計公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)