Mathematica Assignment Number 1

Problem 1

u[x_, t_] := 
        Sin[Pi x]*E^-(Pi^2*t);
Plot3D[u[x, t], {t, 0, 1/6}, {x, 0, 1}];

Problem 2

u[x_, t_] := 
        Sin[Pi x] E^(-Pi^2 t)  +   .1*Sin[Pi 10*x] 
            E^(-10^2* Pi^2 t) ;

For[t = 0, t ≤  .005, 
        t +=  .001, 
Plot[u[x, t], {x, 0, 1}, 
            PlotRange -> {0, 1.1}];
];

Problem 3

Integrate[Sin[n Pi x]^2, {x, 0, 1}]

c = 
        Table[4*Integrate[Sin[2*n Pi x], {x, 0, 1/2}], {n, 1, 
            10}];

c

f[x_] := 
        Sum[c[[k]]*Sin[2*k*Pi*x], {k, 1, Length[c]}];

phi[x_] := If[x <  .5, 1, -1];

Plot[{phi[x], f[x]}, {x, 0, 1}];

u[x_, t_] := 
        Sum[c[[k]]*Sin[2*k*Pi*x]*E^(-(2*k*Pi*t)^2), {k, 1, 
            Length[c]}];

For[t = 0, t ≤  .05, 
        t +=  .01, 
Plot[u[x, t], {x, 0, 1}, 
            PlotRange -> {-1.2, 
                1.2}];
];