6 图形
曲线图
函数的曲线图使用 plot2d
函数.
用如
(%i6) plot2d(sin(x), [x, 0, 2*%pi]);
(%o6) false
可以指定纵坐标范围.
(%i7) plot2d(sin(x), [x, 0, 2*%pi], [y, -1.2, 1.2]);
(%o7) false
图形文件
作图结果可以复制到 Windows 剪贴板, 然后粘贴到 Word 中, 或粘贴到画图程序中再保存为图形文件.
也可以直接保存为图形文件
(%i8) plot2d(sin(x), [x, 0, 2*%pi], [gnuplot_term,png], [gnuplot_out_file,"test_save.png"]);
(%o8) [/tmp/test_save.png]
多条曲线
多条曲线只要指定多个函数.
(%i9) plot2d([sin(x), cos(x)], [x, 0, 2*%pi]);
(%o9) false
对数坐标轴
plot2d
中加选项 [logy]
使得
y
y
y 轴为对数轴, 加选项 [logx, logy]
使得
x
,
y
x, y
x,y 轴都为对数轴.
(%i10) plot2d(2^x, [x, 0, 3]);
(%o10) false
(%i11) plot2d(2^x, [x, 0, 3], [logy]);
(%o11) false
参数方程作图
在 plot2d
中把要绘图的函数用 [parametrix, y(t), x(t), [t, tmin, tmax]]
表示, 可以进行参数方程作图.
例如, 如下参数方程表示的曲线
{
x
(
t
)
=
cos
(
t
)
y
(
t
)
=
sin
(
3
t
)
\left\{ \begin{array}{c} x(t) = \cos(t) \\ y(t) = \sin(3t) \end{array} \right.
{x(t)=cos(t)y(t)=sin(3t)
可以作图如下
(%i12) plot2d([parametric, cos(t), sin(3*t),
[t, 0, 2*%pi]],
[x, -1.2, 1.2],
[y, -1.2, 1.2],
[nticks, 200]);
(%o12) false
极坐标参数曲线可以化为直角坐标后参数作图.
(%i1) r : (exp(cos(t)) - 2*cos(4*t) - sin(t/12)^5);
cos(t) 5 t
(%o1) - 2 cos(4 t) + %e - sin (--)
12
(%i2) plot2d([parametric, r*sin(t), r*cos(t),
[t, -8*%pi, 8*%pi]],
[nticks, 2000]);
(%o2) false
三维曲面图
三维图用 plot3d
.
如
(%i3) plot3d(sin(sqrt(x^2+y^2))/sqrt(x^2+y^2),
[x, -12, 12], [y, -12, 12]);
expt: undefined: 0 to a negative exponent.
(%o3) false
三维参数曲面
三维图用 plot3d
和参数方程, 有两个参数.
如
(%i6) plot3d([cos(x)*(3 + y*cos(x/2)),
sin(x)*(3 + y*cos(x/2)),
y*sin(x/2)],
[x, -%pi, %pi], [y, -1, 1]);
(%o6) false