-5
$\begingroup$

Thank you so much for the helpful comments. Now able to manage to plot all the functions.

Remove[q, qC, IIC]

ass = {d > 1, num > 0, \[CapitalDelta] > 0, t > 0, n >= 0};

q[\[Nu]_, num_, \[CapitalDelta]_, t_] := 
 1/num (1 + 
    2 Exp[-\[Nu]] NSum[
      Sin[(\[Pi] d)/num]/((\[Pi] d)/num) Exp[-d \[CapitalDelta]^2] 
       Cos[(\[Pi] d)/num (2 t + 1)] \[Nu]^(n + d/2)/Sqrt[
       n! (n + d)!], {d, 1, 10}, {n, 0, 10}])

AbsoluteTiming[Table[q[2, 4, 0.2, t], {t, 0, 200, 20}]]

Plot[q[2.0, 4.0, 0.2, t], {t, 0, 200}]

qC[\[Nu]_, num_, \[CapitalDelta]_, t_] := 
  1/num (1 + 
     2 Exp[-\[Nu]] Sum[
       Sin[(\[Pi] d)/num]/((\[Pi] d)/num) Exp[-d \[CapitalDelta]^2] 
        Cos[(\[Pi] d)/num (2 t + 1)] \[Nu]^(n + d/2)/Sqrt[
        n! (n + d)!], {d, 1, 20}, {n, 0, 20}]);

AbsoluteTiming[Table[qC[2., 4., 0.2, t], {t, 0, 200, 10}]]

ListPlot[Table[{t, qC[2, 4, 0.2, t]}, {t, 0, 200}]]

IIC[\[Nu]_, num_, \[CapitalDelta]_] := 

Log[2, num] - Sum[(q[[Nu], num, [CapitalDelta], t]) Log[2, q[[Nu], num, [CapitalDelta], t]], {t, 0, num - 1}]; AbsoluteTiming[Table[IIC[[Nu], 4, 0.2], {[Nu], 1, 200, 20}]] ListPlot[Table[{[Nu], IIC[[Nu], 4, 0.2]}, {[Nu], 1, 50}], PlotRange -> All, AxesOrigin -> {0, 0}]

$\endgroup$
2
  • 4
    $\begingroup$ I and N are built-in symbols, so don't use as custom function or variable names. Please try to come up with a minimal (as short as possible) test case that demonstrates the problem you are having, and describe the problem and the question in detail. If you simply post a large body of code, saying that it doesn't work, but not explaining what you're trying to do and what went wrong, then it's unlikely people will help. $\endgroup$
    – Szabolcs
    Mar 26, 2013 at 16:29
  • $\begingroup$ Thank you Verbeia for the editing!!! $\endgroup$
    – user0322
    Apr 2, 2013 at 12:02

1 Answer 1

2
$\begingroup$

The first plot just works fine, although it takes a long time.

Plot[q[2.0, 4.0, 0.2, t], {t, 0, 200}]

Mathematica graphics

The table contains the same values, because you sample the periodic function periodically.

The data of the second plot is sampled badly. You should increase the frequency:

ListPlot[Table[{t, qC[2, 4, 0.2, t]}, {t, 0, 20, .1}]]

Mathematica graphics

The last plot doesn't work because your function IIC has t both in its argument list as well as in the iterator of the Sum.

$\endgroup$
3
  • $\begingroup$ thank you so much Sjoered C. de Vries. I correcetd my silly mistake and managed to plot the function IIC. $\endgroup$
    – user0322
    Apr 3, 2013 at 8:56
  • $\begingroup$ IIC[[Nu]_, num_, [CapitalDelta]_] := Log[2, num] - Sum[(q[[Nu], num, [CapitalDelta], t]) Log[2, q[[Nu], num, [CapitalDelta], t]], {t, 0, num - 1}]; AbsoluteTiming[Table[IIC[[Nu], 4, 0.2], {[Nu], 1, 200, 20}]] ListPlot[Table[{[Nu], IIC[[Nu], 100, 0.2]}, {[Nu], 1, 100}], PlotRange -> All, AxesOrigin -> {0, 0}] $\endgroup$
    – user0322
    Apr 3, 2013 at 9:27
  • $\begingroup$ @ Sjoerd C. de Vries-in the expression q[[Nu]_, num_, [CapitalDelta]_, t_] the summations over d & d by 10 simply to see if their is any way to get it to work, if it goes to infinity,that is very slow to complete, is there any way to converge? $\endgroup$
    – user0322
    Apr 5, 2013 at 14:36

Your Answer

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

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