| 查看: 3769 | 回复: 27 | |||
| 当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖 | |||
[求助]
Mathematica里的compile怎么使用已有1人参与
|
|||
| 请教一下各位:Mathematica里的compile怎么使用?我现在的程序里需要一个大的循环数组,计算的时间太长,想提高一下计算速度。 |
» 收录本帖的淘帖专辑推荐
软件 |
» 猜你喜欢
孩子确诊有中度注意力缺陷
已经有12人回复
2025冷门绝学什么时候出结果
已经有3人回复
天津工业大学郑柳春团队欢迎化学化工、高分子化学或有机合成方向的博士生和硕士生加入
已经有4人回复
康复大学泰山学者周祺惠团队招收博士研究生
已经有6人回复
AI论文写作工具:是科研加速器还是学术作弊器?
已经有3人回复
2026博士申请-功能高分子,水凝胶方向
已经有6人回复
论文投稿,期刊推荐
已经有4人回复
硕士和导师闹得不愉快
已经有13人回复
请问2026国家基金面上项目会启动申2停1吗
已经有5人回复
同一篇文章,用不同账号投稿对编辑决定是否送审有没有影响?
已经有3人回复
» 本主题相关价值贴推荐,对您同样有帮助:
QE安装出错,求助大神
已经有6人回复
mathematica 10.0 百度云分享链接
已经有17人回复
请教mathematica中求解问题
已经有8人回复
一个很不错的mathematica教程
已经有507人回复
Mathematica问题求助
已经有7人回复
有没有origin使用高手?
已经有3人回复
请教LSDA+U计算的问题
已经有24人回复
谁来帮我一下好不好?mathematica 方程组输入一直错误,不知道怎么办
已经有3人回复
Mathematica迭代运算的终止条件怎么加进去
已经有7人回复
【原创】在WORD中使用Mathematica画的图形的体会
已经有13人回复
6楼2013-06-07 19:49:43
mshwangg
至尊木虫 (正式写手)
- 程序强帖: 5
- 应助: 206 (大学生)
- 金币: 10702.8
- 散金: 100
- 红花: 19
- 帖子: 597
- 在线: 195.4小时
- 虫号: 576702
- 注册: 2008-06-21
- 专业: 物理学I
【答案】应助回帖
★
感谢参与,应助指数 +1
zdzqy: 金币+1, ★★★很有帮助 2013-08-07 10:40:49
感谢参与,应助指数 +1
zdzqy: 金币+1, ★★★很有帮助 2013-08-07 10:40:49
|
Mathematica帮助文件里关于Compile有这样两段话: If you make a definition like f[x_]:=x Sin[x], Mathematica will store the expression x Sin[x] in a form that can be evaluated for any x. Then when you give a particular value for x, Mathematica substitutes this value into x Sin[x], and evaluates the result. The internal code that Mathematica uses to perform this evaluation is set up to work equally well whether the value you give for x is a number, a list, an algebraic object, or any other kind of expression. Having to take account of all these possibilities inevitably makes the evaluation process slower. However, if Mathematica could assume that x will be a machine number, then it could avoid many steps, and potentially evaluate an expression like x Sin[x] much more quickly. 看明白了吧?Mathematica处理一个变量的时候要考虑很多种可能的情况,比如说这个变量是实数、复数、数组还是代数符号等等,所以处理起来比较慢。而用Compile不过是设定使用的变量是具体的那种数据类型,计算起来当然要快一些。 实际上,个人认为Compile的功能有点鸡肋,它不生成可执行文件,也不可以脱离Mathematica环境运行程序。如果在程序中每个变量在使用之前赋值并且所有可能的函数都做数值运算,比如NSolve,NIntegrate,那么Compile与否其实差别不大,不会为你节省多少时间。 Complie的使用方法参考:在Mathematica里键入“Compile”,全选,按键盘上的“F1”! 虽然等于没说,但是比说了还详细。 |
2楼2013-06-04 09:39:06
walk1997
金虫 (著名写手)
- 应助: 1 (幼儿园)
- 金币: 4676.2
- 红花: 22
- 帖子: 1066
- 在线: 798.1小时
- 虫号: 416039
- 注册: 2007-06-29
- 性别: GG
- 专业: 粒子物理学和场论
|
1. 安装好C 2. 直接调用complile。 对于复杂函数的计算的 还是有比较明显速度的提高的 不过编译成C和VM的 看起来差别不是很大 也许非常复杂的表达式会有差别 另外 如果是表达式非常复杂的话 最好相优化下表达式 an example to show the difference Clear["Globale`*"]; f[x_Real] := x^2 + 1; c1 = Compile[ {{x, _Real}}, x^2 + 1, CompilationTarget -> "C"]; c2 = Compile[ {{x, _Real}}, x^2 + 1]; Do[c1, {i, 1.0, 10.0^6, 1.0}] // Timing Do[c2, {i, 1.0, 10.0^6, 1.0}] // Timing Do[f, {i, 1.0, 10.0^6, 1.0}] // Timing Do[c1, {i, 1, 10^6, 1}] // Timing Do[c2, {i, 1, 10^6, 1}] // Timing Do[f, {i, 1, 10^6, 1}] // Timing |
3楼2013-06-06 08:23:10
walk1997
金虫 (著名写手)
- 应助: 1 (幼儿园)
- 金币: 4676.2
- 红花: 22
- 帖子: 1066
- 在线: 798.1小时
- 虫号: 416039
- 注册: 2007-06-29
- 性别: GG
- 专业: 粒子物理学和场论
4楼2013-06-06 08:24:22













回复此楼