小编Car*_*los的帖子

模拟长度函数以获取列表的长度

我正在尝试在Mathematica v.8中模拟Length函数来获取列表的长度.鉴于这一事实:

  • 空列表表示为{}
  • l = Rest [l]为没有第一个元素的列表l分配l(这是一个列表)
  • 一个while循环

这是我使用mathematica的第一年,我对此并不太擅长,所以我正在做的事情可能有些事情(或者一切都有问题):

Ej1[l_List] := Module[{i, v},
v = {{}};
i = 1;
While[l != v, l = Rest[l]; i++]
Return[i]
]
Run Code Online (Sandbox Code Playgroud)

L = {A,B,C,d,E};

当我尝试运行它时,循环永远不会结束,它会给我这个警告:

Set::shape: Lists {a,b,c,d,e} and {b,c,d,e} are not the same shape. >>

Set::shape: Lists {a,b,c,d,e} and {b,c,d,e} are not the same shape. >>

Set::shape: Lists {a,b,c,d,e} and {b,c,d,e} are not the same shape. >>

General::stop: Further output of Set::shape will be suppressed during this calculation. >>
Run Code Online (Sandbox Code Playgroud)

wolfram-mathematica function list

5
推荐指数
2
解决办法
256
查看次数

标签 统计

function ×1

list ×1

wolfram-mathematica ×1