41611

Диференціальні рівняння в частинних похідних

Лабораторная работа

Математика и математический анализ

resizeN1; forint i = 0; i N1; i u[0][i] = conditionih; forint j = 1; j NT; j { file T: htj endl; forint i = 1; i N; i f[i] = u[j1][i1] 2u[j1][i] u[j1][i1] 2hh u[j1][i]1 ht Q 2; l[2] = c; b[2] = f[1] c; u[j][0] = 0; u[j][N] = 0; forint i = 2; i N; i { l[i1] = c l[i]; b[i1] = f[i] b[i] c l[i]; } forint i = N1; i 0; i u[j][i] = l[i1]u[j][i1] b[i1]; int emx = 0; for int i = 0; i N; i { file x: ih ...

Украинкский

2013-10-24

44.88 KB

2 чел.

Науково-навчальний комплекс "Інститут прикладного системного аналізу"  

при Національному технічному університеті України "КПІ"

Кафедра математичних методів системного аналізу

Лабораторна робота № 1

з курсу "Чисельні методи"

на тему "диференціальні рівняння в частинних похідних"

                                

                                        Виконав:      студент 3-го курсу

                                           групи КА-05

                                           Миселюк Артур

                                    Прийняла:   Шубенкова І. А.

Київ 2012

Завдання: Розв’язати рівняння параболічного типу:

Аналітичний розв’язок:

Код програми:

#include <cmath>

#include <fstream>

#include <vector>

using namespace std;

#define PI 3.14159265358979323846

double L = 1.5;

double Q = 0.7;

double solution (double t, double x)

{

 double  alpha = (PI*PI/L/L) + Q;

 return exp(-alpha*t) * sin(PI*x/L);

}

double condition (double x)

{

 return sin(PI*x/L);

}

int main()

{

 ofstream file("output.txt");

 int NT = 11,    

       N = 20;

 double ht = 0.01,

    h = L/N,

    c = 1/(h*h) + 1/ht + Q/2,

    a = 1/(2*h*h);

 vector <vector<double>> u;

 vector <double> f;

 vector <double> l;

 vector <double> b;

f.resize(N+1);

l.resize(N+1);

b.resize(N+1);

u.resize(NT);

 for (int i = 0; i < NT; i++)

 u[i].resize(N+1);

 for(int i = 0; i < N+1; i++)

 u[0][i] = condition(i*h);

 

 for(int j = 1; j < NT; j++)

{

 file << "T:" << ht*j << endl;

 for(int i = 1; i < N; i++)

  f[i] = (u[j-1][i-1] - 2*u[j-1][i] + u[j-1][i+1])/(2*h*h) + u[j-1][i]*(1/ht - Q/2);

 

 l[2] = a/c;

 b[2] = f[1]/c;

 u[j][0] = 0;

 u[j][N] = 0;

 for(int i = 2; i < N; i++)

 {

  l[i+1] = a/(c - a*l[i]);

  b[i+1] = (f[i] + a*b[i])/(c - a*l[i]);

 }

 for(int i = N-1; i > 0; i--)

  u[j][i] = l[i+1]*u[j][i+1] + b[i+1];

 int emax = 0;

 for (int i = 0; i < N; i++)

 {

  file << "x: " << i*h

    << "\tApprox: " << u[j][i]

    << "\tu(t,x): " << solution(j*ht, i*h)

    << "\tError: " << fabs(u[j][i] - solution(j*ht, i*h))

    << endl;

 }

 file << endl;

}  

}

Результати роботи:

T:0.01

x: 0

Approx: 0

u(t,x): 0

Error: 0

x: 0.075

Approx: 0.148688

u(t,x): 0.148676

Error: 1.17766e-005

x: 0.15

Approx: 0.293715

u(t,x): 0.293692

Error: 2.32633e-005

x: 0.225

Approx: 0.43151

u(t,x): 0.431476

Error: 3.41772e-005

x: 0.3

Approx: 0.558679

u(t,x): 0.558635

Error: 4.42495e-005

x: 0.375

Approx: 0.672093

u(t,x): 0.672039

Error: 5.32322e-005

x: 0.45

Approx: 0.768956

u(t,x): 0.768895

Error: 6.09041e-005

x: 0.525

Approx: 0.846886

u(t,x): 0.846819

Error: 6.70765e-005

x: 0.6

Approx: 0.903962

u(t,x): 0.903891

Error: 7.15971e-005

x: 0.675

Approx: 0.93878

u(t,x): 0.938706

Error: 7.43548e-005

x: 0.75

Approx: 0.950482

u(t,x): 0.950407

Error: 7.52817e-005

x: 0.825

Approx: 0.93878

u(t,x): 0.938706

Error: 7.43548e-005

x: 0.9

Approx: 0.903962

u(t,x): 0.903891

Error: 7.15971e-005

x: 0.975

Approx: 0.846886

u(t,x): 0.846819

Error: 6.70765e-005

x: 1.05

Approx: 0.768956

u(t,x): 0.768895

Error: 6.09041e-005

x: 1.125

Approx: 0.672093

u(t,x): 0.672039

Error: 5.32322e-005

x: 1.2

Approx: 0.558679

u(t,x): 0.558635

Error: 4.42495e-005

x: 1.275

Approx: 0.43151

u(t,x): 0.431476

Error: 3.41772e-005

x: 1.35

Approx: 0.293715

u(t,x): 0.293692

Error: 2.32633e-005

x: 1.425

Approx: 0.148688

u(t,x): 0.148676

Error: 1.17766e-005

T:0.02

x: 0

Approx: 0

u(t,x): 0

Error: 0

x: 0.075

Approx: 0.141326

u(t,x): 0.141303

Error: 2.23861e-005

x: 0.15

Approx: 0.279171

u(t,x): 0.279127

Error: 4.4221e-005

x: 0.225

Approx: 0.410143

u(t,x): 0.410078

Error: 6.4967e-005

x: 0.3

Approx: 0.531015

u(t,x): 0.530931

Error: 8.41133e-005

x: 0.375

Approx: 0.638812

u(t,x): 0.638711

Error: 0.000101188

x: 0.45

Approx: 0.730879

u(t,x): 0.730764

Error: 0.000115772

x: 0.525

Approx: 0.80495

u(t,x): 0.804823

Error: 0.000127505

x: 0.6

Approx: 0.8592

u(t,x): 0.859064

Error: 0.000136098

x: 0.675

Approx: 0.892294

u(t,x): 0.892153

Error: 0.00014134

x: 0.75

Approx: 0.903417

u(t,x): 0.903274

Error: 0.000143102

x: 0.825

Approx: 0.892294

u(t,x): 0.892153

Error: 0.00014134

x: 0.9

Approx: 0.8592

u(t,x): 0.859064

Error: 0.000136098

x: 0.975

Approx: 0.80495

u(t,x): 0.804823

Error: 0.000127505

x: 1.05

Approx: 0.730879

u(t,x): 0.730764

Error: 0.000115772

x: 1.125

Approx: 0.638812

u(t,x): 0.638711

Error: 0.000101188

x: 1.2

Approx: 0.531015

u(t,x): 0.530931

Error: 8.41133e-005

x: 1.275

Approx: 0.410143

u(t,x): 0.410078

Error: 6.4967e-005

x: 1.35

Approx: 0.279171

u(t,x): 0.279127

Error: 4.4221e-005

x: 1.425

Approx: 0.141326

u(t,x): 0.141303

Error: 2.23861e-005

T:0.03

x: 0

Approx: 0

u(t,x): 0

Error: 0

x: 0.075

Approx: 0.134327

u(t,x): 0.134295

Error: 3.19151e-005

x: 0.15

Approx: 0.265347

u(t,x): 0.265284

Error: 6.30444e-005

x: 0.225

Approx: 0.389833

u(t,x): 0.389741

Error: 9.26213e-005

x: 0.3

Approx: 0.50472

u(t,x): 0.5046

Error: 0.000119918

x: 0.375

Approx: 0.60718

u(t,x): 0.607035

Error: 0.000144261

x: 0.45

Approx: 0.694688

u(t,x): 0.694523

Error: 0.000165052

x: 0.525

Approx: 0.765091

u(t,x): 0.764909

Error: 0.00018178

x: 0.6

Approx: 0.816655

u(t,x): 0.816461

Error: 0.000194031

x: 0.675

Approx: 0.84811

u(t,x): 0.847908

Error: 0.000201504

x: 0.75

Approx: 0.858682

u(t,x): 0.858478

Error: 0.000204016

x: 0.825

Approx: 0.84811

u(t,x): 0.847908

Error: 0.000201504

x: 0.9

Approx: 0.816655

u(t,x): 0.816461

Error: 0.000194031

x: 0.975

Approx: 0.765091

u(t,x): 0.764909

Error: 0.00018178

x: 1.05

Approx: 0.694688

u(t,x): 0.694523

Error: 0.000165052

x: 1.125

Approx: 0.60718

u(t,x): 0.607035

Error: 0.000144261

x: 1.2

Approx: 0.50472

u(t,x): 0.5046

Error: 0.000119918

x: 1.275

Approx: 0.389833

u(t,x): 0.389741

Error: 9.26213e-005

x: 1.35

Approx: 0.265347

u(t,x): 0.265284

Error: 6.30444e-005

x: 1.425

Approx: 0.134327

u(t,x): 0.134295

Error: 3.19151e-005

T:0.04

x: 0

Approx: 0

u(t,x): 0

Error: 0

x: 0.075

Approx: 0.127676

u(t,x): 0.127635

Error: 4.04448e-005

x: 0.15

Approx: 0.252208

u(t,x): 0.252128

Error: 7.98936e-005

x: 0.225

Approx: 0.37053

u(t,x): 0.370412

Error: 0.000117375

x: 0.3

Approx: 0.479728

u(t,x): 0.479576

Error: 0.000151967

x: 0.375

Approx: 0.577113

u(t,x): 0.576931

Error: 0.000182816

x: 0.45

Approx: 0.660289

u(t,x): 0.66008

Error: 0.000209164

x: 0.525

Approx: 0.727205

u(t,x): 0.726975

Error: 0.000230362

x: 0.6

Approx: 0.776216

u(t,x): 0.77597

Error: 0.000245887

x: 0.675

Approx: 0.806113

u(t,x): 0.805858

Error: 0.000255358

x: 0.75

Approx: 0.816162

u(t,x): 0.815903

Error: 0.000258541

x: 0.825

Approx: 0.806113

u(t,x): 0.805858

Error: 0.000255358

x: 0.9

Approx: 0.776216

u(t,x): 0.77597

Error: 0.000245887

x: 0.975

Approx: 0.727205

u(t,x): 0.726975

Error: 0.000230362

x: 1.05

Approx: 0.660289

u(t,x): 0.66008

Error: 0.000209164

x: 1.125

Approx: 0.577113

u(t,x): 0.576931

Error: 0.000182816

x: 1.2

Approx: 0.479728

u(t,x): 0.479576

Error: 0.000151967

x: 1.275

Approx: 0.37053

u(t,x): 0.370412

Error: 0.000117375

x: 1.35

Approx: 0.252208

u(t,x): 0.252128

Error: 7.98936e-005

x: 1.425

Approx: 0.127676

u(t,x): 0.127635

Error: 4.04448e-005

T:0.05

x: 0

Approx: 0

u(t,x): 0

Error: 0

x: 0.075

Approx: 0.121354

u(t,x): 0.121306

Error: 4.80506e-005

x: 0.15

Approx: 0.239719

u(t,x): 0.239624

Error: 9.49181e-005

x: 0.225

Approx: 0.352182

u(t,x): 0.352042

Error: 0.000139448

x: 0.3

Approx: 0.455973

u(t,x): 0.455792

Error: 0.000180545

x: 0.375

Approx: 0.548536

u(t,x): 0.548319

Error: 0.000217196

x: 0.45

Approx: 0.627593

u(t,x): 0.627344

Error: 0.000248499

x: 0.525

Approx: 0.691196

u(t,x): 0.690922

Error: 0.000273683

x: 0.6

Approx: 0.737779

u(t,x): 0.737487

Error: 0.000292128

x: 0.675

Approx: 0.766197

u(t,x): 0.765893

Error: 0.00030338

x: 0.75

Approx: 0.775747

u(t,x): 0.77544

Error: 0.000307161

x: 0.825

Approx: 0.766197

u(t,x): 0.765893

Error: 0.00030338

x: 0.9

Approx: 0.737779

u(t,x): 0.737487

Error: 0.000292128

x: 0.975

Approx: 0.691196

u(t,x): 0.690922

Error: 0.000273683

x: 1.05

Approx: 0.627593

u(t,x): 0.627344

Error: 0.000248499

x: 1.125

Approx: 0.548536

u(t,x): 0.548319

Error: 0.000217196

x: 1.2

Approx: 0.455973

u(t,x): 0.455792

Error: 0.000180545

x: 1.275

Approx: 0.352182

u(t,x): 0.352042

Error: 0.000139448

x: 1.35

Approx: 0.239719

u(t,x): 0.239624

Error: 9.49181e-005

x: 1.425

Approx: 0.121354

u(t,x): 0.121306

Error: 4.80506e-005

T:0.06

x: 0

Approx: 0

u(t,x): 0

Error: 0

x: 0.075

Approx: 0.115344

u(t,x): 0.11529

Error: 5.48034e-005

x: 0.15

Approx: 0.227849

u(t,x): 0.22774

Error: 0.000108257

x: 0.225

Approx: 0.334743

u(t,x): 0.334584

Error: 0.000159046

x: 0.3

Approx: 0.433394

u(t,x): 0.433188

Error: 0.000205918

x: 0.375

Approx: 0.521374

u(t,x): 0.521126

Error: 0.000247719

x: 0.45

Approx: 0.596516

u(t,x): 0.596232

Error: 0.000283421

x: 0.525

Approx: 0.656969

u(t,x): 0.656657

Error: 0.000312144

x: 0.6

Approx: 0.701246

u(t,x): 0.700913

Error: 0.000333182

x: 0.675

Approx: 0.728256

u(t,x): 0.72791

Error: 0.000346015

x: 0.75

Approx: 0.737334

u(t,x): 0.736984

Error: 0.000350328

x: 0.825

Approx: 0.728256

u(t,x): 0.72791

Error: 0.000346015

x: 0.9

Approx: 0.701246

u(t,x): 0.700913

Error: 0.000333182

x: 0.975

Approx: 0.656969

u(t,x): 0.656657

Error: 0.000312144

x: 1.05

Approx: 0.596516

u(t,x): 0.596232

Error: 0.000283421

x: 1.125

Approx: 0.521374

u(t,x): 0.521126

Error: 0.000247719

x: 1.2

Approx: 0.433394

u(t,x): 0.433188

Error: 0.000205918

x: 1.275

Approx: 0.334743

u(t,x): 0.334584

Error: 0.000159046

x: 1.35

Approx: 0.227849

u(t,x): 0.22774

Error: 0.000108257

x: 1.425

Approx: 0.115344

u(t,x): 0.11529

Error: 5.48034e-005

T:0.07

x: 0

Approx: 0

u(t,x): 0

Error: 0

x: 0.075

Approx: 0.109633

u(t,x): 0.109572

Error: 6.07688e-005

x: 0.15

Approx: 0.216566

u(t,x): 0.216446

Error: 0.000120041

x: 0.225

Approx: 0.318167

u(t,x): 0.317991

Error: 0.000176358

x: 0.3

Approx: 0.411933

u(t,x): 0.411705

Error: 0.000228332

x: 0.375

Approx: 0.495557

u(t,x): 0.495282

Error: 0.000274684

x: 0.45

Approx: 0.566978

u(t,x): 0.566663

Error: 0.000314272

x: 0.525

Approx: 0.624438

u(t,x): 0.624092

Error: 0.000346122

x: 0.6

Approx: 0.666522

u(t,x): 0.666153

Error: 0.000369449

x: 0.675

Approx: 0.692195

u(t,x): 0.691811

Error: 0.000383679

x: 0.75

Approx: 0.700823

u(t,x): 0.700435

Error: 0.000388462

x: 0.825

Approx: 0.692195

u(t,x): 0.691811

Error: 0.000383679

x: 0.9

Approx: 0.666522

u(t,x): 0.666153

Error: 0.000369449

x: 0.975

Approx: 0.624438

u(t,x): 0.624092

Error: 0.000346122

x: 1.05

Approx: 0.566978

u(t,x): 0.566663

Error: 0.000314272

x: 1.125

Approx: 0.495557

u(t,x): 0.495282

Error: 0.000274684

x: 1.2

Approx: 0.411933

u(t,x): 0.411705

Error: 0.000228332

x: 1.275

Approx: 0.318167

u(t,x): 0.317991

Error: 0.000176358

x: 1.35

Approx: 0.216566

u(t,x): 0.216446

Error: 0.000120041

x: 1.425

Approx: 0.109633

u(t,x): 0.109572

Error: 6.07688e-005

T:0.08

x: 0

Approx: 0

u(t,x): 0

Error: 0

x: 0.075

Approx: 0.104204

u(t,x): 0.104138

Error: 6.60085e-005

x: 0.15

Approx: 0.205842

u(t,x): 0.205712

Error: 0.000130392

x: 0.225

Approx: 0.302412

u(t,x): 0.302221

Error: 0.000191564

x: 0.3

Approx: 0.391535

u(t,x): 0.391287

Error: 0.00024802

x: 0.375

Approx: 0.471018

u(t,x): 0.47072

Error: 0.000298368

x: 0.45

Approx: 0.538902

u(t,x): 0.538561

Error: 0.00034137

x: 0.525

Approx: 0.593517

u(t,x): 0.593141

Error: 0.000375966

x: 0.6

Approx: 0.633518

u(t,x): 0.633116

Error: 0.000401304

x: 0.675

Approx: 0.657919

u(t,x): 0.657502

Error: 0.000416761

x: 0.75

Approx: 0.66612

u(t,x): 0.665698

Error: 0.000421956

x: 0.825

Approx: 0.657919

u(t,x): 0.657502

Error: 0.000416761

x: 0.9

Approx: 0.633518

u(t,x): 0.633116

Error: 0.000401304

x: 0.975

Approx: 0.593517

u(t,x): 0.593141

Error: 0.000375966

x: 1.05

Approx: 0.538902

u(t,x): 0.538561

Error: 0.00034137

x: 1.125

Approx: 0.471018

u(t,x): 0.47072

Error: 0.000298368

x: 1.2

Approx: 0.391535

u(t,x): 0.391287

Error: 0.00024802

x: 1.275

Approx: 0.302412

u(t,x): 0.302221

Error: 0.000191564

x: 1.35

Approx: 0.205842

u(t,x): 0.205712

Error: 0.000130392

x: 1.425

Approx: 0.104204

u(t,x): 0.104138

Error: 6.60085e-005

T:0.09

x: 0

Approx: 0

u(t,x): 0

Error: 0

x: 0.075

Approx: 0.0990442

u(t,x): 0.0989736

Error: 7.05796e-005

x: 0.15

Approx: 0.19565

u(t,x): 0.19551

Error: 0.000139421

x: 0.225

Approx: 0.287437

u(t,x): 0.287233

Error: 0.00020483

x: 0.3

Approx: 0.372148

u(t,x): 0.371882

Error: 0.000265195

x: 0.375

Approx: 0.447694

u(t,x): 0.447375

Error: 0.00031903

x: 0.45

Approx: 0.512217

u(t,x): 0.511852

Error: 0.00036501

x: 0.525

Approx: 0.564128

u(t,x): 0.563726

Error: 0.000402001

x: 0.6

Approx: 0.602147

u(t,x): 0.601718

Error: 0.000429094

x: 0.675

Approx: 0.62534

u(t,x): 0.624895

Error: 0.000445622

x: 0.75

Approx: 0.633135

u(t,x): 0.632684

Error: 0.000451177

x: 0.825

Approx: 0.62534

u(t,x): 0.624895

Error: 0.000445622

x: 0.9

Approx: 0.602147

u(t,x): 0.601718

Error: 0.000429094

x: 0.975

Approx: 0.564128

u(t,x): 0.563726

Error: 0.000402001

x: 1.05

Approx: 0.512217

u(t,x): 0.511852

Error: 0.00036501

x: 1.125

Approx: 0.447694

u(t,x): 0.447375

Error: 0.00031903

x: 1.2

Approx: 0.372148

u(t,x): 0.371882

Error: 0.000265195

x: 1.275

Approx: 0.287437

u(t,x): 0.287233

Error: 0.00020483

x: 1.35

Approx: 0.19565

u(t,x): 0.19551

Error: 0.000139421

x: 1.425

Approx: 0.0990442

u(t,x): 0.0989736

Error: 7.05796e-005

T:0.1

x: 0

Approx: 0

u(t,x): 0

Error: 0

x: 0.075

Approx: 0.0941397

u(t,x): 0.0940652

Error: 7.45355e-005

x: 0.15

Approx: 0.185961

u(t,x): 0.185814

Error: 0.000147236

x: 0.225

Approx: 0.273204

u(t,x): 0.272988

Error: 0.000216311

x: 0.3

Approx: 0.35372

u(t,x): 0.35344

Error: 0.000280059

x: 0.375

Approx: 0.425525

u(t,x): 0.425189

Error: 0.000336912

x: 0.45

Approx: 0.486853

u(t,x): 0.486468

Error: 0.000385468

x: 0.525

Approx: 0.536193

u(t,x): 0.535769

Error: 0.000424533

x: 0.6

Approx: 0.57233

u(t,x): 0.571877

Error: 0.000453145

x: 0.675

Approx: 0.594375

u(t,x): 0.593904

Error: 0.000470599

x: 0.75

Approx: 0.601784

u(t,x): 0.601307

Error: 0.000476465

x: 0.825

Approx: 0.594375

u(t,x): 0.593904

Error: 0.000470599

x: 0.9

Approx: 0.57233

u(t,x): 0.571877

Error: 0.000453145

x: 0.975

Approx: 0.536193

u(t,x): 0.535769

Error: 0.000424533

x: 1.05

Approx: 0.486853

u(t,x): 0.486468

Error: 0.000385468

x: 1.125

Approx: 0.425525

u(t,x): 0.425189

Error: 0.000336912

x: 1.2

Approx: 0.35372

u(t,x): 0.35344

Error: 0.000280059

x: 1.275

Approx: 0.273204

u(t,x): 0.272988

Error: 0.000216311

x: 1.35

Approx: 0.185961

u(t,x): 0.185814

Error: 0.000147236

x: 1.425

Approx: 0.0941397

u(t,x): 0.0940652

Error: 7.45355e-005


 

А также другие работы, которые могут Вас заинтересовать

80735. Parts of speech classification, gram-l classes of words 27.62 KB
  There are three main criteria according to which we classify the words into a different gram. classes. They are meaning, form function. not the individual lexical meaning of each word but the meaning common to all the words of a given class which constitutes its essence; form, it’s the morphological characteristics of a type of word...
80736. Text linguistic 28.24 KB
  One-direction sequences can be used in dialogue, when a utterance is not a rejoinder, but a continuation the stimulating utterance addressed the same third party or to both speakers themselves, e. g. St. Erth, all money goes fellows who don’t know a horse from a haystack.- Canynge. And care less want men racing to whom a horse in something.
80738. Morphology: General Principles. Structure of English words 27.02 KB
  Lexicology- is a brunch of linguistics which study the meaning and use of words. In English as in many other languages the word is the smallest unit able to form a sentence by itself. Most words consist of meaningful parts called morphemes, accordingly all Eng. Words fall into two large classes...
80739. The Etimology of English words 26.49 KB
  Etimology study the origin of words and word equivalents. Acc. to the origin all present-day Eng. Words can be divided into two groups: native words, which have been part of the Eng. Vocabulary since the old Eng. period; borrowed words (loan words) which were taken from another lang-ge at a certain stage of Eng. history.
80741. Title as the coding unit of text 27.42 KB
  Lets begin with the units used in titles. Usually these are nouns in the niminative position in singular or plural, combined with position or without it (Mother, Devils, War and Peace) But there may be verbs used in the imperative mood (Live with Lightning), in the firm of the infinitive (to let)...
80742. Syntax and its object. The problem of sentence definition 28.07 KB
  The problem of the definition of S. remains unsolved. There exist 400 different definitions of a S. which fall into 4 main types: psychological, logical, phonetical, structural. The following definition of a S.5 that the S. is a minimal unit of communication is adopted by almost every grammarian.
80743. Paradigmatic structure of the sentence 28.45 KB
  Paradigmatic finds its expression in a system of apposition s making the corresponding meaningful (functional) categories syntactic oppositions are realized by correlated sentence patterns, the relations between which can be described as “transformations”, i.e. transitions to another partern of certain notional parts...