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 bought Mathematica (for Linux) today and am trying to calculate this integral:

\begin{align} \int\limits_{-\tfrac{\pi}{2}a}^{\tfrac{\pi}{2}a}A\cos^2\left(\tfrac{x}{a}\right)\left[-\tfrac{\hbar^2}{2m}\tfrac{d^2}{dx^2}\left(A\cos^2\left(\tfrac{x}{a}\right)\right)\right] \,dx \end{align}

What I inserted in Mathematica was something like this:

A = 0.921*10^-9
h = 1.055*10^-34
m = 9.109*10^-31
a = 1*10^-9

f[x_] := A*Cos^2 (x/a)
g[x_] := -(h^2/(2*m))*Derivative[2][f[x]]
Integrate[f[x]*g[x], {x,-Pi/2*a, Pi/2*a}]

For some reason it is not working and I get an error:

"Tag Times in (9.21*10^-10\ (Cos^2)[1000000000\ x])[x_] is Protected."

Please take it easy on me it is my first post.


Do i only have to ann an N in front of an Integratate to get a numerical value?

EDIT: After inputing what you sugested i get an error again:

enter image description here

share|improve this question
I remember reading an answer on the site about the difference between N@Integrate[..] and NIntegrate[..]. Perhaps someone will find it. –  Michael E2 Aug 3 '13 at 13:53
Si do i have to write square of a cosine like this (Cos(x/a))^2? –  71GA Aug 3 '13 at 14:34
Although this is not the most enlightened question ever seen, OP has clearly made an effort to engage with community norms by asking an understandable and properly formatted question. As such, I don't feel that the downvotes are entirely justified in this case, and would humbly suggest that we might try to be more encouraging (or at least not actively discouraging) toward a newcomer to the software and to the site. There are many stupid questions and unreasonable OPs far more deserving of your downvotes than this. –  Oleksandr R. Aug 4 '13 at 16:55
add comment

closed as off-topic by Michael E2, Yves Klett, Simon Woods, Sjoerd C. de Vries, rm -rf Aug 3 '13 at 17:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Michael E2, Yves Klett, Simon Woods, Sjoerd C. de Vries, rm -rf
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 3 down vote accepted

Mathematica can do this symbolically:

Clear[f, g, A, a, h, m, x];
f[x_] := A*Cos[x/a]^2;
g[x_] := -(h^2/(2*m))*Derivative[2][f][x];
Integrate[f[x]*g[x], {x, -Pi/2*a, Pi/2*a}]
(* (A^2 h^2 \[Pi])/(4 a m) *)

You might want to study the following references to get the hang of Mathematica syntax and definitions.

share|improve this answer
I tried to directly copy/paste your solution, but i get the same error. I pasted it in an EDIT. –  71GA Aug 3 '13 at 14:38
@71GA, try quitting the kernel (Evaluation menu) to clear any unwanted definitions and run the code again. –  Simon Woods Aug 3 '13 at 15:04
I worote QuitKerneland pressed SHIFT + ENTER and nothing helped. –  71GA Aug 3 '13 at 15:12
@71GA I would suggest copying code to clip board.Closing Mathematica then restarting. Paste the code in new notebook and running again. Some previous definitions are preventing execution. You can use Clear but this depends on what you had been doing. Easier to close and restart. –  ubpdqn Aug 3 '13 at 15:21
It worked now. Is it possible that Mathematica isn't optimized for Linux? –  71GA Aug 3 '13 at 15:34
show 1 more comment

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