萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 伺服器教學

Linux 數學利器:Gnuplot 繪圖與 Maxima 代數系統安裝入門

Gnuplot:命令列繪圖神器

安裝

# Ubuntu/Debian
apt-get install gnuplot gnuplot-x11

# CentOS/RHEL
yum install gnuplot

互動式繪圖

gnuplot
gnuplot> plot sin(x)/x
gnuplot> plot sin(x) title 'Sine', cos(x) title 'Cosine'
gnuplot> splot sin(x*y/20)  # 3D 曲面
gnuplot> set terminal pngcairo size 800,600
gnuplot> set output 'plot.png'
gnuplot> replot

腳本化批次繪圖

# plot.gp
set terminal pngcairo size 1024,768
set output 'benchmark.png'
set title 'Performance Comparison'
set xlabel 'Threads'
set ylabel 'Throughput (ops/s)'
set grid
plot 'data.txt' using 1:2 with linespoints title 'System A', \
     'data.txt' using 1:3 with linespoints title 'System B'
# 執行
gnuplot plot.gp

Maxima:電腦代數系統 (CAS)

安裝

# Ubuntu/Debian
apt-get install maxima wxmaxima  # wxMaxima 為圖形介面

# Arch
pacman -S maxima wxmaxima

wxMaxima 快速上手

  • 啟動 wxmaxima 進入筆記本介面。
  • Shift+Enter 執行當前儲存格;Enter 換行。
  • 右鍵選單可輸出 LaTeX、匯出圖片、微分/積分/解方程。

常見操作範例

(%i1) integrate(x^2*sin(x), x);
(%o1) 2*x*sin(x) - (x^2 - 2)*cos(x)

(%i2) solve([x+y=5, 2*x-y=1], [x,y]);
(%o2) [[x=2, y=3]]

(%i3) taylor(exp(x), x, 0, 5);
(%o3) 1 + x + x^2/2 + x^3/6 + x^4/24 + x^5/120 + ...

(%i4) plot2d([sin(x), cos(x)], [x, -%pi, %pi]);  # 呼叫 Gnuplot 繪圖

兩者協作

Maxima 內建 plot2d/plot3d 直接呼叫 Gnuplot 引擎,無需手動切換。複雜數學推導用 Maxima,大數據視覺化用 Gnuplot 腳本。

進階資源

copyright © 萬盛學電腦網 all rights reserved