Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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}]
share|improve this question
1  
I think you should specify the derivation variable in f''[v,k] –  belisarius Oct 24 '13 at 23:11
    
Thanks, that did it. You deserve a kiss. –  Kris Oct 24 '13 at 23:47
    
You don't mention the nominated kisser, but I'll take that as a compliment at any rate. –  belisarius Oct 24 '13 at 23:57
add comment

1 Answer

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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