Mathematica不保存变量 [英] Mathematica Not Saving Variable

查看:180
本文介绍了Mathematica不保存变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试执行此嵌套循环,但无法正常工作.并不是在每个阶段都保存结果.但是,如果我用Print []替换listInitial,我观察到所有更改都已完成.

I try to perform this nested loop but it is not working. It's not saving the result in each stage. But if I replace listInitial with Print[ ] I observer that all changes are made.

有什么建议吗?

For[b = 1, b < 4, b = b + 1,
 For[a = 1, a < 4, a = a + 1,
  For[x = 1, x < 4, x = x + 1,
   For[z = 1, z < 4, z = z + 1, listInitial = 
    If[Random[] > psurvival, 
      ReplacePart[
       InitialMatrix[3, 3, 3, 3], {b, a, x, z} -> 
        InitialMatrix[3, 3, 3, 3][[b]][[a]][[x]][[z]] - 1], 
      InitialMatrix[3, 3, 3, 3], {b, a, x, z} -> 
       InitialMatrix[3, 3, 3, 3][[b]][[a]][[x]][[z]]]]]]]

listInitial // TableForm

推荐答案

谢谢大家.我找到了这个解决方案: 我认为这比较容易,而且可以正常工作.

Thanks guys. I found this solution: I think it's the easier one and it's working.

SetAttributes[myFunction, Listable]
myFunction[x_] := 
 If[Random[] > psurvival, If [x - 1 < 0 , x , x - 1], x]
 myFunction[InitialMatrix[3, 3, 3, 3]] // TableForm

这篇关于Mathematica不保存变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆