**
高斯擬合(gaussian fitting)即使用形如:
gi(x)=ai*exp((x-bi)^2/ci^2)
的高斯函式對資料點集進行函式逼近的擬合方法。
其實可以跟多項式
擬合模擬起來,不同的是多項式擬合是用冪函式系,
而高斯擬合是用高斯函式系。
使用高斯函式來進行擬合,優點在於計算積分十分簡單快捷。這一點
在很多領域都有應用,特別是計算化學。著名的化學軟體gaussian98
就是建立在高斯基函式擬合的數學基礎上的。
c#中用math.net 進行矩陣運算 實現方案
double[,] a = new運用c++實現方案double[fitdatas.count, 3
];
double b = new
double
[fitdatas.count];
double x = new
double[3] ;
for (int i = 0; i < fitdatas.count; i++)
3, a, b, x);
mathnet.numerics.linearalgebra.matrix matrixa = new
mathnet.numerics.linearalgebra.matrix(a);
mathnet.numerics.linearalgebra.matrix matrixb = new
mathnet.numerics.linearalgebra.matrix(b, b.length);
mathnet.numerics.linearalgebra.matrix matrixc =matrixa.solve(matrixb);
x = matrixc.getcolumnvector(0
);
double s = -1 / x[2
];
double xmax = x[1] * s / 2.0
;
double ymax = math.exp(x[0] + xmax * xmax / s);
#include#include#include
#include
double f(int n,double x) }
int xianxingfangchengzu(double **a,int n,double *b,double *p,double dt)//
用高斯列主元法來求解法方程組
if(fabs(c)<=dt)
return(0);
if(l!=k)
t=b[k-1];
b[k-1]=b[l-1];
b[l-1]=t;
}c=1/c;
for(j=k+1;j<=n;j++)
b[k-1]*=c;
for(i=k+1;i<=n;i++)
b[i-1]-=b[k-1]*a[i-1][k-1];
}for(i=n;i>=1;i--)
for(j=i+1;j<=n;j++)
b[i-1]-=b[j-1]*a[i-1][j-1];
cout.precision(
12);
for(i=0;ib[i]; }
double** create(int a,int b)//
動態生成陣列
void zuixiaoerchengnihe(double x,double y,int n,double a,intm)
for(i=0;i0.0;
for(i=0;i)
for(j=0;jf(i,x[j]);
for(i=0;i"b["
/記錄b[n]
xianxingfangchengzu(a,m,b,a,1e-6);
deletea;
delete b; }
double pingfangwucha(double x,double y,int n,double a,int m)//
計算最小二乘解的平方誤差
void main(void)
x=new
double[n]; //
存放資料點x
y=new
double[n]; //
存放資料點y
a=new
double[m]; //
存放擬合多項式的係數
cout
<
請輸入所給定的
"個資料x
"<
for(i=0;i)
cout
<
請輸入所給定的
"個資料y
"<
for(i=0;i)
zuixiaoerchengnihe(x,y,n,a,m+1);
cout
<
cout
<
擬合多項式的係數為:
"<
for(i=0;i<=m;i++)cout<
; cout
<
cout
<
平方誤差為:
"<1)<
delete x; delete y;
cout
<
按y繼續,按其他字元退出
"<
cin>>ch;
}while(ch=='
y'||ch=='
y');
高斯曲線擬合原理及實現
高斯 擬合 gaussian fitting 即使用形如 gi x ai exp x bi 2 ci 2 的高斯函式 對資料點集進行函式逼近的 擬合方法。其實可以跟 多項式擬合 模擬起來,不同的是 多項式擬合是用 冪函式系,而高斯擬合是用 高斯函式 系。使用 高斯函式 來進行擬合,優點在於計算積分十...
MATLAB實現高斯曲線擬合
完成某次課程任務,在matlab中新建乙個m檔案,將下列 複製,或者直接複製到命令欄回車即可使用 x 0 0.1 10 0 10每次加0.1,共101個點 y 50 exp x 5 2.2 x,y為初始函式值表現為紅線 x x 因為擬合曲線時需要列向量 y y y0 1 randn 1,101 新增...
手寫高斯牛頓曲線擬合(c
擬合曲線 取100個帶有高斯雜訊的數,利用高斯牛頓法進行擬合求取估計值 a b c 主要步驟 1.構造誤差項 2,求雅克比,以及cost 3,判斷cost是否小於上次cost,小 執行4,大 輸出結果 4,求h g 5求dx 6,更新估計量,到步驟2 高斯牛頓法練習 created by fangu...