昨天画1/4 椭圆在各方格点内地面积时想起
Mathematica。试了一下,果然强大!
效果图:
不由得去找了 Wolfram 的简历来看看,牛人啊!
- {a, b} = {40, 10};
- anti[y_] := a/b Sqrt[b^2 - y^2]
- ellipse[s_,
- t_] := (a b)/2 (ArcSin[t/a] - ArcSin[s/a]) + (a b)/
- 4 (Sin[2 ArcSin[t/a]] -
- Sin[2 ArcSin[s/
- a]])(*the integration of a quarter ellipse from s to t.*)
- data = Table[
- Which[x^2/a^2 + y^2/b^2 < 1 && (x + 1)^2/a^2 + (y + 1)^2/b^2 > 1,
- ellipse[Max[x, anti[y + 1]], Min[x + 1, anti[y]]] -
- y (Min[x + 1, anti[y]] - Max[x, anti[y + 1]]) + (Max[x,
- anti[y + 1]] - x), (x + 1)^2/a^2 + (y + 1)^2/b^2 < 1, 1,
- x^2/a^2 + y^2/b^2 > 1, 0], {x, 0, a}, {y, 0, b}];
- ListPlot3D[data, Mesh -> None, InterpolationOrder -> 0,
- ColorFunction -> "SouthwestColors"]
- data2 = Table[
- Which[x^2/a^2 + y^2/b^2 < 1 && (x + 1)^2/a^2 + (y + 1)^2/b^2 > 1,
- Round[ellipse[Max[x, anti[y + 1]], Min[x + 1, anti[y]]] -
- y (Min[x + 1, anti[y]] - Max[x, anti[y + 1]]) + (Max[x,
- anti[y + 1]] - x)], (x + 1)^2/a^2 + (y + 1)^2/b^2 < 1, 1,
- x^2/a^2 + y^2/b^2 > 1, 0], {x, 0, a}, {y, 0, b}];
- ListPlot3D[data2, Mesh -> None, InterpolationOrder -> 0,
- ColorFunction -> "SouthwestColors"]
效果图:
不由得去找了 Wolfram 的简历来看看,牛人啊!
刚上离散课的时候,看到一切都基础都是集合,就想写一个基于序偶的语言。可是也就想想,直到知道有Lisp 这种编程语言才淡了这想法。本来对Mathematica 不感冒的,这学期上数学实验才知道原来Mathematica 的鼻祖就是用纯Lisp 编的
MACSYMA ,一下来了兴趣,学了一下,发现它的格式挺优美的。
函数一定是:函数名[参数];用()改变运算顺序;用 列表名[[index]] 引用元素……
还可以用方便的快捷键书写二维表达式:
ctr + ^ 是幂,ctr + 2 是根号,ctr + / 是分数,
ctr + _ 是下标,esc + p + esc 是π ……
最让我觉得顺手的是它的画图函数,就像用ruby 写小程序一样顺畅。