16.12.2012 Views

Computer Algebra Recipes

Computer Algebra Recipes

Computer Algebra Recipes

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.2. DIFFUSION AND LAPLACE'S EQUATION MODELS 225<br />

> pdsolve(heateq,HINT=S(x)*F(t));<br />

·½<br />

d<br />

(T (x; t) =S (x) F (t)) &where<br />

dt F (t) = c1 F (t); d2<br />

dx2 S(x) = c1<br />

¾¸<br />

S(x)<br />

The heat equation has been separated into two ODEs, c1 being the separation<br />

constant. If the INTEGRATE option is also included, the general solution of each<br />

ODE will be generated as Russell now illustrates.<br />

> pdsolve(heateq,HINT=S(x)*F(t),INTEGRATE);<br />

(T (x; t) =S (x) F (t)) &where<br />

[ffF (t) = C3 e ( c1 t) g; fS (x) = C1 e ( p c1 x) + C2 e (¡ p c1 x) gg]<br />

There are three unknown constants in the output, namely C1 , C2 ,and C3 .<br />

Finally, including the build option produces the general product solution, sol.<br />

> sol:=pdsolve(heateq,HINT=S(x)*F(t),INTEGRATE,build);<br />

sol := T (x; t) = C3 e ( c1 t) C1 e (p c1 x) + C3 e ( c1 t) C2<br />

e (p c1 x)<br />

Russell then substitutes c1 = ¡k 2 on the rhs of sol and applies the simplify<br />

command with the symbolic option, which is equivalent to assuming that k>0.<br />

> temp:=simplify(subs(_c[1]=-k^2,rhs(sol)),symbolic);<br />

temp := C3 ( C1 e (k (¡tk+xI)) + C2 e (¡k (tk+xI)) )<br />

The resulting form is complex in appearance, so the complex evaluation command<br />

is applied to separate temp into real and imaginary terms.<br />

> temp:=evalc(temp);<br />

temp := C3 ( C1 e (¡k2 t) (¡k cos(kx)+ C2 e 2 t) cos(kx))<br />

+ C3 ( C1 e (¡k2 t) (¡k sin(kx) ¡ C2 e 2 t) sin(kx)) I<br />

The temperature has been expressed in terms of cosine, sine, and exponential<br />

terms, which are now successively collected.<br />

> temp:=collect(%,[cos,sin,exp]);<br />

temp := C3 ( C1 + C2) e (¡k2 t) cos(kx)+ C3 ( C1 ¡ C2 ) e (¡k 2 t) sin(kx) I<br />

Since T (x =0;t) = 0 for all times and cos(kx) does not vanish at x =0,Russell<br />

removes it from temp. This is the ¯rst boundary condition (bc1).<br />

> temp:=remove(has,temp,cos); #bc1<br />

temp := C3 ( C1 ¡ C2 ) e (¡k2 t) sin(kx) I<br />

Similarly, the temperature must also vanish at x = L =1forallt (the second<br />

boundary condition). Therefore sin(kL)=0,sok = n¼=Lwith n =1; 2; 3;:::<br />

The general solution must involve a linear combination of terms involving all<br />

possible n values. With the coe±cient labeled An, thenth term in the Fourier<br />

series representation of the temperature will be of the following form.<br />

> T[n]:=A[n]*subs(k=n*Pi/L,exp(-k^2*t)*sin(k*x)); #bc2<br />

Tn := An e (¡n2 ¼ 2 t) sin(n¼x)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!