gpt4 book ai didi

wolfram-mathematica - 如何在mathematica中模拟以下场景

转载 作者:行者123 更新时间:2023-12-04 08:16:26 25 4
gpt4 key购买 nike

假设我有 n=6 个不同的单体,每个单体都有两个不同的 react 端。在每一轮 react 中,一个随机末端与另一个随机末端结合,将单体延长为二聚体或自缔合成环。只要系统中不存在自由端,该 react 过程就会停止。我想用Mma来模拟 react 过程。

我想将单体表示为字符串列表,{'1-2', '3-4', '5-6', '7-8', '9-10', '11- 12'},然后通过更新列表的内容来进行一轮 react ,例如 {'1-2-1', '3-4', '5-6', '7-8', ' 9-10'、'11-12'} 或 {'1-2-3-4'、'5-6'、'7-8'、'9-10'、'11-12'}。但由于我在 Mma 中的编程限制,我不能走得太远。有人可以帮忙吗?非常感谢。

最佳答案

这是设置:

Clear[freeVertices];
freeVertices[edgeList_List] := Select[Tally[Flatten[edgeList]], #[[2]] < 2 &][[All, 1]];

ClearAll[setNew, componentsBFLS];
setNew[x_, x_] := Null;
setNew[lhs_, rhs_] := lhs := Function[Null, (#1 := #0[##]); #2, HoldFirst][lhs, rhs];

componentsBFLS[lst_List] :=
Module[{f}, setNew @@@ Map[f, lst, {2}]; GatherBy[Tally[Flatten@lst][[All, 1]], f]];

这里是开始:

In[13]:= start = Partition[Range[12], 2]

Out[13]= {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}, {11, 12}}

步骤如下:

In[51]:= steps = 
NestWhileList[Append[#, RandomSample[freeVertices[#], 2]] &,
start, freeVertices[#] =!= {} &]

Out[51]= {{{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}, {11, 12}}, {{1,
2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}, {11, 12}, {5, 1}}, {{1,
2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}, {11, 12}, {5, 1}, {3,
4}}, {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}, {11, 12}, {5,
1}, {3, 4}, {7, 11}}, {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9,
10}, {11, 12}, {5, 1}, {3, 4}, {7, 11}, {8, 2}}, {{1, 2}, {3,
4}, {5, 6}, {7, 8}, {9, 10}, {11, 12}, {5, 1}, {3, 4}, {7, 11}, {8,
2}, {6, 10}}, {{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}, {11,
12}, {5, 1}, {3, 4}, {7, 11}, {8, 2}, {6, 10}, {9, 12}}}

以下是您可以研究的连通分量(循环等):

In[52]:= componentsBFLS /@ steps

Out[52]= {{{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}, {11, 12}}, {{1, 2,
5, 6}, {3, 4}, {7, 8}, {9, 10}, {11, 12}}, {{1, 2, 5, 6}, {3,
4}, {7, 8}, {9, 10}, {11, 12}}, {{1, 2, 5, 6}, {3, 4}, {7, 8, 11,
12}, {9, 10}}, {{1, 2, 5, 6, 7, 8, 11, 12}, {3, 4}, {9, 10}}, {{1,
2, 5, 6, 7, 8, 9, 10, 11, 12}, {3, 4}}, {{1, 2, 5, 6, 7, 8, 9, 10,
11, 12}, {3, 4}}}

发生的情况是,我们将所有对视为一个大图中的边,如果此时两个顶点至多与其他边有一条连接,则随机添加一条边。在某个时候,该过程停止。然后,我们将 componentsBFLS 函数映射到结果图(表示模拟的步骤)上,以获得图(步骤)的连接组件。当然,您也可以使用其他指标,并编写更多函数来分析循环等步骤。希望这能让您入门。

关于wolfram-mathematica - 如何在mathematica中模拟以下场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5226257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com