A Notebook to illustrate the "Characteristic Method" of numerically solving first order linear PDE' s.

Clear[sol,h,phi,f,ActualSol]

Enter the initial condition.

phi[x_]=If[-1<x<1,1-Abs[x],0]

Plot[phi[x],{x,-3,3}]

Set the grid spacing.

h=0.1

sol:={}

Enter the characteristic equations.

For[n=0,n<40,n++,s=NDSolve[{x'[t]==1+((x[t])^2),z'[t]==0,x[0]==-2+n h,z[0]==phi[-2+n h]},{x,z},{t,0,0.3}];sol=Append[sol,First[{x[0.25],z[0.25]}/.s]]]

sol

f=Interpolation[sol]

Plot the computed solution.

Plot[f[x],{x,-1.1,4}]

For comparison, here is the exact solution computed in class.

ActualSol[x_]:=If[Abs[Tan[ArcTan[x]-0.25]]<1,(1-Abs[Tan[ArcTan[x]-0.25]]),0]

Plot[ActualSol[x],{x,-1.1,4}]

hnew=0.01

solnew={}

Here' s a computed solution on a much finer grid.

For[n=0,n<400,n++,s=NDSolve[{x'[t]==1+((x[t])^2),z'[t]==0,x[0]==-2+n *hnew,z[0]==phi[-2+n* hnew]},{x,z},{t,0,0.3}];solnew=Append[solnew,First[{x[0.25],z[0.25]}/.s]]]

fnew=Interpolation[solnew]

Plot[fnew[x],{x,-1.1,4}]