Skip to main content
use Array[r,n] instead of ToString... to produce symbols
Source Link
flinty
  • 25.9k
  • 2
  • 22
  • 92

The integration limits can't be Row and there were some syntax issues I cleaned up. Hopefully the comments (* ... *) below explain everything. You can change the $x,R,n$ in the With to different values if needed:

(* Function to create the symbols r[1],r[2],...,r[n] *)
LoC[n_] := Symbol["r" <> ToString@#] & /@ Range[n]Array[r,n]

(* Functions to integrate *)
f[x_] := x
g[l_] := Sum[f[i], {i, l}]

(* Function to generate an interval for integration *)
iv[variable_, x_, R_] := {variable, x, R}

(* Given x,R,n - integrate g[LoC[n]]. *)
With[{x = 1, R = 100, n = 3},
 NIntegrate[g[LoC[n]],
  (* generate intervals and splice into arguments here with Sequence *)
  Evaluate[Sequence @@ (iv[#, x, R] & /@ LoC[n])]
  ]
 ]

The integration limits can't be Row and there were some syntax issues I cleaned up. Hopefully the comments (* ... *) below explain everything. You can change the $x,R,n$ in the With to different values if needed:

(* Function to create the symbols *)
LoC[n_] := Symbol["r" <> ToString@#] & /@ Range[n]

(* Functions to integrate *)
f[x_] := x
g[l_] := Sum[f[i], {i, l}]

(* Function to generate an interval for integration *)
iv[variable_, x_, R_] := {variable, x, R}

(* Given x,R,n - integrate g[LoC[n]]. *)
With[{x = 1, R = 100, n = 3},
 NIntegrate[g[LoC[n]],
  (* generate intervals and splice into arguments here with Sequence *)
  Evaluate[Sequence @@ (iv[#, x, R] & /@ LoC[n])]
  ]
 ]

The integration limits can't be Row and there were some syntax issues I cleaned up. Hopefully the comments (* ... *) below explain everything. You can change the $x,R,n$ in the With to different values if needed:

(* Function to create the symbols r[1],r[2],...,r[n] *)
LoC[n_] := Array[r,n]

(* Functions to integrate *)
f[x_] := x
g[l_] := Sum[f[i], {i, l}]

(* Function to generate an interval for integration *)
iv[variable_, x_, R_] := {variable, x, R}

(* Given x,R,n - integrate g[LoC[n]]. *)
With[{x = 1, R = 100, n = 3},
 NIntegrate[g[LoC[n]],
  (* generate intervals and splice into arguments here with Sequence *)
  Evaluate[Sequence @@ (iv[#, x, R] & /@ LoC[n])]
  ]
 ]
Source Link
flinty
  • 25.9k
  • 2
  • 22
  • 92

The integration limits can't be Row and there were some syntax issues I cleaned up. Hopefully the comments (* ... *) below explain everything. You can change the $x,R,n$ in the With to different values if needed:

(* Function to create the symbols *)
LoC[n_] := Symbol["r" <> ToString@#] & /@ Range[n]

(* Functions to integrate *)
f[x_] := x
g[l_] := Sum[f[i], {i, l}]

(* Function to generate an interval for integration *)
iv[variable_, x_, R_] := {variable, x, R}

(* Given x,R,n - integrate g[LoC[n]]. *)
With[{x = 1, R = 100, n = 3},
 NIntegrate[g[LoC[n]],
  (* generate intervals and splice into arguments here with Sequence *)
  Evaluate[Sequence @@ (iv[#, x, R] & /@ LoC[n])]
  ]
 ]