0
$\begingroup$

I am trying to find a solution on mathematica to

$ \partial_tu-\partial_{xx}u= \cos(2\pi x), \; 0<x<1,\; t>0 $

$ \partial_xu(0,t)=\partial_xu(1,t)=0, \; t>0 $

$ u(x,0) = \sin^2(3\pi x), \; 0 \leq x \leq 1 $

to be able to check my answers when working them out by hand. I have tried several methods, two of which I will list here:

  • Method 1
    sol = NDSolve[{D[u[t, x], {t, 1}] - D[u[t, x], {x, 2}] == Cos[2 \[Pi] x], Derivative[0, 1][u][t, 0] == 0 , u[0, x] == Sin[3 \[Pi] x]^2}, u, {x, 0, 1}, {t, 0, 10}];
    

This gives me an output of an interpolating function. Is there any way to get an explicit answer?

  • Method 2
    eqn = D[u[x,t],t]-D[D[u[x,t],x],x]==Cos[2 \[Pi] x];
    BC1 = D[u[x,t],t]/.x->0==0;
    BC2 = D[u[x,t],t]/.x->1==0;
    IC = u[x,0]==Sin[3\[Pi]x]^2;
    DSolve[{eqn,BC1,BC2,IC},u[x,t],{x,t}]
    
    However, I do not think I am using the right functions to solve this. DSolve, NDSolve? any suggestions would be very welcome. I am trying to read up on their website how to solve PDEs.

Thank you

$\endgroup$
  • $\begingroup$ There are typos in method 1; try sol = NDSolve[{D[u[t, x], {t, 1}] - D[u[t, x], {x, 2}] == Cos[2 \[Pi] x], Derivative[0, 1][u][t, 0] == 0 , u[0, x] == Sin[3 \[Pi] x]^2}, u, {x, 0, 1}, {t, 0, 10}]. $\endgroup$ – b.gates.you.know.what May 14 at 15:51
  • $\begingroup$ thanks for the comment, i get NDSolve::ibcinc: Warning: boundary and initial conditions are inconsistent. NDSolve::bcart: Warning: an insufficient number of boundary conditions have been specified for the direction of independent variable x. Artificial boundary effects may be present in the solution. u-> interpolating function scalar hermite $\endgroup$ – elcharlosmaster May 14 at 15:51
0
$\begingroup$
pde = D[u[x, t], t] - D[u[x, t], x, x] == Cos[2 \[Pi] x];
bcs = Derivative[1, 0][u][0, t] == Derivative[1, 0][u][1, t] == 0;
ic = u[x, 0] == Sin[3 \[Pi] x]^2;
sol = DSolveValue[{pde, bcs, ic}, u[x, t], {x, t}]

enter image description here

Plot3D[sol, {x, 0, 1}, {t, 0, 5}, PlotRange -> All]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.