Professional Documents
Culture Documents
Explicit Method For The Heat Equation
Explicit Method For The Heat Equation
//
// du/dt = d^2u/dx^2,
// boundary conditions:
// u(t,pi)=u(t,0)=exp(-4*t) for 0 <= t <= 1
// u(0,x)=cos(2*x) for 0 <= x <= pi
//
#include <iostream>
#include <cmath>
#include <armadillo>
int main()
{
double m = 500;
double n = 40;
double T = 1;
double X = 2*acos(0.0); // this is actually pi, or can use 22/7
double h = T / m;
double k = X / n;
double a = h / (k*k);
cout << "m = " << m << ", n = " << n << endl;
cout << "h = " << h << ", k = " << k << endl;
cout << "matrix first 5 rows" << endl; //
cout << u(span(0,4),span(0,n)) << endl;//
cout << "Total squared error = " << squaredError << endl;
u.save("explicit_heat.csv",csv_ascii);
system("pause");
return 0;
}