小白求助,有关FOR
mathematica吧
全部回复
仅看楼主
level 1
cjynl 楼主
我想通过FOR一共生成21个向量,但它只生成了i=6时的向量,怎么解决呢?
diameter = 10
ncircle = 36
forceinitial = 20
focallength = 6
zz0[xx_, yy_] := (xx^2 + yy^2)/4 focallength;
n = 5
ld = diameter/(2 n)
For[i = 1, i <= 6, i++,
For[ptmp0 = {}; j = 1, j <= i, j++,
ptmp0 =
Join[ptmp0, {{ld*(Cos[Pi/3]*(i - 6) + 1 - j),
ld*Sin[Pi/3]*(6 - i)}}]
]
]
ptmp0 = Delet[ptmp0, {16}]
2023年02月25日 10点02分 1
吧务
level 15

……你自己看看ptmp0 = {}写哪去了,还有,别用For好吗!:
Flatten[#, 1] &@
Table[{ld (Cos[π/3] (i - 6) + 1 - j), ld Sin[π/3] (6 - i)}, {i, 6}, {j, i}]
(* {{-(5/2), (5 Sqrt[3])/2}, {-2, 2 Sqrt[3]}, {-3, 2 Sqrt[3]}, {-(3/2), (
3 Sqrt[3])/2}, {-(5/2), (3 Sqrt[3])/2}, {-(7/2), (3 Sqrt[3])/2}, {-1, Sqrt[
3]}, {-2, Sqrt[3]}, {-3, Sqrt[3]}, {-4, Sqrt[3]}, {-(1/2), Sqrt[3]/2}, {-(3/2),
Sqrt[3]/2}, {-(5/2), Sqrt[3]/2}, {-(7/2), Sqrt[3]/2}, {-(9/2), Sqrt[3]/2}, {0,
0}, {-1, 0}, {-2, 0}, {-3, 0}, {-4, 0}, {-5, 0}} *)
《别用For循环,它在Mathematica里又慢又不简洁,百害无一利!》
https://tieba.baidu.com/p/5104865347
2023年03月04日 04点03分 2
1