Исследование модели фрактального броуновского движения (1005943), страница 8
Текст из файла (страница 8)
double Ak1[N/2+1];
double Bk1[N/2+1];
double Ak2[N/2+1];
double Bk2[N/2+1];
double beta1[n+1];
double beta2[n+1];
AnsiString buf;
// Считывание значений Mu[k] для данного N и параметра Харста H
for (int i=0; i<=N/2; i++) {
buf = Memo2->Lines->Strings[i];
mu[i] = StrToFloat(buf);
}
// Генерирование случайных величин V[k]
for (int i=0; i<=N/2; i++) {
Ak1[i] = RandG(0,1)/sqrt(N);
Bk1[i] = RandG(0,1)/sqrt(N);
Ak2[i] = RandG(0,1)/sqrt(N);
Bk2[i] = RandG(0,1)/sqrt(N);
}
// Вычисление реализаций ФГШ
for (int i=0; i<=n; i++) {
beta1[i]=0;
beta2[i]=0;
for (int j=1; j<=N/2; j++) {
beta1[i] += cos(mu[j]*i)*Ak1[j] + sin(mu[j]*i)*Bk1[j];
beta2[i] += cos(mu[j]*i)*Ak2[j] + sin(mu[j]*i)*Bk2[j];
}
}
// Масштабирование beta1
double dev = 0;
for (int j=1; j<=n; j++) {
dev += pow(beta1[j],2);
}
dev = dev/n;
double coef = sqrt(1.0/dev);
for (int j=1; j<=n; j++) {
beta1[j] = beta1[j]*coef;
}
// Масштабирование beta2
dev = 0;
for (int j=1; j<=n; j++) {
dev += pow(beta2[j],2);
}
dev = dev/n;
coef = sqrt(1.0/dev);
for (int j=1; j<=n; j++) {
beta2[j] = beta2[j]*coef;
}
// Решение системы диффуров с помощью конечных разностей
for (int i=1; i<=n; i++) {
X[i] = X[i-1]*(1.0-alpha*d) + beta1[i]*pow(d,H);
Y[i] = Y[i-1] + X[i-1]*d + sigma*beta2[i]*pow(d,H);
}
M[0] = 0;
double bbeta = sqrt(pow(alpha,2)+1/pow(sigma,2));
for (int i=1; i<=n; i++) {
M[i] = M[i-1]*(1.0-bbeta*d) + (bbeta-alpha)*(Y[i]-Y[i-1]);
}
// Вычисление масштаба шкалы значений функций
double maxb = 0;
for (int i=0; i<=n; i++) {
if (maxb < fabs(X[i])) {
maxb = fabs(X[i]);
}
if (maxb < fabs(Y[i])) {
maxb = fabs(Y[i]);
}
if (maxb < fabs(M[i])) {
maxb = fabs(M[i]);
}
}
int scale = floor(250/maxb);
if (scale > 249 ) {
scale = 249;
}
Image1->Canvas->Pen->Color = clSilver;
Image1->Canvas->MoveTo(5,250);
Image1->Canvas->LineTo(405,250);
Image1->Canvas->MoveTo(405,250);
Image1->Canvas->LineTo(405,255);
Image1->Canvas->MoveTo(5,250-scale);
Image1->Canvas->LineTo(5,250+scale);
Image1->Canvas->MoveTo(5,250-scale);
Image1->Canvas->LineTo(10,250-scale);
Image1->Canvas->MoveTo(5,250+scale);
Image1->Canvas->LineTo(10,250+scale);
Image1->Canvas->MoveTo(5,250-Y[0]*scale);
Image1->Canvas->Pen->Color = clBlue;
for (int i=1; i<=n; i++) {
Image1->Canvas->LineTo(5+i*2,250-Y[i]*scale);
}
Image1->Canvas->MoveTo(5,250-X[0]*scale);
Image1->Canvas->Pen->Color = clBlack;
for (int i=1; i<=n; i++) {
Image1->Canvas->LineTo(5+i*2,250-X[i]*scale);
}
Image1->Canvas->MoveTo(5,250-M[0]*scale);
Image1->Canvas->Pen->Color = clRed;
for (int i=1; i<=n; i++) {
Image1->Canvas->LineTo(5+i*2,250-M[i]*scale);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnShowClick(TObject *Sender)
{
CanvasClear();
// Вычисление масштаба шкалы значений ФБД
double maxb = 0;
for (int i=0; i<=n; i++) {
if (maxb < fabs(B[i])) {
maxb = fabs(B[i]);
}
}
int scale = floor(250/maxb);
if (scale > 249 ) {
scale = 249;
}
// Отрисовка осей координат
Image1->Canvas->Pen->Color = clSilver;
Image1->Canvas->MoveTo(5,250);
Image1->Canvas->LineTo(405,250);
Image1->Canvas->MoveTo(405,250);
Image1->Canvas->LineTo(405,255);
Image1->Canvas->MoveTo(5,250-scale);
Image1->Canvas->LineTo(5,250+scale);
Image1->Canvas->MoveTo(5,250-scale);
Image1->Canvas->LineTo(10,250-scale);
Image1->Canvas->MoveTo(5,250+scale);
Image1->Canvas->LineTo(10,250+scale);
Image1->Canvas->MoveTo(5,250);
Image1->Canvas->Pen->Color = clBlack;
// Построение графика ФБД
for (int i=0; i<=n; i++) {
Image1->Canvas->LineTo(5+i*2,250-B[i]*scale);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnFBM2Click(TObject *Sender)
// Моделирование ФБД (альтернативный вариант)
{
Memo1->Clear();
CanvasClear();
double mu[N/2+1];
double Ak[N/2+1];
double Bk[N/2+1];
double beta[n+1];
AnsiString buf;
// Считывание значений Mu[k] для данного N и параметра Харста H
for (int i=0; i<=N/2; i++) {
buf = Memo2->Lines->Strings[i];
mu[i] = StrToFloat(buf);
}
// Генерирование случайных величин V[k]
randomize();
for (int i=0; i<=N/2; i++) {
Ak[i] = sqrt(2.0)*RandG(0,1)/sqrt(N);
Bk[i] = sqrt(2.0)*RandG(0,1)/sqrt(N);
}
// Вычисление реализаций ФГШ
for (int i=0; i<n; i++) {
beta[i]=0;
for (int j=1; j<=N/2; j++) {
beta[i] += cos(mu[j]*i)*Ak[j] + sin(mu[j]*i)*Bk[j];
}
}
// Вычисление значений ФБД
B[0] = 0;
Memo1->Lines->Add(AnsiString(B[0]));
for (int i=1; i<=n; i++) {
B[i] = B[i-1] + beta[i-1];
Memo1->Lines->Add(AnsiString(i)+" : "+AnsiString(B[i]));
}
//ScaleMotion();
// Вычисление масштаба шкалы значений ФБД
double maxb = 0;
for (int i=0; i<=n; i++) {
if (maxb < fabs(B[i])) {
maxb = fabs(B[i]);
}
}
int scale = floor(250/maxb);
if (scale > 249 ) {
scale = 249;
}
// Отрисовка осей координат
Image1->Canvas->Pen->Color = clSilver;
Image1->Canvas->MoveTo(5,250);
Image1->Canvas->LineTo(405,250);
Image1->Canvas->MoveTo(405,250);
Image1->Canvas->LineTo(405,255);
Image1->Canvas->MoveTo(5,250-scale);
Image1->Canvas->LineTo(5,250+scale);
Image1->Canvas->MoveTo(5,250-scale);
Image1->Canvas->LineTo(10,250-scale);
Image1->Canvas->MoveTo(5,250+scale);
Image1->Canvas->LineTo(10,250+scale);
Image1->Canvas->MoveTo(5,250);
Image1->Canvas->Pen->Color = clBlack;
// Построение графика ФБД
for (int i=0; i<=n; i++) {
Image1->Canvas->LineTo(5+i*2,250-B[i]*scale);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnErrClick(TObject *Sender)
{
double maxb;
int scale;
Memo1->Clear();
CanvasClear();
if (ind2 == 0) {
double eps[n+1];
double maxe=0;
for (int i=0; i<=n; i++) {
eps[i] = X[i] - M[i];
if (i>10) {
if (fabs(eps[i]) > maxe) {
maxe = fabs(eps[i]);
}
}
}
// Вычисление масштаба шкалы значений функций
maxb = 0;
for (int i=0; i<=n; i++) {
if (maxb < fabs(eps[i])) {
maxb = fabs(eps[i]);
}
}
scale = floor(250/maxb);
if (scale > 249 ) {
scale = 249;
}
Image1->Canvas->Pen->Color = clSilver;
Image1->Canvas->MoveTo(5,250);
Image1->Canvas->LineTo(405,250);
Image1->Canvas->MoveTo(405,250);
Image1->Canvas->LineTo(405,255);
Image1->Canvas->MoveTo(5,250-scale);
Image1->Canvas->LineTo(5,250+scale);
Image1->Canvas->MoveTo(5,250-scale);
Image1->Canvas->LineTo(10,250-scale);
Image1->Canvas->MoveTo(5,250+scale);
Image1->Canvas->LineTo(10,250+scale);
Image1->Canvas->Pen->Color = clRed;
Image1->Canvas->MoveTo(5,250-maxe*scale);
Image1->Canvas->LineTo(405,250-maxe*scale);
Image1->Canvas->MoveTo(5,250+maxe*scale);
Image1->Canvas->LineTo(405,250+maxe*scale);
Image1->Canvas->MoveTo(5,250-eps[0]*scale);
Image1->Canvas->Pen->Color = clBlack;
for (int i=1; i<=n; i++) {
Image1->Canvas->LineTo(5+i*2,250-eps[i]*scale);
}
ind2 = 1;
ShowMessage("maxe = "+AnsiString(maxe));
}
else {
maxb = 0;
for (int i=0; i<=n; i++) {
if (maxb < fabs(X[i])) {
maxb = fabs(X[i]);
}
if (maxb < fabs(Y[i])) {
maxb = fabs(Y[i]);
}
if (maxb < fabs(M[i])) {
maxb = fabs(M[i]);
}
}
scale = floor(250/maxb);
if (scale > 249 ) {
scale = 249;
}
Image1->Canvas->Pen->Color = clSilver;
Image1->Canvas->MoveTo(5,250);
Image1->Canvas->LineTo(405,250);
Image1->Canvas->MoveTo(405,250);
Image1->Canvas->LineTo(405,255);
Image1->Canvas->MoveTo(5,250-scale);
Image1->Canvas->LineTo(5,250+scale);
Image1->Canvas->MoveTo(5,250-scale);
Image1->Canvas->LineTo(10,250-scale);
Image1->Canvas->MoveTo(5,250+scale);
Image1->Canvas->LineTo(10,250+scale);
Image1->Canvas->MoveTo(5,250-Y[0]*scale);
Image1->Canvas->Pen->Color = clBlue;
for (int i=1; i<=n; i++) {
Image1->Canvas->LineTo(5+i*2,250-Y[i]*scale);
}
Image1->Canvas->MoveTo(5,250-X[0]*scale);
Image1->Canvas->Pen->Color = clBlack;
for (int i=1; i<=n; i++) {
Image1->Canvas->LineTo(5+i*2,250-X[i]*scale);
}
Image1->Canvas->MoveTo(5,250-M[0]*scale);
Image1->Canvas->Pen->Color = clRed;
for (int i=1; i<=n; i++) {
Image1->Canvas->LineTo(5+i*2,250-M[i]*scale);
}
ind2=0;
}
}
//---------------------------------------------------------------------------
97