这个软件一直装在电脑上,不过很少用。
本来在很久之前就该学会的东西,不知道为什么现在还没入门。学渣的悲哀。
前几天找了一本书看,效果不是很好。于是现在直接看代码,边看边学。
官方的帮助:
http://reference.wolfram.com/mathematica/guide/Mathematica.html
另一个不错的自学资源:
http://zh.wikibooks.org/wiki/Mathematica
0.mathematics中主要一种叫做列表的东西,就像这样
{{1,2,3},{4,5},{6},{7,8,9}}
0.1上一个输出
%
0.2函数定义与调用使用方括号
[]
0.3输出
Print[]
0.4帮助,?+想要知道的东西
?#
# 表示提供给一个纯函数的第一个参数.
# n 表示第 n 个参数.
0.5注释
(*我是注释*)
1.函数定义
f[x_]:=Module[{局部变量},表达式]
2.载入package
<<package_name`
3.函数说明
function_name::usage = ""
4.列表
Range[8]
{1,2,3,4,5,6,7,8}
Range[1,8]
{1,2,3,4,5,6,7,8}
ConstantArray[0,8]
{0,0,0,0,0,0,0,0}
Table[x,{x,8}]
{1,2,3,4,5,6,7,8}
Range[36][[1 ;; 35 ;; 2]]
{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35}
Flatten[{1,2,3},{4,5}]
{1,2,3,4,5}
Flatten[{{{1, 2}, {3}}, {{4}, {5}, {6}}},1]
{{1, 2}, {3}, {4}, {5}, {6}}
5.函数作用于列表中的每一个元素
function /@{x,y,z}
6.函数条件
multSequence[x__]:= Module[{},Fold[cornMult,cId,{x}]]/;(Count[{x}[[1,2]],_Integer]==8)
multSequence[x__]:= Module[{},Fold[edgeMult,eId,{x}]]/;(Count[{x}[[1,2]],_Integer]==12)
7.可变参数
fun[x_, y__] := x + y
fun[1,2]
3
fun[1,2,3,4,5]
15
8.默认参数
g[x_, y_: 1] := x + sin[y]
g[1,2]
1+sin[2]
g[1]
1+sin[1]
9.匿名函数,纯函数
(#1-#2)&[a,b]
a-b
10.绘制二维曲线,离散点,离散点连线
Plot[Sin[x], {x, -1, 1}]
f[x_] := Sin[x]
Plot[f[x], {x, 0, 1}]
points = Table[{i, (-1)^i}, {i, 0, 10}]
ListPlot[points]
ListLinePlot[points]
ListLinePlot[points, InterpolationOrder -> 3](*用三次样条插值函数连接*)
ListLinePlot[points, InterpolationOrder -> 3, Frame -> True](*显示边框*)
ListLinePlot[points, Mesh -> Full, MeshStyle -> Directive[PointSize[Medium],Red]](*对点加重绘制, Mesh->Full 时, 后面设置的MeshStyle才有效*)
ListLinePlot[points, Axes -> False](*去掉坐标轴*)
ListLinePlot[points, GridLines -> Automatic](*加入坐标网格线*)
ListLinePlot[points, Background -> LightBlue]
Plot[Sin[x], {x, -1, 1}, AxesLabel -> {"x", "sin(x)"}]
11.曲线在一个坐标中绘制
Show[pic]
Show[pic, 选项名 -> 选项值]
Show[pic1,pic2,...,picn]
12.曲线拟合
points = {{1, 2}, {2, 4}, {3, 6}, {4, 8}}
Fit[points, {1, x, x^2}, x]
13.积分
Integrate[x ^n * Exp[-x^2], x]
Integrate[x ^n * Exp[-x^2], {x, 0, Infinity}]
Integrate[x ^4 * Exp[-x^2], {x, -Infinity, Infinity}]
================================================================================================
其他一些事情:
1.负数开根号
2.隐函数作图用ContourPlot,不知道有没有更好的方法
ContourPlot3D[{Abs[x - y] == 1, Abs[x + y] == 1, y^2 + z^2 == 1}, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}]
3.含参数的函数作图ParametricPlot
ParametricPlot[{t - Sin[t], 1 - Cos[t]}, {t, -Pi, Pi}]
4.跑分
<< Benchmarking`
BenchmarkReport[]