0
$\begingroup$

I want to create a ListDensityPlot of T vs k, and to do so I am not able to achieve an appropriate Array output from my code. The code is

eq[\[Alpha]_, k_, T_] := \[Alpha]*Sin[k + \[Alpha]] == T*Cos[k];
sol[T_?NumericQ,k_ /; 0 <= k <= Pi/2] := \[Alpha] /.NSolve[{eq[\[Alpha],k,T], 0 <= \[Alpha] <= Pi/2}, \[Alpha], 
 Reals] /. \[Alpha] -> {};

Table[With[{v = -2.5, \[Alpha] = 1}, 
Block[{w = -2 Cos[k], \[Delta] = v - w + (T*Sin[k]^2)/(Sin[2*k + sol[T,k]]^2 + T*Sin[k]^2), \[Rho] = 
 v - w + (\[Alpha]*T*Abs[\[Delta] - E^(I*k)]^2)/(
  1 + T*Abs[\[Delta] - E^(I*k)]^2) }, Abs[(E^(I k) - 
   E^(-I k))/(1 + (\[Rho] - E^(I k)) (E^(
      I k) - \[Delta]))]^2]], {T, 0.1, 0.3, 0.1}, {k, 0.1, 0.3, 0.1}]

I am however able to make a ListLinePlot by using Flatten@Table[...]. The output I get is something like {{{a},{b},{c}},{{d},{e},{f}},{{g},{h},{i}}} which should instead be like {{a,b,c},{d,e,f},{g,h,i}}? for making a ListDensityPlot for T vs k.

$\endgroup$
1
$\begingroup$

Table works by returning lists of lists of outputs. You can use this inelegant approach to fix the format:

Do[t[[i]] = t[[i]] // Flatten, {i, 3}]

I think if you understand head (3rd argument of Flatten) you might be able to skip the loop.

You should try giving more minimal examples, eg. by using Table[foo[args], ...]. The numbers obfuscate your code.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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