0

I'm new to Mathematica and am running in to all sorts of silly difficulties with coding in it. I'm trying to calculate a function f[x, k], normalise it with another function n[k] and then calculate and plot a thrid function en[k] that depends on the first two. Unfortunately, Mathematica won't plot it, and I can't see what I did wrong. I'm sure it's a trivial mistake on my part and I'm sorry to have to ask. Here's my code:

L = 8;
f[x_, k_] := 
  Cos[Pi k/(2 L)]^2  Exp[(-(x - k)^2)/2] - Sin[Pi k/(2 L)]^2 (x - L) Exp[(-(x - k)^2)/2];
n[k_] := Integrate[f[u, k]^2, {u, -L, L}];
en[k_] := Integrate[f[v, k] (-f''[v, k] + (v - k)^2  f[v, k]), {v, -L, L}]/n[k];
Plot[en[k], {k, 0, L}]
m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Kris
  • 141
  • 3

1 Answers1

2

First, as Belisarius points out, you need to indicate the variable for your second derivative. You also need to carry out your differentiation and integrations before you try to plot en[k] Also, please look at the help that is provided here, especially the discussions of the difference between = and :=.

L = 8;
f[x_, k_] :=
  Cos[Pi k/(2 L)]^2 Exp[(-(x - k)^2)/2] - Sin[Pi k/(2 L)]^2 (x - L) Exp[(-(x - k)^2)/2];
n[k_] = Integrate[f[u, k]^2, {u, -L, L}];
d2f[v_, k_] = D[f[v, k], {v, 2}];
en[k_] = Integrate[f[v, k] (d2f[v, k] + (v - k)^2 f[v, k]), {v, -L, L}]/n[k];
Plot[en[k], {k, 0, L}]

plot.png

m_goldberg
  • 107,779
  • 16
  • 103
  • 257