Mathematica
关于mathematica这个软件,有时候会用到它,虽然懂一点,但是基础不好,问Chat也是不懂,准备系统的学习一下,在这里记录一下!
近来状况
最近这半年在接触Github和cloudflare,学习了搭建博客、科学上网、ChatGPT以及搞了一些VPS,俗话说:工欲善其事,必先利其器!最近,会把一部分的时间学习mathematic这个软件,当然,Github上也会利用chat写一些代码,毕竟技多不压身!OK,先定计划!
图床不管用了,暂时不折腾了
快速入门
1. 基本算术运算
1 2 3 4 5 6 7 8 9
| 3 + 5
7 - 2
4 * 6
10 / 2
2^3
|
2. 符号计算
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| Simplify[Sin[x]^2 + Cos[x]^2]
Expand[(x + 1)^2]
Factor[x^2 - 2 x - 3]
Solve[x^2 - 4 == 0, x]
DSolve[y'[x] == y[x], y[x], x]
|
3. 矩阵运算
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| Det[{{1, 2}, {3, 4}}]
Inverse[{{1, 2}, {3, 4}}]
Transpose[{{1, 2}, {3, 4}}]
Eigenvalues[{{1, 2}, {3, 4}}]
Eigenvectors[{{1, 2}, {3, 4}}]
|
4. 微积分运算
1 2 3 4 5 6 7 8 9 10 11
| D[x^2 + 3 x + 1, x]
Integrate[x^2, x]
Integrate[x^2, {x, 0, 1}]
Limit[Sin[x]/x, x -> 0]
|
5. 数值计算
1 2 3 4 5 6 7 8 9 10 11
| N[Pi]
FindRoot[Cos[x] - x == 0, {x, 0}]
NSolve[x^3 - x == 0, x]
NIntegrate[Exp[-x^2], {x, 0, 1}]
|
6. 绘图与可视化
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| Plot[Sin[x], {x, 0, 2 Pi}]
Plot3D[Sin[x] Sin[y], {x, 0, Pi}, {y, 0, Pi}]
ListPlot[{{1, 2}, {2, 3}, {3, 5}, {4, 7}}]
ContourPlot[Sin[x] Sin[y], {x, 0, 2 Pi}, {y, 0, 2 Pi}]
ParametricPlot[{Cos[t], Sin[t]}, {t, 0, 2 Pi}]
|
7. 列表与数组
1 2 3 4 5 6 7 8 9 10 11
| Table[i^2, {i, 1, 5}]
Range[1, 5]
Map[Sin, {0, Pi/2, Pi}]
Apply[Plus, {1, 2, 3}]
|
8. 逻辑与条件运算
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| If[x > 0, "Positive", "Non-positive"]
Which[x < 0, "Negative", x == 0, "Zero", x > 0, "Positive"]
And[True, False]
Or[True, False]
Equal[2 + 2, 4]
|
9. 程序结构与控制
1 2 3 4 5 6 7 8 9 10 11
| Module[{x = 3}, x^2]
Do[Print[i], {i, 1, 5}]
For[i = 1, i <= 5, i++, Print[i]]
While[x < 10, x *= 2; Print[x]]
|
10. 文件与输入输出
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| Export["data.csv", {{1, 2}, {3, 4}}]
Import["data.csv"]
Print["Hello, World!"]
InputString["Enter your name: "]
OpenWrite["output.txt"]
|
11. 随机数与统计
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| RandomReal[{0, 1}]
RandomInteger[{1, 6}]
Mean[{1, 2, 3, 4, 5}]
Variance[{1, 2, 3, 4, 5}]
StandardDeviation[{1, 2, 3, 4, 5}]
|
12. 字符串处理
1 2 3 4 5 6 7 8 9 10 11
| StringJoin["Hello", " ", "World"]
StringLength["Mathematica"]
StringTake["Hello, World!", 5]
StringReplace["Hello, World!", "World" -> "Mathematica"]
|
13. 函数定义与操作
1 2 3 4 5 6 7 8 9 10 11
| f[x_] := x^2
f[3]
Map[f, {1, 2, 3}]
Function[x, x^2][5]
|