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$
4
  • $\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, 2017 at 5:59
  • $\begingroup$ and 100[ 2] is not 100 (2) --> 200 $\endgroup$
    – Kuba
    Sep 7, 2017 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$ Sep 7, 2017 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, 2017 at 6:04

1 Answer 1

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$
1
  • $\begingroup$ Yup, got it. Thanks. $\endgroup$
    – b-fg
    Sep 7, 2017 at 7:26

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