从这一篇开始,我可能会换一种方式来讲,因为我发现现在在mathematica的官方网站上已经有中文版的入门指南了,所以在这里我就不需要翻译了。
但是既然开了这个系列,那我还是想要把这个系列更新完毕的,所以我决定后面的文章会稍微调整一下,还是按照官方教程的每个主题来讲,只不过我会加一些我在使用过程中觉得比较重要的东西,并且,会加多一点关于mathematica与python这两个语言的比较。那么下面就开始这一篇的内容,关于函数的定义。
函数定义
在 Wolfram 语言中,申明函数时参数名称后紧随下划线. 如果您在 Wolfram 语言中省略下划线,函数将按原文处理。我们看下面的例子
![Mathematica入门[9]–Function Definitions(函数定义)](https://img.mathpretty.com/snipaste_20180101_224752.png?imageView2/0/q/75|watermark/2/text/5YWz5rOo5YWs5LyX5Y-377ya5paH6Im65pWw5a2m5ZCb/font/5b6u6L2v6ZuF6buR/fontsize/540/fill/IzAwMDAwMA==/dissolve/100/gravity/SouthEast/dx/10/dy/10|imageslim)
并且在函数中,我们是可以按指定其值
![Mathematica入门[9]–Function Definitions(函数定义)](https://img.mathpretty.com/snipaste_20180101_225013.png?imageView2/0/q/75|watermark/2/text/5YWz5rOo5YWs5LyX5Y-377ya5paH6Im65pWw5a2m5ZCb/font/5b6u6L2v6ZuF6buR/fontsize/540/fill/IzAwMDAwMA==/dissolve/100/gravity/SouthEast/dx/10/dy/10|imageslim)
所以,我们可以这样来定义分段函数
![Mathematica入门[9]–Function Definitions(函数定义)](https://img.mathpretty.com/snipaste_20180101_225032.png?imageView2/0/q/75|watermark/2/text/5YWz5rOo5YWs5LyX5Y-377ya5paH6Im65pWw5a2m5ZCb/font/5b6u6L2v6ZuF6buR/fontsize/540/fill/IzAwMDAwMA==/dissolve/100/gravity/SouthEast/dx/10/dy/10|imageslim)
在python中,我们是使用def来定义函数的
def f(x,y):
return x+y
![Mathematica入门[9]–Function Definitions(函数定义)](https://img.mathpretty.com/snipaste_20180101_225508.png)
下面我们来看一下python中分段函数是如何定义的
def f(x):
if x>=0:
return x
else:
return -x
![Mathematica入门[9]–Function Definitions(函数定义)](https://img.mathpretty.com/snipaste_20180101_225721.png)
其实就是使用if语句来完成的。
- 微信公众号
- 关注微信公众号
-
- QQ群
- 我们的QQ群号
-


![Mathematica入门[13]–Associations(关联)](https://img.mathpretty.com/20210911_162105_q285v1d.jpg)
![Mathematica入门[12]–Options(选项)](https://img.mathpretty.com/20210911_162056_tt49p1t.jpg)
![Mathematica入门[11]–Applying Functions(函数应用)](https://img.mathpretty.com/20210911_162114_futklns.jpg)
![Mathematica入门[10]–Pure Functions(纯函数)](https://img.mathpretty.com/20210911_162011_tcryqxk.jpg)
![Mathematica入门[8]–Patterns(模式)](https://img.mathpretty.com/20210911_162025_0gwx5df.jpg)
![Mathematica入门[7]--Assignments(赋值)](https://img.mathpretty.com/20210911_162124_pk73t7w.jpg)
![Mathematica入门[6]--Iterators(迭代器)](https://img.mathpretty.com/20210911_162111_41geeb4.jpg)
![Mathematica入门[4]--Symbolic Expressions(符号表达式)](https://img.mathpretty.com/20210911_162028_ouho1s3.jpg)

评论