首页 > 解决方案 > 最大值绘制具有 3 列的离散数据

问题描述

如何绘制具有 3 列或更多列的离散数据集?MWE如下:

/* Required essentially to create the data set */
eqn1: 4 - x^2 - 4*y^2$
eqn2: y^2 - x^2 + 1$
sol: rk([eqn1,eqn2],[x,y],[-1.25, 0.75],[t,0,4,0.2])$

/* My current workaround to plot (x vs t) and (y vs t) */
n : length(sol)$
/* Select the ith column and create separate lists */
tseries : makelist(sol[i][1], i, 1, n)$ 
xseries:  makelist(sol[i][2], i, 1, n)$ 
yseries:  makelist(sol[i][3], i, 1, n)$ 

plot2d([
    [discrete, tseries, xseries],
    [discrete, tseries, yseries]
], [legend,"x","y"] ,[xlabel,"t"], [ylabel,"x, y"],[style, 
[linespoints,2,2]],
[gnuplot_preamble,"set key box width 2 spacing 1.3 top left"])$

有没有更好的解决方案来绘制而不创建tseries,xseriesyseries列表?

标签: plotmaxima

解决方案


好的,根据您的评论,我知道目标是什么。您的解决方案可以更简短一些,尽管不是很多。无论如何,map(lambda([txy], [txy[1], txy[2]]), sol)生成 [t, x] 点map(lambda([txy], [txy[1], txy[3]]), sol)列表并生成 [t, y] 点列表。因此,sol如上所述,我发现

plot2d ([[discrete, map(lambda([txy], [txy[1], txy[2]]), sol)],
         [discrete, map(lambda([txy], [txy[1], txy[3]]), sol)]]);

具有所需的输出(为清楚起见省略了绘图选项)。


推荐阅读