0
$\begingroup$

I have just started working with Mathematica and I am stuck with something that should be pretty simple, but I cannot find the solution. I want to define a function and then integrate it within a certain interval. The function is defined as follows

w[x_, y_] := With[{r = sqrt[x^2 + y^2]}, 100[1 - (r/0.1)^2] exp[-(r/0.1)^2]]

And the integral is just the squared function between x=[-1,1] and y=[-1,1]

Integrate[w[x_, y_]^2, {x, -1, 1}, {y, -1, 1}]

But the answer I get is just

\begin{equation} \int _{-1}^1\int _{-1}^1\left(100\left(1-100. \text{sqrt}\left(\text{x$\_$}{}^2+\text{y$\_$}{}^2\right){}^2\right)\right){}^2 \exp \left(-100. \text{sqrt}\left(\text{x$\_$}{}^2+\text{y$\_$}{}^2\right){}^2\right){}^2dydx \end{equation}

whereas I would like to get the numerical result.

$\endgroup$

closed as off-topic by b3m2a1, Vitaliy Kaurov, b.gates.you.know.what, Itai Seggev, J. M. is away Sep 7 '17 at 15:59

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." – b3m2a1, Vitaliy Kaurov, b.gates.you.know.what, Itai Seggev, J. M. is away
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ w[x_, y_]^2 should be w[x, y]^2. The _ specifies that it's a function variable in the definition. Pass the variables of integration in to the function to get them to substitute. One other thing: built-in functions use capital letters. So sqrt and exp should be Sqrt and Exp. Maybe also see this? $\endgroup$ – b3m2a1 Sep 7 '17 at 5:59
  • $\begingroup$ and 100[ 2] is not 100 (2) --> 200 $\endgroup$ – Kuba Sep 7 '17 at 5:59
  • $\begingroup$ As noted, capitalization matters. Use Exp[] and Sqrt[]. Also, do not use square brackets for grouping, as you did with 100[1 - (r/0.1)^2]; parentheses are meant for that: 100 (1 - (r/0.1)^2) $\endgroup$ – J. M. is away Sep 7 '17 at 6:00
  • $\begingroup$ Got it, thank you all. Should I delete the question? I am aware is rather a simple one and only because I am completely new to Mathematica. $\endgroup$ – b-fg Sep 7 '17 at 6:04
1
$\begingroup$

You have a number of syntaxes errors. After correcting it looks as follows:

w[x_, y_] := 
 100 (1 - (r/0.1)^2) Exp[-(r/0.1)^2] /. r -> Sqrt[x^2 + y^2];
Integrate[w[x, y]^2, {x, -1, 1}, {y, -1, 1}]
(*  78.5  *)

Have fun!

$\endgroup$
  • $\begingroup$ Yup, got it. Thanks. $\endgroup$ – b-fg Sep 7 '17 at 7:26

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