Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Why is Mathematica assuming k==l and how do I make it

1 view
Skip to first unread message

Bob Hanlon

unread,
Oct 8, 2008, 6:38:13 AM10/8/08
to
Integrate[Cos[k alpha] Cos[l alpha], {alpha, -Pi, Pi},
Assumptions -> {l == k, Element[{l, k}, Integers]}]

Pi

Integrate[Cos[k alpha] Cos[l alpha], {alpha, -Pi, Pi},
Assumptions -> {l != k, Element[{l, k}, Integers]}]

0

Assuming[{l == k, Element[{k, l}, Integers]},
Integrate[Cos[k alpha] Cos[l alpha], {alpha, -Pi, Pi}]]

Pi

Assuming[{l != k, Element[{k, l}, Integers]},
Integrate[Cos[k alpha] Cos[l alpha], {alpha, -Pi, Pi}]]

0


Bob Hanlon

---- Aaron Fude <aaro...@gmail.com> wrote:

=============
As in

Assuming[Element[{k, l}, Integers] ,
Integrate[Cos[k alpha] Cos[l alpha], {alpha, -Pi, Pi}]]

I get 0 whereas the answer is Pi if k=l;

Thanks!

Aaron


--

Bob Hanlon


mariam

unread,
Oct 10, 2008, 4:38:29 AM10/10/08
to
On Oct 8, 12:38 pm, Bob Hanlon <hanl...@cox.net> wrote:
> Integrate[Cos[k alpha] Cos[l alpha], {alpha, -Pi, Pi},
> Assumptions -> {l == k, Element[{l, k}, Integers]}]
>
> Pi
>
> Integrate[Cos[k alpha] Cos[l alpha], {alpha, -Pi, Pi},
> Assumptions -> {l != k, Element[{l, k}, Integers]}]
>
> 0
>
> Assuming[{l == k, Element[{k, l}, Integers]},
> Integrate[Cos[k alpha] Cos[l alpha], {alpha, -Pi, Pi}]]
>
> Pi
>
> Assuming[{l != k, Element[{k, l}, Integers]},
> Integrate[Cos[k alpha] Cos[l alpha], {alpha, -Pi, Pi}]]
>
> 0
>
> Bob Hanlon
>
> ---- Aaron Fude <aaronf...@gmail.com> wrote:
>
> =============
> As in
>
> Assuming[Element[{k, l}, Integers] ,
> Integrate[Cos[k alpha] Cos[l alpha], {alpha, -Pi, Pi}]]
>
> I get 0 whereas the answer is Pi if k=l;
>
> Thanks!
>
> Aaron
>
> --
>
> Bob Hanlon


hi all,
i found your group via web-search.
i am new to mathematica and learning about some codes needed in my
projects.
i want to know that:
1)

Do[{
amplist[i1]= Read[StringJoin[jproc,"/",QCD[i1],"diagrams.amp"]],
ileng[i1] = Length[amplist[i1]],

Do[{
Print["Processing amp[",i1,",",i2,"]"],
If[i1===2,{amp[i1,i2] = amplist[i1][[i2]][[3]]}, {amp[i1,i2] =
amplist[i1][[i2]][[2]]
}],
---------------------------------- and so on.
What does amp[i1,i2] = amplist[i1] [[i2]] [[3]] mean? I mean any
f[i.j]=g[i] [[j]] [[k]]
I am confused about the double-brackets used [[----]].

2) in another expression,
itwo = StringPosition[jproc,"2"][[1,1]]

what for [[ x, y]] is used?

I'll be very grateful for your help.

Jean-Marc Gulliet

unread,
Oct 11, 2008, 6:43:55 AM10/11/08
to
mariam wrote:

*snip*

> i am new to mathematica and learning about some codes needed in my
> projects.
> i want to know that:
> 1)
>
> Do[{
> amplist[i1]= Read[StringJoin[jproc,"/",QCD[i1],"diagrams.amp"]],
> ileng[i1] = Length[amplist[i1]],
>
> Do[{
> Print["Processing amp[",i1,",",i2,"]"],
> If[i1===2,{amp[i1,i2] = amplist[i1][[i2]][[3]]}, {amp[i1,i2] =
> amplist[i1][[i2]][[2]]
> }],
> ---------------------------------- and so on.
> What does amp[i1,i2] = amplist[i1] [[i2]] [[3]] mean? I mean any
> f[i.j]=g[i] [[j]] [[k]]
> I am confused about the double-brackets used [[----]].
>
> 2) in another expression,
> itwo = StringPosition[jproc,"2"][[1,1]]
>
> what for [[ x, y]] is used?

The notation [[__]] is a shortcut for the built-in functions *Part*,
which works to some extent like an index for an array, except that you
can iterate over any kind of expression.


In[1]:= lst = {{a, b, c}, {3, 5, 1}};

In[2]:= lst[[2, 2]]

Out[2]= 5

In[3]:= Do[Print[lst[[x, y]]], {x, 2, 1, -1}, {y, 3, 1, -1}]

During evaluation of In[3]:= 1

During evaluation of In[3]:= 5

During evaluation of In[3]:= 3

During evaluation of In[3]:= c

During evaluation of In[3]:= b

During evaluation of In[3]:= a

In[4]:= poly = a x^3 + b x^2 + c x + d

Out[4]= d + c x + b x^2 + a x^3

In[5]:= poly[[3]]

Out[5]= b x^2

In[6]:= poly[[3, 2]]

Out[6]= x^2

In[7]:= poly[[3, 2, 2]]

Out[7]= 2


You should have a look at the following (short) documents:

"Manipulating Elements of Lists"
http://reference.wolfram.com/mathematica/tutorial/ManipulatingElementsOfLists.html

"Getting Pieces of Lists"
http://reference.wolfram.com/mathematica/tutorial/GettingPiecesOfLists.html

"Parts of Expressions"
http://reference.wolfram.com/mathematica/tutorial/PartsOfExpressions.html

"Manipulating Lists by Their Indices"
http://reference.wolfram.com/mathematica/tutorial/ManipulatingListsByTheirIndices.html

"Part ([[...]])"
http://reference.wolfram.com/mathematica/ref/Part.html

Regards,
-- Jean-Marc

sjoerd.c...@gmail.com

unread,
Oct 11, 2008, 6:46:31 AM10/11/08
to
First of all you should put your question as a new posting and not
hijack a thread that has nothing to do with it.

Secondly, you really should try to read some basic documentation on
Mathematica. Just looking at someone's code and starting a newsgroup
discussion for every element your unfamiliar with is rather
inefficient, to say the least.

Anyway, to answer your question: [[ .. ]] are used to indicate array
indices. Single brackets [ .. ] are used for function arguments.

Sjoerd

> amplist[i1]= Read[StringJoin[jproc,"/",QCD[i1],"diagram=


s.amp"]],
> ileng[i1] = Length[amplist[i1]],
>
> Do[{
> Print["Processing amp[",i1,",",i2,"]"],

> If[i1===2,{amp[i1,i2] = amplist[i1][[i2]][[3]]}, =


{amp[i1,i2] =
> amplist[i1][[i2]][[2]]

> =
=

0 new messages