2
$\begingroup$

I am trying to plot f as a function of k (n,k naturals):

f[n_, k_] := NIntegrate[( n)^(2 k)g1[n, k, \[Theta]], {\[Theta], -\[Pi], \[Pi]}]/NIntegrate[g2[n, k, \[Theta]], {\[Theta], -\[Pi], \[Pi]}];

g1[n_, k_, \[Theta]_] := (Sin[(n \[Theta])/2]/Sin[\[Theta]/2])^(
   2 k) (2 Sin[\[Theta]/2])^(2 k);

g2[n_, k_, \[Theta]_] := (Sin[(n \[Theta])/2]/Sin[\[Theta]/2])^(2 k);

n=10;
Plot[f[n, k], {k, 1, 5}]
```
$\endgroup$
1
  • $\begingroup$ Nintegrate in title $\endgroup$
    – Narasimham
    Commented Sep 21, 2022 at 22:12

2 Answers 2

1
$\begingroup$

We can use NumericQ and ReIm to plot this function. Also, it is better to divide f into two parts:

f[n_?NumericQ, k_?NumericQ] := 
  NIntegrate[(n)^(2 k) g1[n, 
     k, \[Theta]], {\[Theta], -\[Pi], \[Pi]}];
f1[n_?NumericQ, k_?NumericQ] := 
  NIntegrate[g2[n, k, \[Theta]], {\[Theta], -\[Pi], \[Pi]}];
g1[n_, k_, \[Theta]_] := (Sin[(n \[Theta])/2]/
      Sin[\[Theta]/2])^(2 k) (2 Sin[\[Theta]/2])^(2 k);

g2[n_, k_, \[Theta]_] := (Sin[(n \[Theta])/2]/Sin[\[Theta]/2])^(2 k);

n = 10;

Plot[Evaluate[ReIm[f[n, k]/f1[n, k]]], {k, 1, 2}, Frame -> True]

Figure 1

$\endgroup$
2
  • $\begingroup$ Hey, @Alex Trounev! thank you for your response clue, but why it is appearing two graphs? $\endgroup$
    – V Bert
    Commented Sep 21, 2022 at 22:00
  • $\begingroup$ This is complex function, blue is real part, orang is Im part. $\endgroup$ Commented Sep 22, 2022 at 2:24
1
$\begingroup$
$Version

(* "13.1.0 for Mac OS X x86 (64-bit) (June 16, 2022)" *)

Clear["Global`*"]

g1[n_, k_, θ_] := (Sin[(n θ)/2]/
      Sin[θ/2])^(2 k) (2 Sin[θ/2])^(2 k);

g2[n_, k_, θ_] := (Sin[(n θ)/2]/Sin[θ/2])^(2 k);

The natural numbers is an ambiguous constraint, it can mean either positive or nonnegative integers. I have defined f for n positive and k nonnegative.

f[n_Integer?Positive, k_Integer?NonNegative] :=
  NIntegrate[(n)^(2 k) g1[n, k, θ], {θ, -π, π}]/
   NIntegrate[g2[n, k, θ], {θ, -π, π}];

Manipulate[
 DiscretePlot[f[n, k], {k, 0, 4},
  AxesLabel -> {k, f},
  PlotRange -> All],
 {{n, 5}, Range[5]}]

enter image description here

$\endgroup$
1
  • $\begingroup$ thank you @Bob Hanlon very much for you help! $\endgroup$
    – V Bert
    Commented Sep 22, 2022 at 14:08

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.