FTCS Soluon o he Hea Equaon ME 448/548 Noes Gerald Reckenwald Porland Sae Unversy Deparmen of Mechancal Engneerng gerry@pdxedu ME 448/548: FTCS Soluon o he Hea Equaon Overvew Use he forward fne d erence approxmaon o @u/@ @u @ uk+ u k Use he cenral d erence approxmaon o @ u/@x a me k @ u = uk u k + uk + @x x x 3 Solve for u k+ The compuaonal formula s explc: each value of u k+ can be updaed ndependenly 4 FTCS s easy o mplemen, bu s only condonally sable 5 Truncaon errors are O ( x) and O( ) ME 448/548: FTCS Soluon o he Hea Equaon page
Fne D erence Operaors Choose he forward d erence o evaluae he me dervave a = k @u = uk+ @ k,x u k + O( ) () Approxmae he spaal dervave wh he cenral d erence operaor and ake all nodal values a me k @ u @x x = uk u k + uk + x + O( x ) () ME 448/548: FTCS Soluon o he Hea Equaon page FTCS Approxmaon o he Hea Equaon Subsue Equaon () and Equaon () no he hea equaon u k+ u k = uk u k + uk + x + O( ) +O( x ) (3) Drop runcaon error erms o ge u k+ u k = uk u k + uk + x (4) ME 448/548: FTCS Soluon o he Hea Equaon page 3
FTCS Compuaonal Molecule k+ k k FTCS scheme enables explc calculaon of u a hs node Soluon s known for hese nodes =, k= = + n x x= x=l ME 448/548: FTCS Soluon o he Hea Equaon page 4 FTCS Approxmaon o he Hea Equaon Solve Equaon (4) for u k+ u k+ = ru k + + ( r)uk + ruk (5) where r = / x FTCS s an explc scheme because provdes a smple formula o updae u k+ ndependenly of he oher nodal values a k+ k+ k k =, k= = + n x x= x=l ME 448/548: FTCS Soluon o he Hea Equaon page 5
demoftcs Code funcon errou = demoftcs(nx,n) % Commens and processng of oponal npus skpped % --- Assgn physcal and mesh parameers alfa = ; L = ; max = ; % Dffuson coeffcen, doman lengh and max me dx = L/(nx-); d = max/(n-); r = alfa*d/dx^; r = - *r; % --- Assgn IC and BC u s nalzed o a vecor ha ncludes BC x = lnspace(,l,nx) ; u = sn(p*x/l); % --- Loop over me seps for k=:n uold = u; % prepare for nex sep for =:nx- u() = r*uold(-) + r*uold() + r*uold(+); end end Remember ha he formula for updang u k+ u k+ = ru k + + ( r)uk + ruk s ME 448/548: FTCS Soluon o he Hea Equaon page 6 Alernave formulaon o he FTCS Algorhm Equaon (5) can be expressed as a marx mulplcaon u (k+) = Au (k) (6) where u (k+) s he vecor of u values a me sep k +, u (k) s he vecor of u values a me sep k, anda s he rdagonal marx 3 r ( r) r r ( r) r A = (7) 6 7 4 r ( r) r5 The frs and las rows of A are se o enforce he Drchle boundary condons a x = and x = L ME 448/548: FTCS Soluon o he Hea Equaon page 7
Run he demoftcs code >> demoftcs Error n FTCS soluon = 4 FTCS Exac 8 u 6 4 4 6 8 x ME 448/548: FTCS Soluon o he Hea Equaon page 8 moveftcs(5): Unsable FTCS Soluon 5 = 4 Inal Condon FTCS soluon 5 = 63 Inal Condon FTCS soluon 5 = 96 Inal Condon FTCS soluon 5 5 5 5 5 5 4 6 8 4 6 8 4 6 8 5 = 8 Inal Condon FTCS soluon 5 = 88 Inal Condon FTCS soluon 5 = Inal Condon FTCS soluon 5 5 5 5 5 5 4 6 8 4 6 8 4 6 8 5 = Inal Condon FTCS soluon 5 = 9 Inal Condon FTCS soluon 5 = 4 Inal Condon FTCS soluon 5 5 5 5 5 5 4 6 8 4 6 8 4 6 8 ME 448/548: FTCS Soluon o he Hea Equaon page 9
Condonally Sable FTCS Scheme Observaons: The FTCS soluon appears o be sable a frs Toward he end of he smulaon me, oscllaons grow exponenally Insably s no caused by runcaon error Insably s fed by round-o errors, bu no drecly caused by round-o We ll use a smplfed form of Fourer Sably Analyss Suppose ha he nal condon s a small sne wave The correc soluon s a decay of he sne wave Under wha condon does he soluon grow nsead of decay? Sably or nsably s an nrnsc propery of he scheme FTCS s condonally sable for soluons o he hea equaon ME 448/548: FTCS Soluon o he Hea Equaon page Sably Analyss Suppose he nal condon looks lke hs x u (x) = cos = ( ) x where s a suably small value The soluon a me sep k =s u () = r u (x + )+u (x ) + ( r)u (x ) = r ( ) +( ) + ( r) ( ) = r ( ) + +( ) + ( r) ( ) ME 448/548: FTCS Soluon o he Hea Equaon page
Sably Analyss Snce ( ) + =( ) for any, he soluon a k =can be furher smplfed u () = r ( ) + ( r) ( ) = ( 4r) ( ) = ( 4r)u (x ) The paern s u () = ( 4r)u (x ) u (3) = ( 4r)u () (x )=( 4r) u (x ) u (4) = ( 4r)u (3) (x )=( 4r) 3 u (x ) where u () s he numercal soluon a x and k =; and where ( 4r) s he square of ( 4r) ME 448/548: FTCS Soluon o he Hea Equaon page Sably Analyss The general paern s u k = ( 4r)k u (x ) where ( 4r) k s ( 4r) rased o he k power Therefore, he soluon grows when 4r > Therefore, sably requres 4r < and ( 4r) < 4r <=) 4r <=) r> rue for any r> The second case s ( 4r) < =) 4r <=) r< ME 448/548: FTCS Soluon o he Hea Equaon page 3
Sably Analyss The quck and dry sably analyss shows ha he FTCS scheme s sable only f r = x < (8) Recall: s a parameer of he physcal problem We mus choose and x so ha Equaon (8) s sasfed ME 448/548: FTCS Soluon o he Hea Equaon page 4 Workng wh he FTCS Sably Creron To ncrease accuracy, we wan o decrease boh x and For a gven x, he sably lm for FTCS mposes an upper lm on < x (9) Choosng and x so ha r< does no guaranee an accurae numercal soluon r< only guaranees ha he FTCS soluon wll no blow up ME 448/548: FTCS Soluon o he Hea Equaon page 5
Workng wh he FTCS Sably Creron When reducng x and o mprove accuracy, follow a pah lke A!C no A!B Noe ha he axes have logarhmc scales log( ) Unsable B C A Sable ( x) = α log( x) ME 448/548: FTCS Soluon o he Hea Equaon page 6 Measurng he FTCS Truncaon Error The error repored by demoftcs s defned as E(n x,n )= p nx ku k u(x, k )k () The facor of / p n x convers ku k u(x, k )k o an average error ME 448/548: FTCS Soluon o he Hea Equaon page 7
Measurng he FTCS Truncaon Error Desgnae he local error a x = x and = k as e k = uk u(x, k ) () Defne ē k as an RMS average error per node a me sep k ē k " n x Xnx = (e k ) # / () Algebrac subsuon shows ha E(n x,n )=ē k If he soluon o he hea equaon s smooh, hen E(n x,n )=O( ) +O( x ) ME 448/548: FTCS Soluon o he Hea Equaon page 8 Measurng he runcaon error Sysemacally reduce x and o deermne wheher runcaon error predcon s realzed by he code We know he exac soluon, so we use Equaon() Ths s a es of wheher he code correcly mplemens FTCS Recall ha for FTCS E(n x,n )=O( ) +O( x ) bu sably requres = C x,wherec s a consan Therefore, a sable soluon o FTCS should demonsrae E(n x,n )=O( x ) ME 448/548: FTCS Soluon o he Hea Equaon page 9
Measurng he runcaon error Suppose we don know he exponen of he runcaon error for our code In oher words, nsead of we have where p s uknown E(n x,n )=O( x ) E(n x,n )=O( x p ) Snce x = L n x we have E(n x,n )=O( x p L p )=O (n x ) p ME 448/548: FTCS Soluon o he Hea Equaon page Measurng he runcaon error Smplfy he precedng expresson E(n x,n )=O( x p ) L p = O (n x ) p O (n x ) p O n p x gnore mulplcave consans leadng powers domnae Therefore, we expec E(n x,n )=O n p x ME 448/548: FTCS Soluon o he Hea Equaon page
Measurng he runcaon error Measure E(n x,n ) on wo d erence meshes, n x, and n x, Wh we form he rao Solve for p E(n x,n )=O n p x E(n x,,n ) E(n x,,n ) = n p x, n p x, = p nx, n x, p = log (E(n x,,n )/E(n x,,n )) log (n x, /n x, ) ME 448/548: FTCS Soluon o he Hea Equaon page convftcs Code funcon convftcs % convftcs Convergence of FTCS on a seres of fner spaal meshes % --- Se consans o be conssen wh demoftcs alfa = ; L = ; max=; rsafe = 49999; % sable r<5 % --- Specfy nx and compue n conssen wh sably lm nx = [8 6 3 64 8 56]; dx = L/(nx-); n = cel( + alfa*max*((nx-)^)/(rsafe*l^) ); % --- Loop over mesh szes, sore error and compue order of scheme fprnf( \n nx n error E(j)/E(j-) p\n ); er = NaN; p = ; for j=:lengh(nx); e(j) = demoftcs(nx(j),n(j)); f j> er = e(j)/e(j-); p = log(er)/log(nx(j-)/nx(j)); end fprnf( %5d %5d %3e %84f %84f\n,nx(j),n(j),e(j),er,p); end % -- plong code skpped ME 448/548: FTCS Soluon o he Hea Equaon page 3
Runnng he convftcs Code >> convftcs nx n error E(j)/E(j-) p 8 68e-3 NaN 6 9 356e-3 49 54 3 386 36e-4 46 553 64 589 797e-5 444 39 8 6453 97e-5 47 7 56 6 4895e-6 485 85 E(n x,n y ) 3 4 FTCS deal The las column of ex oupu shows ha demoftcs has he rgh runcaon error behavor 5 6 3 x ME 448/548: FTCS Soluon o he Hea Equaon page 4 Summary for he FTCS Scheme FTCS s easy o mplemen The updae formula s u k+ = ru k + + ( r)uk + ruk The FTCS scheme s condonally sable when r = x < / In wo spaal dmensons wh y = x, he sably condon s r < /4 In 3D wh y = z = x, he sably condon s r</8 There are much beer schemes for solvng he hea equaon FTCS s a oy used o nroduce he numercal soluon of PDEs ME 448/548: FTCS Soluon o he Hea Equaon page 5