n = 2;
yv[i_] := Range[1/n, 1, 1/n];
yv[n]
yc[j_] := Which[
0 <= i <= 1, 0,
1 < i <= n, 1/2 (yv[n][[i]] + yv[n][[i - 1]])];
Table[yc[j], {i, 1, n}]
test1 = Table[
N[1/(2 \[Pi]) (yv[i]/(yv[i]^2 - yc[j]^2))], {i, 1, n}, {j, 1, n}]
test2 = Table[N[1/(2 \[Pi]) (yv[i]/(yv[i]^2 - yc[j]^2))], {i, 1, n}]
Outputs:
{1/2, 1}
{0, 3/4}
{{{0.31831, 0.159155}, {0.31831, 0.159155}}, {{-0.254648,
0.363783}, {-0.254648, 0.363783}}}{{0.31831, 0.159155}, {-0.254648, 0.363783}}
I'm an undergraduate aerospace engineer learning Mathematica and trying to program Prandtl's numerical lifting line theory. I'm having trouble trying to understand Mathematica's interation process and how it creates lists (in this case, why I get a list of lists of lists vs. a list of lists). I'm doing some iterations (observe the "test" functions) with an equation that depends on two variables: variable yv that depends on i, and variable yc that depends on j. Both of my yv and yc functions are producing the correct answers that I need (sorry if the code for them looks ugly; it's a learning process). Test2 produces the correct output that I need: a square n x n matrix that matches my hand-calculations. Bluntly speaking, why does test1 create a weird looking list? If I need to do an iteration of both i and j from 1 to n, it visually seems like that code should produce an answer that matches test2. Is there a way to make test1 match test2's answer? Also, why does my code for test2 even work when I'm only iterating i, not j, from 1 to n (how does yc get its values)?
I'd appreciate any tips, as well as any resources to better understand the iteration process/linear algebra in Mathematica (my code will require me to use a lot of iterations and linear algebra, so I better learn from my mistakes and prevent this in my future codes. As a side note, I'm also trying to also switch from Matlab to Mathematica in my CFD class so I'll need to really understand Mathematica's numerical computation process).
TL;DR: My test2 output is exactly what I need, but how did Mathematica compute yc without steps for j?
Thank you.