Home > Back-end >  . Finite difference method to solve heat conduction equation
. Finite difference method to solve heat conduction equation

Time:11-28


Specific topics as shown in figure
 # include 

using namespace std;

Int main ()
{
Double L=6;
Double T=6;

int n;
Cout & lt; <"Both Please input 'n' for 'x'" & lt; Cin & gt;> n;
Cin. The get ();
Int m;
Cout & lt; <"Both Please input the 'm' for the 't'" & lt; Cin & gt;> m;
Cin. The get ();

Long double deltat=T/m;//calculation step length
Long double deltax=L/n;
Double r=deltat/(deltax * deltax);

Int n1=n + 1;
Int m1=m + 1;
Double u (n1) (m1);
Int h, k, l;

For (int a=1; A. & lt; N/2; A=a + 1)//by the boundary value relation and the initial conditions to the array element assignment
{
U [a] [0]=a * deltax;
}

For (int b=n/2; B & lt; N + 1; B=b + 1)
{
U [b] [0]=L - b * deltax;
}

For (int c=1; C & lt; M + 1; C=c + 1)
{
U [0]=u [n] [c] [c]=0;
}

For (int I=1; I & lt; n; I=I + 1)//difference, recursive method to calculate the u
{
H=I - 1;
L=I + 1;

for(int j=0; J & lt; m; J=j + 1)
{
K=j + 1;
U [I] [k]=r * u [h] [j] + (1-2 * r) * u [I] [j] + r * u [l] [j];
}
}

for(int i=0; I & lt; N + 1; I=I + 1)
{
for(int j=0; J & lt; M + 1; J=j + 1)
{
Cout & lt; <"U [& lt; & lt;" I & lt; & lt; "] [" & lt; & lt; j & lt; & lt; "]="& lt; }
}

Cout & lt; Cin. The get ();
}

Input of n=6, m=6, the result of running out the following

These results do not conform to my recursive equation of save the children

Recursive equation is this:
  • Related