Message Boards Message Boards

0
|
3540 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Use Round in NIntegrate?

Posted 4 years ago

I need to integrate an expression using Nintegrate. A problematic part is that this expression contains a variable Cp whose values come from an discrete array which is accessed like Cp[[n]] for the nth element. The integrand contains such quantities where the variable is such that Cp[[magnitude of a vector]] hence I would have to round the vector magnitude to ensure it's an integer and hence one can access the correct element of Cp. However, when I use Round, I get the following error.

Part::pkspec1: The expression IntegerPart[Sqrt[Abs[l1 Cos[\[CapitalPhi]]]^2+Abs[l1 Sin[\[CapitalPhi]]]^2]] cannot be used as a part specification.

This is the full integral in question

Integral

POSTED BY: Jiatianfu Qu
4 Replies
Posted 4 years ago

Hi Jiatianfu,

I don't think so. Looks like there is an extra set of [ ] somewhere in your code, maybe Cp[[...]] should be Cp[...]? Hard to say without seeing all of the code (please post code, not images). There is a clue in the error message Cos[[CapitalPhi]] is an example of the extra set of [ ].

POSTED BY: Rohit Namjoshi
Posted 4 years ago

Hi Rohit: This is the full set of code + definition of variables

Ci = Flatten[Import["Downloads/ctjulien.txt", "table"]]
Cp = Flatten[Import["Downloads/clphiphi.txt", "table"]]
Subscript[C, t] = 
 Flatten[Import["Downloads/clphiphi.txt", "table"]]       
Lp[a_] := 1052*{Cos[a], Sin[a]}
vL[L_] := {L, 0}
l[l1_, \[CapitalPhi]1_] := 
 l1*{Cos[\[CapitalPhi]1], Sin[\[CapitalPhi]1]}
f[x_, y_] := 
 Ci[[IntegerPart[Norm[x]]]]*Dot[x + y, x] + 
  Ci[[IntegerPart[Norm[y]]]]*Dot[x + y, y]
F[x_, y_] := 
 f[x, y]/(2*Subscript[C, t][[IntegerPart[Norm[x]]]]*
    Subscript[C, t][[IntegerPart[Norm[y]]]])

L = 40
NIntegrate[
 l1*F[l[l1, \[CapitalPhi]], {L, 0} - l[l1, \[CapitalPhi]]]*
  F[Lp[\[CapitalPhi]p], {L, 0} - 
    Lp[\[CapitalPhi]p]]*(Dot[Lp[\[CapitalPhi]p], 
      Lp[\[CapitalPhi]p] - l[l1, \[CapitalPhi]]]*
     Cp[[Round[Norm[Lp[\[CapitalPhi]p] - l[l1, \[CapitalPhi]]]]]]*
     f[-{L, 0} + l[l1, \[CapitalPhi]], {L, 0} - Lp[\[CapitalPhi]p]] + 
    Dot[Lp[\[CapitalPhi]p], 
      Lp[\[CapitalPhi]p] - 
       l[{L, 0} - l[l1, \[CapitalPhi]], \[CapitalPhi]]]*
     Cp[[Round[
        Norm[Lp[\[CapitalPhi]p] - 
          l[{L, 0} - l[l1, \[CapitalPhi]], \[CapitalPhi]]]]]]*
     f[-l[l1, \[CapitalPhi]], {L, 0} - 
       Lp[\[CapitalPhi]p]]), {\[CapitalPhi], -Pi, 
  Pi}, {\[CapitalPhi]p, -Pi, Pi}, {l1, 2, 2900}]
POSTED BY: Jiatianfu Qu
Posted 4 years ago

Hello Jiatianfu,

I suspect that you receive the error since there are symbolic arguments in the calculation like l1 , CapitalPhi which prevent to compute an array index. In order to compute the array index all symbolic arguments need to have a numeric assignment. This is how I read the error message (my guess)

POSTED BY: Michael Helmle
Posted 4 years ago

Hi Michael: You mean it is because the length of array Cp is 9000 and since l1 only goes to 2992 there are values that do not have an assignment?

POSTED BY: Jiatianfu Qu
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract