0
$\begingroup$

I am new to Mathematica I have a simple question.

I have the following definition:

f[i_,j_] := Integrate[KroneckerDelta[i, j] - ki * kj + Exp[-(kx^2+ky^2)], 
{kx, 0, 10}, {ky, 0, 100}]

I would like to write it in a way that if I call f[x,x] it would compute:

f[x,x] = Integrate[KroneckerDelta[x, x] - kx * kx + Exp[-(kx^2+ky^2)],{kx, 0, 
10}, {ky, 0, 100}]

or if I call f[x,y] it returns:

f[x,y] = Integrate[KroneckerDelta[x, y] - kx * ky + Exp[-(kx^2+ky^2)],{kx, 0, 
10}, {ky, 0, 100}]`
$\endgroup$
8
  • $\begingroup$ Surely just: f[x_] := A^2 x^2 and f[b_, q_] := A^2 b q? $\endgroup$
    – Feyre
    Commented Aug 25, 2016 at 11:39
  • $\begingroup$ I do not realy get the question: if you call your $f[b,q]$ with the arguments $x,x$ it does what you wanted with $f[x,x]$. You should maybe specifiy your question a bit more. $\endgroup$
    – N0va
    Commented Aug 25, 2016 at 11:44
  • $\begingroup$ It's hard even to formulate the question because I am not familiar with it. I edited it, maybe it's clearer now. $\endgroup$ Commented Aug 25, 2016 at 11:56
  • 1
    $\begingroup$ Please always post code as plain text, not LaTeX. Put it in a code block (see ? button in the editing toolbar for help). Make sure that it can be copied and pasted back in to Mathematica. It is hard to tell from what you posted if your function definition is even valid ... $\endgroup$
    – Szabolcs
    Commented Aug 25, 2016 at 11:56
  • 1
    $\begingroup$ That is an extremly strange function; I mean you just want to return some powers of ten why dont you just use f[a_, b_: 0] := 10^(a + b). Or why do you even need such a "function"? $\endgroup$
    – N0va
    Commented Aug 25, 2016 at 11:58

1 Answer 1

3
$\begingroup$

You can use $1-\delta_{xy}$ and $\delta_{xy}$ to get your two different terms $a*b$ and $a*a$:

f[x_, y_] := Integrate[KroneckerDelta[x, y] - KroneckerDelta[x, y]*(a*a) - (1 
- KroneckerDelta[x, y])*(a*b) + Exp[-(a^2 + b^2)], {a, 0, 10}, {b, 0, 10}]

This gives for $$f[x,x]=\int_0^{10}da\int_0^{10}db ~e^{-a^2-b^2}-a^2+1=-3232.55$$ and for $$f[x,y]=\int_0^{10}da\int_0^{10}db ~e^{-a^2-b^2}-a b=-2499.21.$$

$\endgroup$
1
  • $\begingroup$ Smart.Thank you! $\endgroup$ Commented Aug 25, 2016 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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