Zaciatocna funkcia

phi0[x1_,x2_]=Exp[-100.0*((x1-.25)^2+(x2-0.25)^2)];
Plot3D[phi0[x,y],{x,0,1},{y,0,1},PlotRange->{0,1}]
ContourPlot[phi0[x,y],{x,0,1},{y,0,1},PlotRange->All]

Definuj rychlostne vektorove pole

vp1[t_,x1_,x2_]=1.0
vp2[t_,x1_,x2_]=1.0

Parametre pre numericku metodu, zaciatocna numericka funkcia

ii=20; L = 1.0; h=L/ii;
For[i=0, i<=ii, i++, 
For[j=0,j<=ii,j++,
phi[i,j,0] = phi0[i*h,j*h]]];
i=.;j=.;
ListPlot3D[Table[phi[i,j,0],{j,0,ii},{i,0,ii}],DataRange->{{0,1},{0,1}},PlotRange->All]
ListContourPlot[Table[phi[i,j,0],{j,0,ii},{i,0,ii}],DataRange->{{0,1},{0,1}},PlotRange->{0.0,1.0}]

Numericka metoda

T=0.5
tau=h/1.0;
nn=IntegerPart[T/tau]
For[n=0,n<nn,n++,
{
For[i=1, i<=ii-1, i++, 
For[j=1,j<=ii-1,j++,
{
v1=vp1[(n+1/2)*tau,i*h,j*h],
If[v1>0.0,phix =(phi[i,j,n]-phi[i-1,j,n])/h,phix =(phi[i+1,j,n]-phi[i,j,n])/h],
phiOS[i,j] = phi[i,j,n] - tau*(v1*phix ),
}
]
],
For[i=0, i<=ii, i++,phiOS[i,0]=phiOS[i,ii]=phiOS[0,i]=phiOS[ii,i]=0.0;],
For[i=1, i<=ii-1, i++, 
For[j=1,j<=ii-1,j++,
{
v2=vp2[(n+1/2)*tau,i*h,j*h],
If[v2>0.0,phiy =(phiOS[i,j]-phiOS[i,j-1])/h,phiy =(phiOS[i,j+1]-phiOS[i,j])/h],
phi[i,j,n+1] = phiOS[i,j] - tau*(v2*phiy),
}
]
],
For[i=0, i<=ii, i++,phi[i,0,n+1]=phi[i,ii,n+1]=phi[0,i,n+1]=phi[ii,i,n+1]=0.0;],
If[ Mod[n,Quotient[nn,5]]==0,Print[ListPlot3D[Table[phi[i,j,n+1],{j,1,ii-1},{i,1,ii-1}],PlotRange->{0.0,1.0},DataRange->{{0,1},{0,1}}]]]
}
];
ListPlot3D[Table[phi[i,j,n],{j,1,ii-1},{i,1,ii-1}],PlotRange->{0.0,1.0}]

Animate[ListPlot3D[Table[phi[i,j,k],{j,1,ii-1},{i,1,ii-1}],PlotRange->{0.0,1.0}],{k,0,nn,Mod[nn,10]+1},AnimationRepetitions->1]

Animate[ListContourPlot[Table[phi[i,j,k],{j,1,ii-1},{i,1,ii-1}]],{k,0,nn,Mod[nn,10]+1},AnimationRepetitions->1]

nn

phi[30,20,nn]

Min[Table[phi[i,j,nn],{j,1,ii-1},{i,1,ii-1}]]

Max[Table[phi[i,j,nn],{j,1,ii-1},{i,1,ii-1}]]