Example 7.9.mw

Example 7.9

> |

> | with(plots):

> | eq:=diff(u(x,t),t)=diff(u(x,t),x$2);

| (1)

> | IC:=u(x,0)=0;

| (2)

> | bc1:=diff(u(x,t),x)=0;

| (3)

> | bc2:=diff(u(x,t),x)=delta;

| (4)

> | eq1:=eval(subs(u(x,t)=g(x,t)+w(x)+v(t),eq));

| (5)

The governing equations for v(t), w(x) and g(x, t) are:

> | eqv:=diff(v(t),t)=k;

| (6)

> | eqw:=diff(w(x),x$2)=k;

| (7)

> | eqg:=diff(g(x,t),t)=diff(g(x,t),x$2);

| (8)

The boundary conditions for w(x) are:

> | bc1w:=diff(w(x),x)=0;

| (9)

> | bc2w:=diff(w(x),x)=delta;

| (10)

w(x) can be solved with the boundary condition at x = 0 as:

> | w(x):=rhs(dsolve({eqw,D(w)(0)=0},w(x)));

| (11)

The value of constant k is found using the boundary condtion at x = 1:

> | bc2w:=subs(x=1,diff(w(x),x))=delta;

| (12)

> | k:=solve(bc2w,k);

| (13)

> | w(x):=1/2*delta*x^2+B;

| (14)

v(t) is solved as:

> | v(t):=rhs(dsolve({eqv,v(0)=0},v(t)));

| (15)

> | Eq:=subs(g(x,t)=X(x)*T(t),eqg):

g(x, t) is obtained as:

> | Eq:=expand(Eq/X(x)/T(t)):

> | Eq_T:=lhs(Eq)=-lambda^2:

> | T(t):=rhs(dsolve({Eq_T,T(0)=T0},T(t))):

> | Eq_X:=rhs(Eq)=-lambda^2:

> | Eq_X:=expand(Eq_X*X(x)):

> | dsolve({Eq_X},X(x)):

> | X(x):=c[1]*sin(lambda*x)+c[2]*cos(lambda*x):

> | Bc1:=diff(X(x),x)=0:

> | Bc2:=diff(X(x),x)=0:

> | Eq_Bc1:=eval(subs(x=0,Bc1)):

> | c[1]:=solve(Eq_Bc1,c[1]):

> | Eq_Bc2:=eval(subs(x=1,Bc2)):

> | Eq_Eig:=sin(lambda)=0:

> | solve(Eq_Eig,lambda):

> | _EnvAllSolutions := true:

> | solve(Eq_Eig,lambda):

> | G1:=eval(X(x)*T(t)):

> | Gn:=subs(c[2]=A[n]/T0,lambda=lambda[n],G1):

> | g(x,t):=Sum(Gn,n=1..infinity):

> | g(x,t):=subs(lambda[n]=n*Pi,g(x,t));

| (16)

> | u(x,t):=g(x,t)+w(x)+v(t);

| (17)

> | eq_An:=eval(subs(t=0,u(x,t)))=rhs(IC);

| (18)

The constant An is found as:

> | phi[n]:=cos(n*Pi*x):

> | r(x):=1:

> | I1:=int(phi[n]^2*r(x),x=0..1):

> | I2:=int((rhs(IC)-w(x))*phi[n]*r(x),x=0..1):

> | vars:={sin(n*Pi)=0}:

> | I1:=subs(vars,I1):

> | I2:=subs(vars,I2):

> | A[n]:=I2/I1;

| (19)

Next, constant B is found as:

> | eqB:=int(lhs(eq_An*r(x)),x=0..1)=int(rhs(eq_An*r(x)),x=0..1);

Error, (in simpl/Im) too many levels of recursion |

> | eqB:=subs(vars,eqB);

| (20)

> | B:=-delta/6;

| (21)

> | u(x,t):=eval(u(x,t));

| (22)

> | u(x,t):=subs(infinity=N,u(x,t)):

> | ua:=subs(N=20,u(x,t)):

> | uu:=piecewise(t=0,rhs(IC),t>0,ua);

| (23)

> | plot3d(subs(delta=1,uu),x=1..0,t=0.5..0,axes=boxed,title="Figure Exp. 7.21.",labels=[x,t,"u"],orientation=[-135,60]);

> | plot([subs(t=0,delta=1,uu),subs(t=0.2,delta=1,uu),subs(t=0.5,delta=1,uu),subs(t=0.7,delta=1,uu),subs(t=1,delta=1,uu)],x=0..1,title="Figure Exp. 7.22.",axes=boxed,thickness=5,labels=[x,"u"],legend=["t=0","t=0.2","t=0.5","t=0.7","t=1.0"]);

> |