Mathematica 入门笔记

这个软件一直装在电脑上,不过很少用。

本来在很久之前就该学会的东西,不知道为什么现在还没入门。学渣的悲哀。

前几天找了一本书看,效果不是很好。于是现在直接看代码,边看边学。

官方的帮助:

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[]


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值