-3
$\begingroup$

I made the following about Fourier series:

eo = Integrate[(Cos[Pi*x])^2, {x, 0, 1}]
en := 2*Integrate[(Cos[Pi*x])^2*Cos[n*Pi*x], {x, 0, 1}]
ca = Table[en, {n, 1, 20}]
ListPlot[ca]
v[x_, t_, N_] := eo + Sum[en*Cos[Pi*n*x]*E^[-(n^2)*(Pi^2)*t], {n, 1, N}]
v[x, t, 20]
ContourPlot[v[x, t, 20], {x, 0, Pi}, {t, 0, 0.5}, 
ColorFunction \[RightArrow] "DarkRainbow"]
u[x_, t_, b_, N_] := v[x, t, N]*E^[b*x]
u[x, t, b, 20]
ContourPlot[u[x, t, 5, 20], {x, 0, Pi}, {t, 0, 0.5}, 
ColorFunction \[RightArrow] "DarkRainbow"]

but it seems not to work, and I can't understand the reason. I was trying to solve $ v_t=v_{xx}$ with $ v_x(0,t)=v_x(1,t)=0, v(x,0)=(\cos {(\pi x)})^2, 0<x<1,t >0.$ I calculated analytically and show the results with the partial sums, that is my goal.
Any help?

$\endgroup$
  • $\begingroup$ Not sure what you are doing here. Are you trying to calculate the Fourier series for Cos^2 over half a period? There are built-in routines for Fourier. $\endgroup$ – Hugh Mar 26 at 11:38
  • $\begingroup$ I was trying to solve: $v_t=v_{xx}$ with $v_x(0,t)=v_x(1,t)=0, v[x,0]=(\cos {(\pi x)})^2, 0<x<1,t >0.$ I calculated analytically and show the results, that is my goal $\endgroup$ – George Mar 26 at 11:42
  • $\begingroup$ There're multiple simple mistakes. 1. \[RightArrow] should be ->, notice they're different. 2. The E^[ should be e.g. Exp[. 3. {x,0,Pi} should be {x,0,1}. 4. If the ListPlot doesn't even work, consider Clear[x,n] at the beginning. $\endgroup$ – xzczd Mar 26 at 13:34
3
$\begingroup$

Mathematica solves your PDE with the boundary and initial conditions by

sol = DSolve[{D[v[x, t], t] == D[v[x, t], {x, 2}], Derivative[1, 0][v][0, t] == 0, 
Derivative[1, 0][v][1, t] == 0, v[x, 0] == Cos[Pi*x^2]^2}, v[x,t], {x, t}]

(* {{v[x, t] ->  1/4 (2 + FresnelC[2]) + 
2 Inactive[Sum][ 1/8 E^(-\[Pi]^2 t K[1]^2)
    Cos[\[Pi] x K[
      1]] (Cos[1/8 \[Pi] K[1]^2] FresnelC[2 - K[1]/2] + 
     Cos[1/8 \[Pi] K[1]^2] FresnelC[
       1/2 (4 + K[1])] + (FresnelS[2 - K[1]/2] + 
        FresnelS[1/2 (4 + K[1])]) Sin[1/8 \[Pi] K[1]^2]), {K[1], 
   1, \[Infinity]}]*)

In order to visualize the solution,

asol = v[x, t] /. sol[[1]] /. {\[Infinity] -> 3} // Activate;
Plot3D[asol // Evaluate, {x, 0, 1}, {t, 0, 2}, Exclusions -> None, 
PlotRange -> All, PlotPoints -> 50]

enter image description here

PS. It seems you changed the initial condition from $\cos(x^2))^2$ to $\cos(x)^2$. In this case

DSolve[{D[v[x, t], t] == D[v[x, t], {x, 2}], Derivative[1, 0][v][0, t] == 0, Derivative[1, 0][v][1, t] == 0, v[x, 0] == Cos[Pi*x]^2}, v[x, t], {x, t}]
(*{{v[x, t] -> 1/2 (1 + E^(-4 \[Pi]^2 t) Cos[2 \[Pi] x])}}*)
|improve this answer|||||
$\endgroup$
  • $\begingroup$ I need to show the partial sums, as I tried and plot them $\endgroup$ – George Mar 26 at 12:22
  • $\begingroup$ I added that in response to your additional request. $\endgroup$ – user64494 Mar 26 at 12:30
  • $\begingroup$ Thank you, I preffer an answer about my original question $\endgroup$ – George Mar 26 at 12:31
  • $\begingroup$ @George: You missed the minus sign in E^[(n^2)*(Pi^2)*t]. $\endgroup$ – user64494 Mar 26 at 12:42
  • $\begingroup$ that is right. But ca and the ListPlot doesn't work, and so the others command and I don;t know the reason $\endgroup$ – George Mar 26 at 12:45

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